fix(proxy): clean up temp launch settings

This commit is contained in:
Tam Nhu Tran
2026-04-28 11:59:37 -04:00
parent 3dcf150978
commit 47fbe8bb3a
6 changed files with 93 additions and 15 deletions
+20 -3
View File
@@ -5,10 +5,15 @@ import * as path from 'path';
import type { Settings } from '../types/config';
import { stripAnthropicRoutingEnv } from './shell-executor';
export function createOpenAICompatLaunchSettingsPath(
export interface OpenAICompatLaunchSettings {
settingsPath: string;
cleanup: () => void;
}
export function createOpenAICompatLaunchSettings(
settingsPath: string,
settings: Settings
): string {
): OpenAICompatLaunchSettings {
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'ccs-openai-compat-settings-'));
fs.chmodSync(tempDir, 0o700);
@@ -31,5 +36,17 @@ export function createOpenAICompatLaunchSettingsPath(
mode: 0o600,
});
return launchSettingsPath;
let cleanedUp = false;
const cleanup = (): void => {
if (cleanedUp) {
return;
}
cleanedUp = true;
fs.rmSync(tempDir, { recursive: true, force: true });
};
return {
settingsPath: launchSettingsPath,
cleanup,
};
}
+13 -1
View File
@@ -208,7 +208,8 @@ export function getWindowsEscapedCommandShell(): SpawnOptions['shell'] {
export function execClaude(
claudeCli: string,
args: string[],
envVars: NodeJS.ProcessEnv | null = null
envVars: NodeJS.ProcessEnv | null = null,
onExitCleanup?: () => void
): void {
const isWindows = process.platform === 'win32';
const isPowerShellScript = isWindows && /\.ps1$/i.test(claudeCli);
@@ -286,6 +287,17 @@ export function execClaude(
});
}
let cleanedUp = false;
const runExitCleanup = (): void => {
if (cleanedUp) {
return;
}
cleanedUp = true;
onExitCleanup?.();
};
child.once('exit', runExitCleanup);
child.once('error', runExitCleanup);
wireChildProcessSignals(child, async (err: NodeJS.ErrnoException) => {
if (err.code === 'EACCES') {
console.error(`[X] Claude CLI is not executable: ${claudeCli}`);