From 01c2d9629e37129855c67ffad88f2a611029dc22 Mon Sep 17 00:00:00 2001 From: chekayo <9827969+chekayo@user.noreply.gitee.com> Date: Thu, 2 Oct 2025 14:21:02 +0800 Subject: [PATCH 1/2] fix: resolve Windows settings file path issue in ccr code command - Fix settings file not found error by creating temporary JSON file instead of passing JSON string - Remove shell-quote usage for settings argument to prevent path escaping issues - Use proper spawn args array instead of concatenated string - Add platform-specific shell option for Windows PATH resolution - Clean up temporary settings file on process exit Fixes the 'Settings file not found' error when running 'ccr code' on Windows --- src/utils/codeCommand.ts | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/utils/codeCommand.ts b/src/utils/codeCommand.ts index 3eb11849..13814212 100644 --- a/src/utils/codeCommand.ts +++ b/src/utils/codeCommand.ts @@ -6,6 +6,9 @@ import { incrementReferenceCount, } from "./processCheck"; import { quote } from 'shell-quote'; +import { writeFileSync, unlinkSync } from 'fs'; +import { join } from 'path'; +import { tmpdir } from 'os'; export async function executeCodeCommand(args: string[] = []) { // Set environment variables @@ -30,7 +33,18 @@ export async function executeCodeCommand(args: string[] = []) { padding: 0, } } - args.push('--settings', `${JSON.stringify(settingsFlag)}`); + + // Create a temporary settings file + const tempSettingsPath = join(tmpdir(), `claude-settings-${Date.now()}.json`); + try { + const settingsContent = JSON.stringify(settingsFlag, null, 2); + writeFileSync(tempSettingsPath, settingsContent); + } catch (error) { + console.error("Failed to create temporary settings file:", error); + process.exit(1); + } + + args.push('--settings', tempSettingsPath); // Non-interactive mode for automation environments if (config.NON_INTERACTIVE_MODE) { @@ -51,18 +65,18 @@ export async function executeCodeCommand(args: string[] = []) { // Execute claude command const claudePath = config?.CLAUDE_PATH || process.env.CLAUDE_PATH || "claude"; - const joinedArgs = args.length > 0 ? quote(args) : ""; - + // Don't use quote for the entire args array since it escapes colons in paths + // Instead, use spawn with proper args array const stdioConfig: StdioOptions = config.NON_INTERACTIVE_MODE ? ["pipe", "inherit", "inherit"] // Pipe stdin for non-interactive : "inherit"; // Default inherited behavior const claudeProcess = spawn( - claudePath + (joinedArgs ? ` ${joinedArgs}` : ""), - [], + claudePath, + args, { env: process.env, stdio: stdioConfig, - shell: true, + shell: process.platform === 'win32', // Use shell on Windows for PATH resolution } ); @@ -76,11 +90,23 @@ export async function executeCodeCommand(args: string[] = []) { console.log( "Make sure Claude Code is installed: npm install -g @anthropic-ai/claude-code" ); + // Clean up temporary settings file + try { + unlinkSync(tempSettingsPath); + } catch (e) { + // Ignore cleanup errors + } decrementReferenceCount(); process.exit(1); }); claudeProcess.on("close", (code) => { + // Clean up temporary settings file + try { + unlinkSync(tempSettingsPath); + } catch (e) { + // Ignore cleanup errors + } decrementReferenceCount(); closeService(); process.exit(code || 0); From 850c882fdacf0477127762cccdc25e38fa614204 Mon Sep 17 00:00:00 2001 From: chekayo <9827969+chekayo@user.noreply.gitee.com> Date: Thu, 2 Oct 2025 15:01:18 +0800 Subject: [PATCH 2/2] chore: use shell on all platforms for consistent PATH resolution --- src/utils/codeCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/codeCommand.ts b/src/utils/codeCommand.ts index 13814212..d082fd0a 100644 --- a/src/utils/codeCommand.ts +++ b/src/utils/codeCommand.ts @@ -76,7 +76,7 @@ export async function executeCodeCommand(args: string[] = []) { { env: process.env, stdio: stdioConfig, - shell: process.platform === 'win32', // Use shell on Windows for PATH resolution + shell: true, // Use shell on all platforms for PATH resolution } );