Use env in claude code SDK
This commit is contained in:
+8
-2
@@ -2,7 +2,7 @@ import { query, type SDKMessage } from "@anthropic-ai/claude-agent-sdk";
|
|||||||
import packageJson from "../package.json" with { type: "json" };
|
import packageJson from "../package.json" with { type: "json" };
|
||||||
import { log } from "../utils/cli.ts";
|
import { log } from "../utils/cli.ts";
|
||||||
import { addInstructions } from "./instructions.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({
|
export const claude = agent({
|
||||||
name: "claude",
|
name: "claude",
|
||||||
@@ -15,7 +15,12 @@ export const claude = agent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
run: async ({ payload, mcpServers, apiKey, cliPath }) => {
|
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);
|
const prompt = addInstructions(payload);
|
||||||
console.log(prompt);
|
console.log(prompt);
|
||||||
@@ -26,6 +31,7 @@ export const claude = agent({
|
|||||||
permissionMode: "bypassPermissions",
|
permissionMode: "bypassPermissions",
|
||||||
mcpServers,
|
mcpServers,
|
||||||
pathToClaudeCodeExecutable: cliPath,
|
pathToClaudeCodeExecutable: cliPath,
|
||||||
|
env: createAgentEnv({ ANTHROPIC_API_KEY: apiKey }),
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -92783,7 +92783,10 @@ var claude = agent({
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
run: async ({ payload, mcpServers, apiKey, cliPath }) => {
|
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);
|
const prompt = addInstructions(payload);
|
||||||
console.log(prompt);
|
console.log(prompt);
|
||||||
const queryInstance = query({
|
const queryInstance = query({
|
||||||
@@ -92791,7 +92794,8 @@ var claude = agent({
|
|||||||
options: {
|
options: {
|
||||||
permissionMode: "bypassPermissions",
|
permissionMode: "bypassPermissions",
|
||||||
mcpServers,
|
mcpServers,
|
||||||
pathToClaudeCodeExecutable: cliPath
|
pathToClaudeCodeExecutable: cliPath,
|
||||||
|
env: createAgentEnv({ ANTHROPIC_API_KEY: apiKey })
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
for await (const message of queryInstance) {
|
for await (const message of queryInstance) {
|
||||||
|
|||||||
Reference in New Issue
Block a user