fix: ensure Claude Code finds skills in ~/.claude/commands/

1. Skills API: accept optional cwd query param so project-level skills
   are scanned from the session's working directory, not the standalone
   server's process.cwd().
2. SDK env: explicitly set HOME so Claude Code can resolve ~/.claude/
   for global skills discovery in packaged builds.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
7418andClaude Opus 4.6 committed 2026-02-07 00:49:40 +08:00
1 parent f310fab397
commit fab8b41966
2 files changed
+12 -5

No files matched your search

+7 -5
View File
@@ -1,4 +1,4 @@
import { NextResponse } from "next/server";
import { NextRequest, NextResponse } from "next/server";
import fs from "fs";
import path from "path";
import os from "os";
@@ -15,8 +15,8 @@ function getGlobalCommandsDir(): string {
return path.join(os.homedir(), ".claude", "commands");
}
function getProjectCommandsDir(): string {
return path.join(process.cwd(), ".claude", "commands");
function getProjectCommandsDir(cwd?: string): string {
return path.join(cwd || process.cwd(), ".claude", "commands");
}
function getPluginCommandsDirs(): string[] {
@@ -157,10 +157,12 @@ function scanDirectory(
return skills;
}
export async function GET() {
export async function GET(request: NextRequest) {
try {
// Accept optional cwd query param for project-level skills
const cwd = request.nextUrl.searchParams.get("cwd") || undefined;
const globalSkills = scanDirectory(getGlobalCommandsDir(), "global");
const projectSkills = scanDirectory(getProjectCommandsDir(), "project");
const projectSkills = scanDirectory(getProjectCommandsDir(cwd), "project");
const installedSkills = scanInstalledSkills();
// Scan installed plugin skills
+5
View File
@@ -138,6 +138,11 @@ export function streamClaude(options: ClaudeStreamOptions): ReadableStream<strin
// Then overlay any API config the user set in CodePilot settings (optional).
const sdkEnv: Record<string, string> = { ...process.env as Record<string, string> };
// Ensure HOME is explicitly set so Claude Code can find ~/.claude/commands/
if (!sdkEnv.HOME) {
sdkEnv.HOME = os.homedir();
}
const appToken = getSetting('anthropic_auth_token');
const appBaseUrl = getSetting('anthropic_base_url');
if (appToken) {