From 1c678f6ef8d69abd1e4748f7b8a192afc479156f Mon Sep 17 00:00:00 2001 From: Colin McDonnell Date: Tue, 2 Dec 2025 18:51:43 -0800 Subject: [PATCH] Use env in claude code SDK --- agents/claude.ts | 10 ++++++++-- entry | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/agents/claude.ts b/agents/claude.ts index ffe4f95..375a626 100644 --- a/agents/claude.ts +++ b/agents/claude.ts @@ -2,7 +2,7 @@ import { query, type SDKMessage } from "@anthropic-ai/claude-agent-sdk"; import packageJson from "../package.json" with { type: "json" }; import { log } from "../utils/cli.ts"; import { addInstructions } from "./instructions.ts"; -import { agent, installFromNpmTarball, setupProcessAgentEnv } from "./shared.ts"; +import { agent, createAgentEnv, installFromNpmTarball, setupProcessAgentEnv } from "./shared.ts"; export const claude = agent({ name: "claude", @@ -15,7 +15,12 @@ export const claude = agent({ }); }, run: async ({ payload, mcpServers, apiKey, cliPath }) => { - setupProcessAgentEnv({ ANTHROPIC_API_KEY: apiKey }); + setupProcessAgentEnv({ + // ANTHROPIC_API_KEY: apiKey + }); + + // delete process.env.ANTHROPIC_API_KEY to ensure it's not used by the SDK + delete process.env.ANTHROPIC_API_KEY; const prompt = addInstructions(payload); console.log(prompt); @@ -26,6 +31,7 @@ export const claude = agent({ permissionMode: "bypassPermissions", mcpServers, pathToClaudeCodeExecutable: cliPath, + env: createAgentEnv({ ANTHROPIC_API_KEY: apiKey }), }, }); diff --git a/entry b/entry index 5a4d59b..56b0b11 100755 --- a/entry +++ b/entry @@ -92783,7 +92783,10 @@ var claude = agent({ }); }, run: async ({ payload, mcpServers, apiKey, cliPath }) => { - setupProcessAgentEnv({ ANTHROPIC_API_KEY: apiKey }); + setupProcessAgentEnv({ + // ANTHROPIC_API_KEY: apiKey + }); + delete process.env.ANTHROPIC_API_KEY; const prompt = addInstructions(payload); console.log(prompt); const queryInstance = query({ @@ -92791,7 +92794,8 @@ var claude = agent({ options: { permissionMode: "bypassPermissions", mcpServers, - pathToClaudeCodeExecutable: cliPath + pathToClaudeCodeExecutable: cliPath, + env: createAgentEnv({ ANTHROPIC_API_KEY: apiKey }) } }); for await (const message of queryInstance) {