From e5f78a0456c7b960c0c4f38d0737ca52094ea4ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Barreiro?= <52393857+BarreiroT@users.noreply.github.com> Date: Tue, 1 Jul 2025 08:39:58 +0200 Subject: [PATCH] Do not read auth variables from the user env when using Claude Code (#4591) --- .changeset/poor-years-grab.md | 5 +++++ src/integrations/claude-code/run.ts | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/poor-years-grab.md diff --git a/.changeset/poor-years-grab.md b/.changeset/poor-years-grab.md new file mode 100644 index 00000000..97e5ab22 --- /dev/null +++ b/.changeset/poor-years-grab.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +fix: Do not read auth variables from the user env when using Claude Code diff --git a/src/integrations/claude-code/run.ts b/src/integrations/claude-code/run.ts index 94d2766a..b89a1ea6 100644 --- a/src/integrations/claude-code/run.ts +++ b/src/integrations/claude-code/run.ts @@ -128,15 +128,21 @@ function runProcess({ systemPrompt, messages, path, modelId }: ClaudeCodeOptions args.push("--model", modelId) } + const env: NodeJS.ProcessEnv = { + ...process.env, + // The default is 32000. However, I've gotten larger responses, so we increase it unless the user specified it. + CLAUDE_CODE_MAX_OUTPUT_TOKENS: process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS || "64000", + } + + // We don't want to consume the user's ANTHROPIC_API_KEY, + // and will allow Claude Code to resolve auth by itself + delete env["ANTHROPIC_API_KEY"] + const claudeCodeProcess = execa(claudePath, args, { stdin: "pipe", stdout: "pipe", stderr: "pipe", - env: { - ...process.env, - // The default is 32000. However, I've gotten larger responses, so we increase it unless the user specified it. - CLAUDE_CODE_MAX_OUTPUT_TOKENS: process.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS || "64000", - }, + env, cwd, maxBuffer: 1024 * 1024 * 1000, timeout: CLAUDE_CODE_TIMEOUT,