@workbench-ai/agent-driver-anthropic-claude-code 0.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,69 @@
1
+ export declare const CLAUDE_CODE_OAUTH_TOKEN_ENV = "CLAUDE_CODE_OAUTH_TOKEN";
2
+ export interface ClaudeWorkbenchProviderAuthEnvVar {
3
+ name: string;
4
+ value: string;
5
+ }
6
+ export interface ClaudeWorkbenchBedrockEnvCollection {
7
+ entries: ClaudeWorkbenchProviderAuthEnvVar[];
8
+ missing: string[];
9
+ }
10
+ export interface ClaudeWorkbenchBedrockConnectEnvOptions {
11
+ env?: Record<string, string | undefined>;
12
+ flags?: Record<string, string | undefined>;
13
+ runCommand?: (command: string, args: readonly string[], env: Record<string, string | undefined>) => Promise<string>;
14
+ }
15
+ export declare const claudeWorkbenchProviderAuth: {
16
+ readonly apiKey: {
17
+ readonly envName: "ANTHROPIC_API_KEY";
18
+ };
19
+ readonly profile: {
20
+ readonly required: readonly [".claude.json"];
21
+ readonly optional: readonly [".claude/oauth-token", ".claude/.credentials.json"];
22
+ readonly alternatives: readonly [readonly [".claude/oauth-token", ".claude/.credentials.json"]];
23
+ };
24
+ readonly oauthToken: {
25
+ readonly envName: "CLAUDE_CODE_OAUTH_TOKEN";
26
+ readonly relativePath: ".claude/oauth-token";
27
+ readonly parse: typeof parseClaudeSetupTokenOutput;
28
+ readonly setup: {
29
+ readonly command: "claude";
30
+ readonly args: readonly ["setup-token"];
31
+ readonly prompt: "Claude Code needs a portable OAuth token for Workbench sandboxes. Starting `claude setup-token`.";
32
+ readonly envDenylist: readonly ["CLAUDE_CODE_OAUTH_TOKEN"];
33
+ };
34
+ };
35
+ readonly envAuth: {
36
+ readonly bedrock: {
37
+ readonly envAllowlist: readonly ["CLAUDE_CODE_USE_BEDROCK", "AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "AWS_REGION", "AWS_DEFAULT_REGION", "AWS_BEARER_TOKEN_BEDROCK", "ANTHROPIC_MODEL", "ANTHROPIC_SMALL_FAST_MODEL"];
38
+ readonly collect: typeof collectClaudeWorkbenchBedrockEnv;
39
+ readonly collectFromConnectEnvironment: typeof collectClaudeWorkbenchBedrockConnectEnv;
40
+ };
41
+ };
42
+ readonly harnessDefaults: {
43
+ readonly config: {
44
+ readonly max_turns: 64;
45
+ readonly permission_mode: "bypassPermissions";
46
+ };
47
+ };
48
+ readonly toHarnessAuth: (auth: {
49
+ kind: "profile" | "api_key" | "bedrock";
50
+ root?: string;
51
+ }) => {
52
+ strategy: string;
53
+ ref: string;
54
+ path?: undefined;
55
+ } | {
56
+ strategy: string;
57
+ ref?: undefined;
58
+ path?: undefined;
59
+ } | {
60
+ strategy: string;
61
+ path: string;
62
+ ref?: undefined;
63
+ } | null;
64
+ readonly staleErrorPatterns: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
65
+ };
66
+ export declare function collectClaudeWorkbenchBedrockEnv(env: Record<string, string | undefined>): ClaudeWorkbenchBedrockEnvCollection;
67
+ export declare function collectClaudeWorkbenchBedrockConnectEnv({ env, flags, runCommand, }?: ClaudeWorkbenchBedrockConnectEnvOptions): Promise<Record<string, string | undefined>>;
68
+ export declare function parseClaudeSetupTokenOutput(output: string): string | null;
69
+ //# sourceMappingURL=workbench-auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workbench-auth.d.ts","sourceRoot":"","sources":["../src/workbench-auth.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,2BAA2B,4BAA4B,CAAC;AAErE,MAAM,WAAW,iCAAiC;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mCAAmC;IAClD,OAAO,EAAE,iCAAiC,EAAE,CAAC;IAC7C,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,uCAAuC;IACtD,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;IAC3C,UAAU,CAAC,EAAE,CACX,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,SAAS,MAAM,EAAE,EACvB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,KACpC,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB;AAED,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCA4ClB;QAClB,IAAI,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;QACxC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf;;;;;;;;;;;;;;CAkCO,CAAC;AAEX,wBAAgB,gCAAgC,CAC9C,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GACtC,mCAAmC,CA6BrC;AAED,wBAAsB,uCAAuC,CAAC,EAC5D,GAAiB,EACjB,KAAU,EACV,UAA8B,GAC/B,GAAE,uCAA4C,GAAG,OAAO,CACvD,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CACnC,CAgCA;AAsFD,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA0BzE"}
@@ -0,0 +1,212 @@
1
+ import { spawn } from "node:child_process";
2
+ export const CLAUDE_CODE_OAUTH_TOKEN_ENV = "CLAUDE_CODE_OAUTH_TOKEN";
3
+ export const claudeWorkbenchProviderAuth = {
4
+ apiKey: {
5
+ envName: "ANTHROPIC_API_KEY",
6
+ },
7
+ profile: {
8
+ required: [".claude.json"],
9
+ optional: [".claude/oauth-token", ".claude/.credentials.json"],
10
+ alternatives: [[".claude/oauth-token", ".claude/.credentials.json"]],
11
+ },
12
+ oauthToken: {
13
+ envName: CLAUDE_CODE_OAUTH_TOKEN_ENV,
14
+ relativePath: ".claude/oauth-token",
15
+ parse: parseClaudeSetupTokenOutput,
16
+ setup: {
17
+ command: "claude",
18
+ args: ["setup-token"],
19
+ prompt: "Claude Code needs a portable OAuth token for Workbench sandboxes. Starting `claude setup-token`.",
20
+ envDenylist: [CLAUDE_CODE_OAUTH_TOKEN_ENV],
21
+ },
22
+ },
23
+ envAuth: {
24
+ bedrock: {
25
+ envAllowlist: [
26
+ "CLAUDE_CODE_USE_BEDROCK",
27
+ "AWS_ACCESS_KEY_ID",
28
+ "AWS_SECRET_ACCESS_KEY",
29
+ "AWS_SESSION_TOKEN",
30
+ "AWS_REGION",
31
+ "AWS_DEFAULT_REGION",
32
+ "AWS_BEARER_TOKEN_BEDROCK",
33
+ "ANTHROPIC_MODEL",
34
+ "ANTHROPIC_SMALL_FAST_MODEL",
35
+ ],
36
+ collect: collectClaudeWorkbenchBedrockEnv,
37
+ collectFromConnectEnvironment: collectClaudeWorkbenchBedrockConnectEnv,
38
+ },
39
+ },
40
+ harnessDefaults: {
41
+ config: {
42
+ max_turns: 64,
43
+ permission_mode: "bypassPermissions",
44
+ },
45
+ },
46
+ toHarnessAuth(auth) {
47
+ if (auth.kind === "api_key") {
48
+ return {
49
+ strategy: "secret_ref",
50
+ ref: "ANTHROPIC_API_KEY",
51
+ };
52
+ }
53
+ if (auth.kind === "bedrock") {
54
+ return {
55
+ strategy: "bedrock_env",
56
+ };
57
+ }
58
+ if (!auth.root) {
59
+ return null;
60
+ }
61
+ return {
62
+ strategy: "profile_path",
63
+ path: auth.root,
64
+ };
65
+ },
66
+ staleErrorPatterns: [
67
+ /not logged in/iu,
68
+ /login required/iu,
69
+ /authentication required/iu,
70
+ /failed to authenticate/iu,
71
+ /authentication_error/iu,
72
+ /api error:\s*401/iu,
73
+ /invalid.*session/iu,
74
+ /invalid bearer token/iu,
75
+ /session.*expired/iu,
76
+ /oauth.*expired/iu,
77
+ /unauthorized/iu,
78
+ /claude_code_oauth_token/iu,
79
+ ],
80
+ };
81
+ export function collectClaudeWorkbenchBedrockEnv(env) {
82
+ const usesBearerToken = Boolean(env.AWS_BEARER_TOKEN_BEDROCK?.trim());
83
+ const required = usesBearerToken
84
+ ? []
85
+ : ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"];
86
+ const missing = required.filter((name) => !env[name]?.trim());
87
+ const region = env.AWS_REGION?.trim() || env.AWS_DEFAULT_REGION?.trim();
88
+ if (!region) {
89
+ missing.push("AWS_REGION");
90
+ }
91
+ const entries = [
92
+ {
93
+ name: "CLAUDE_CODE_USE_BEDROCK",
94
+ value: "1",
95
+ },
96
+ ];
97
+ for (const name of claudeWorkbenchProviderAuth.envAuth.bedrock.envAllowlist) {
98
+ if (name === "CLAUDE_CODE_USE_BEDROCK") {
99
+ continue;
100
+ }
101
+ const value = env[name]?.trim();
102
+ if (value) {
103
+ entries.push({ name, value });
104
+ }
105
+ }
106
+ if (!entries.some((entry) => entry.name === "AWS_REGION") && region) {
107
+ entries.push({ name: "AWS_REGION", value: region });
108
+ }
109
+ return { entries, missing };
110
+ }
111
+ export async function collectClaudeWorkbenchBedrockConnectEnv({ env = process.env, flags = {}, runCommand = runCommandCapture, } = {}) {
112
+ const profile = flags["aws-profile"] ?? env.AWS_PROFILE;
113
+ const region = flags["aws-region"] ?? env.AWS_REGION ?? env.AWS_DEFAULT_REGION;
114
+ const direct = {
115
+ CLAUDE_CODE_USE_BEDROCK: "1",
116
+ AWS_ACCESS_KEY_ID: env.AWS_ACCESS_KEY_ID,
117
+ AWS_SECRET_ACCESS_KEY: env.AWS_SECRET_ACCESS_KEY,
118
+ AWS_SESSION_TOKEN: env.AWS_SESSION_TOKEN,
119
+ AWS_REGION: region,
120
+ AWS_DEFAULT_REGION: env.AWS_DEFAULT_REGION,
121
+ AWS_BEARER_TOKEN_BEDROCK: env.AWS_BEARER_TOKEN_BEDROCK,
122
+ ANTHROPIC_MODEL: env.ANTHROPIC_MODEL,
123
+ ANTHROPIC_SMALL_FAST_MODEL: env.ANTHROPIC_SMALL_FAST_MODEL,
124
+ };
125
+ if (direct.AWS_BEARER_TOKEN_BEDROCK ||
126
+ (direct.AWS_ACCESS_KEY_ID && direct.AWS_SECRET_ACCESS_KEY)) {
127
+ return direct;
128
+ }
129
+ if (!profile) {
130
+ return direct;
131
+ }
132
+ const profileRegion = region
133
+ ? undefined
134
+ : await exportAwsProfileRegion(profile, env, runCommand);
135
+ return {
136
+ ...direct,
137
+ ...(await exportAwsProfileCredentials(profile, env, runCommand)),
138
+ AWS_REGION: region ?? profileRegion,
139
+ };
140
+ }
141
+ async function exportAwsProfileCredentials(profile, env, runCommand) {
142
+ const output = await runCommand("aws", [
143
+ "configure",
144
+ "export-credentials",
145
+ "--format",
146
+ "env-no-export",
147
+ "--profile",
148
+ profile,
149
+ ], env);
150
+ const exported = {};
151
+ for (const line of output.split(/\r?\n/u)) {
152
+ const match = line.match(/^([A-Z0-9_]+)=(.*)$/u);
153
+ if (match) {
154
+ exported[match[1]] = match[2];
155
+ }
156
+ }
157
+ return exported;
158
+ }
159
+ async function exportAwsProfileRegion(profile, env, runCommand) {
160
+ const output = await runCommand("aws", ["configure", "get", "region", "--profile", profile], env).catch(() => "");
161
+ const region = output.trim();
162
+ return region.length > 0 ? region : undefined;
163
+ }
164
+ async function runCommandCapture(command, args, env) {
165
+ return await new Promise((resolve, reject) => {
166
+ const child = spawn(command, [...args], {
167
+ stdio: ["ignore", "pipe", "pipe"],
168
+ env: { ...process.env, ...env },
169
+ });
170
+ let stdout = "";
171
+ let stderr = "";
172
+ child.stdout?.setEncoding("utf8");
173
+ child.stderr?.setEncoding("utf8");
174
+ child.stdout?.on("data", (chunk) => {
175
+ stdout += chunk;
176
+ });
177
+ child.stderr?.on("data", (chunk) => {
178
+ stderr += chunk;
179
+ });
180
+ child.on("error", reject);
181
+ child.on("exit", (code, signal) => {
182
+ if (code === 0) {
183
+ resolve(stdout);
184
+ return;
185
+ }
186
+ reject(new Error(`${command} ${args.join(" ")} exited with code ${code ?? "null"} signal ${signal ?? "null"}${stderr.trim() ? `: ${stderr.trim()}` : ""}.`));
187
+ });
188
+ });
189
+ }
190
+ export function parseClaudeSetupTokenOutput(output) {
191
+ const lines = output
192
+ .replace(/\x1B\[[0-?]*[ -/]*[@-~]/gu, "")
193
+ .replace(/\r/gu, "")
194
+ .split("\n");
195
+ for (let index = 0; index < lines.length; index += 1) {
196
+ const line = lines[index]?.trim();
197
+ const firstSegment = line?.match(/sk-ant-oat\d{2}-[A-Za-z0-9_-]*/iu)?.[0];
198
+ if (!firstSegment) {
199
+ continue;
200
+ }
201
+ const segments = [firstSegment];
202
+ for (let continuationIndex = index + 1; continuationIndex < lines.length; continuationIndex += 1) {
203
+ const continuation = lines[continuationIndex]?.trim();
204
+ if (!continuation || !/^[A-Za-z0-9_-]+$/u.test(continuation)) {
205
+ break;
206
+ }
207
+ segments.push(continuation);
208
+ }
209
+ return segments.join("");
210
+ }
211
+ return null;
212
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@workbench-ai/agent-driver-anthropic-claude-code",
3
+ "version": "0.0.44",
4
+ "type": "module",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/workbench-ai/workbench-monorepo.git",
8
+ "directory": "products/agent-drivers/packages/anthropic-claude-code"
9
+ },
10
+ "publishConfig": {
11
+ "registry": "https://registry.npmjs.org/",
12
+ "access": "public"
13
+ },
14
+ "main": "dist/index.js",
15
+ "types": "dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "default": "./dist/index.js"
20
+ },
21
+ "./workbench-auth": {
22
+ "types": "./dist/workbench-auth.d.ts",
23
+ "default": "./dist/workbench-auth.js"
24
+ }
25
+ },
26
+ "files": [
27
+ "dist"
28
+ ],
29
+ "dependencies": {
30
+ "zod": "^4.1.5",
31
+ "@workbench-ai/agent-driver": "0.0.44"
32
+ },
33
+ "devDependencies": {
34
+ "@types/node": "^24.3.1",
35
+ "prettier": "^3.6.2",
36
+ "typescript": "^5.9.2"
37
+ },
38
+ "scripts": {
39
+ "build": "rm -rf dist && tsc -p tsconfig.json",
40
+ "dev": "tsc -p tsconfig.json --watch --preserveWatchOutput",
41
+ "lint": "tsc -p tsconfig.json --noEmit",
42
+ "format": "prettier --check 'src/**/*.ts'"
43
+ }
44
+ }