@yanzc/claude-pro 0.7.2 → 0.7.4
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.
- package/.env.example +24 -34
- package/README.md +317 -331
- package/package.json +2 -2
- package/src/agent.js +41 -4
- package/src/api.js +40 -173
- package/src/commands.js +19 -84
- package/src/config.js +32 -137
- package/src/gateway.js +9 -3
- package/src/host.js +8 -5
- package/src/main.js +19 -2
- package/src/mcp.js +14 -0
- package/src/peers.js +3 -6
- package/src/print.js +1 -1
- package/src/prompts.js +23 -14
- package/src/ratelimit.js +6 -19
- package/src/remote.js +6 -40
- package/src/runtime.js +7 -4
- package/src/tools/peers.js +5 -9
- package/src/ui/repl.js +24 -204
- package/src/work-state.js +62 -0
- package/src/claude-code.js +0 -60
- package/src/codex/client.js +0 -310
- package/src/codex/translate-request.js +0 -239
- package/src/codex/translate-stream.js +0 -328
- package/src/oauth.js +0 -287
- package/src/transfer.js +0 -260
- package/src/utils/downloads.js +0 -83
package/src/commands.js
CHANGED
|
@@ -6,9 +6,7 @@ import { c, padEnd, truncate } from './ui/ansi.js';
|
|
|
6
6
|
import { SelectDialog } from './ui/dialogs.js';
|
|
7
7
|
import { renderTodos, resultLines, formatTokens, formatDuration } from './ui/render.js';
|
|
8
8
|
import { loadConfig, settingsFiles, updateSettingsFile, rememberChoice, applyRememberedChoices, KNOWN_KEYS, VERSION, APP_NAME, CONFIG_DIR } from './config.js';
|
|
9
|
-
import { loginWithBrowser, readGatewayLogin, clearGatewayLogin, fetchGatewayAccount, fetchGatewayModels, cachedGatewayModel, gatewayEfforts, formatUsd } from './gateway.js';
|
|
10
|
-
import { codexLoginSummary, codexModels, codexEfforts } from './codex/client.js';
|
|
11
|
-
import { readClaudeCodeLogin } from './claude-code.js';
|
|
9
|
+
import { loginWithBrowser, readGatewayLogin, gatewayLogin, clearGatewayLogin, fetchGatewayAccount, fetchGatewayModels, cachedGatewayModel, gatewayEfforts, formatUsd } from './gateway.js';
|
|
12
10
|
import { SessionStore } from './session.js';
|
|
13
11
|
import { memoryFiles, listAutoMemories } from './context.js';
|
|
14
12
|
import { INIT_PROMPT } from './prompts.js';
|
|
@@ -25,13 +23,11 @@ import { describeHost, normalizeDir } from './host.js';
|
|
|
25
23
|
|
|
26
24
|
const EFFORTS = ['none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'];
|
|
27
25
|
const isGpt = (modelId) => /^gpt-/i.test(modelId);
|
|
28
|
-
// The levels /effort offers for a model:
|
|
29
|
-
// else the local Codex cache; EFFORTS for other models (an Anthropic-compatible API may take any of them).
|
|
26
|
+
// The levels /effort offers for a gateway model: use its advertised levels when available.
|
|
30
27
|
const effortLevels = (modelId, modelInfo = null) => {
|
|
31
28
|
if (/^claude-/i.test(modelId)) return CLAUDE_EFFORTS;
|
|
32
29
|
const remote = gatewayEfforts(modelInfo);
|
|
33
|
-
|
|
34
|
-
return isGpt(modelId) && codexEfforts(modelId).length ? codexEfforts(modelId) : EFFORTS;
|
|
30
|
+
return remote.length ? remote : EFFORTS;
|
|
35
31
|
};
|
|
36
32
|
|
|
37
33
|
// What /model offers (and the remote page, see App.remoteOptions): [{value, label, description}] in plain text, the
|
|
@@ -40,15 +36,10 @@ const effortLevels = (modelId, modelInfo = null) => {
|
|
|
40
36
|
export async function modelChoices(cfg) {
|
|
41
37
|
const configured = cfg.configuredModelSpec;
|
|
42
38
|
const opts = [{ value: 'default', label: 'Default', description: `${configured} → ${cfg.resolveModel(configured).id}` }];
|
|
43
|
-
|
|
44
|
-
// The models the local Codex install lists.
|
|
45
|
-
for (const m of codexModels({ ...process.env, ...cfg.env }).models.filter((x) => !x.hidden)) opts.push({ value: m.slug, label: m.slug, description: m.contextWindow ? `${formatTokens(m.contextWindow)} context` : '' });
|
|
46
|
-
} else {
|
|
47
|
-
opts.push(...['opus', 'sonnet', 'haiku'].map((a) => ({ value: a, label: a, description: `→ ${cfg.resolveModel(cfg.aliasTarget(a)).label}` })));
|
|
48
|
-
}
|
|
39
|
+
opts.push(...['opus', 'sonnet', 'haiku'].map((a) => ({ value: a, label: a, description: `→ ${cfg.resolveModel(cfg.aliasTarget(a)).label}` })));
|
|
49
40
|
if (cfg.usesGateway) {
|
|
50
41
|
// The other models the gateway serves (Fable, the GPT models, …); without an answer, gpt-6.1-sol.
|
|
51
|
-
const login =
|
|
42
|
+
const login = gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
52
43
|
let served = null;
|
|
53
44
|
try { if (login) served = await fetchGatewayModels(login, { signal: AbortSignal.timeout(4000) }); } catch { /* offline: the fallback below */ }
|
|
54
45
|
const aliased = new Set(['opus', 'sonnet', 'haiku'].map((a) => cfg.resolveModel(cfg.aliasTarget(a)).id));
|
|
@@ -57,7 +48,6 @@ export async function modelChoices(cfg) {
|
|
|
57
48
|
opts.push({ value: m.id, label: m.id, description: isGpt(m.id) ? 'OpenAI, through the gateway\'s Codex login' : m.display_name || '' });
|
|
58
49
|
}
|
|
59
50
|
}
|
|
60
|
-
if (cfg.provider === 'api' && cfg.env.CLAUDE_CODE_SUBAGENT_MODEL) opts.push({ value: cfg.env.CLAUDE_CODE_SUBAGENT_MODEL, label: cfg.env.CLAUDE_CODE_SUBAGENT_MODEL, description: 'sub-agent model' });
|
|
61
51
|
return opts;
|
|
62
52
|
}
|
|
63
53
|
|
|
@@ -67,7 +57,7 @@ export async function effortChoices(cfg) {
|
|
|
67
57
|
const id = cfg.mainModel.id;
|
|
68
58
|
let info = null;
|
|
69
59
|
if (cfg.usesGateway && isGpt(id)) {
|
|
70
|
-
const login =
|
|
60
|
+
const login = gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
71
61
|
try { if (login) info = (await fetchGatewayModels(login, { signal: AbortSignal.timeout(4000) })).find((m) => m.id === id) || null; } catch { /* use local cache or generic levels */ }
|
|
72
62
|
}
|
|
73
63
|
const levels = effortLevels(id, info);
|
|
@@ -106,7 +96,6 @@ export function buildCommands(app) {
|
|
|
106
96
|
cfg.env = fresh.env;
|
|
107
97
|
cfg.sources = fresh.sources;
|
|
108
98
|
cfg.settings = fresh.settings;
|
|
109
|
-
cfg.ignoredFromDotEnv = fresh.ignoredFromDotEnv;
|
|
110
99
|
// What the system prompt is built from may have changed (memory switched off, say). It is not rebuilt in the
|
|
111
100
|
// middle of a conversation, which would lose its prompt cache; it is, at the next /clear or compaction. A
|
|
112
101
|
// different model is the exception: the prompt names it, and the new model has a cache of its own anyway.
|
|
@@ -278,7 +267,6 @@ export function buildCommands(app) {
|
|
|
278
267
|
if (v === undefined) continue;
|
|
279
268
|
lines.push(`${padEnd(k, 34)} ${c.bold(v)} ${c.dim(cfg.sources[k] || '')}`);
|
|
280
269
|
}
|
|
281
|
-
if (cfg.ignoredFromDotEnv.length) lines.push('', c.dim(`Not applied from .env with the claude-code provider (it is the API provider's setup; the subscription's defaults are used instead): ${cfg.ignoredFromDotEnv.join(', ')}. Set them with /config set or /effort to apply them here.`));
|
|
282
270
|
lines.push('', c.dim('Other keys: ' + Object.keys(KNOWN_KEYS).filter((k) => cfg.env[k] === undefined).join(', ')));
|
|
283
271
|
lines.push('', `${c.dim('Change with')} /config set KEY VALUE [--project|--local] ${c.dim('or edit')} ${settingsFiles(app.cwd).user}`);
|
|
284
272
|
log(lines, '');
|
|
@@ -312,7 +300,7 @@ export function buildCommands(app) {
|
|
|
312
300
|
name: 'effort',
|
|
313
301
|
get argHint() {
|
|
314
302
|
const cfg = app.runtime.config;
|
|
315
|
-
const login = cfg.usesGateway ?
|
|
303
|
+
const login = cfg.usesGateway ? gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY) : null;
|
|
316
304
|
return `[${effortLevels(cfg.mainModel.id, cachedGatewayModel(login, cfg.mainModel.id)).join('|')}|auto|default]`;
|
|
317
305
|
},
|
|
318
306
|
description: 'Set reasoning effort (output_config.effort; kept for later sessions)',
|
|
@@ -345,7 +333,7 @@ export function buildCommands(app) {
|
|
|
345
333
|
},
|
|
346
334
|
});
|
|
347
335
|
|
|
348
|
-
//
|
|
336
|
+
// Keep the gateway selection in the user settings and apply its remembered /model and /effort.
|
|
349
337
|
const switchProvider = (provider) => {
|
|
350
338
|
const cfg = app.runtime.config;
|
|
351
339
|
const files = settingsFiles(app.cwd);
|
|
@@ -381,50 +369,13 @@ export function buildCommands(app) {
|
|
|
381
369
|
|
|
382
370
|
add({
|
|
383
371
|
name: 'login',
|
|
384
|
-
argHint: '[
|
|
385
|
-
description: '
|
|
372
|
+
argHint: '[gateway]',
|
|
373
|
+
description: 'Log in to the codex-gateway account in your browser',
|
|
386
374
|
async run(args) {
|
|
387
375
|
const cfg = app.runtime.config;
|
|
388
|
-
|
|
389
|
-
if (choice
|
|
390
|
-
if (!choice) {
|
|
391
|
-
const saved = readGatewayLogin(cfg.gatewayUrl);
|
|
392
|
-
const codex = codexLoginSummary({ ...process.env, ...cfg.env });
|
|
393
|
-
choice = await app.showDialog(new SelectDialog({
|
|
394
|
-
title: 'Log in',
|
|
395
|
-
question: `Now: ${c.bold(cfg.provider)} (${cfg.endpointLabel})`,
|
|
396
|
-
options: [
|
|
397
|
-
{ label: `Gateway ${cfg.gatewayUrl} ${c.dim(saved ? `(logged in as ${saved.account?.email || 'this machine'}; paid from the account balance)` : '(log in in the browser; paid from the account balance)')}`, value: 'gateway' },
|
|
398
|
-
{ label: `Claude subscription ${c.dim('(the login of the claude command on this computer)')}`, value: 'claude-code' },
|
|
399
|
-
{ label: `Codex subscription ${c.dim(codex.ok ? `(the local Codex login${codex.plan ? `, ${codex.plan}` : ''})` : '(run `codex login` first)')}`, value: 'codex' },
|
|
400
|
-
],
|
|
401
|
-
}));
|
|
402
|
-
if (!choice) return;
|
|
403
|
-
}
|
|
404
|
-
if (!['claude-code', 'gateway', 'codex'].includes(choice)) { out(c.red(`Unknown choice "${choice}". Use claude, gateway or codex.`)); return; }
|
|
405
|
-
if (choice !== cfg.provider && !(await confirmCacheLoss('Switching the provider'))) { out(c.dim('Nothing was changed.')); return; }
|
|
406
|
-
|
|
407
|
-
if (choice === 'claude-code') {
|
|
408
|
-
try { readClaudeCodeLogin(cfg); } catch (e) {
|
|
409
|
-
// An expired token is renewed at the first request; a missing login is not.
|
|
410
|
-
if (!/expired/i.test(e.message)) {
|
|
411
|
-
out(c.red(`The Claude subscription login cannot be used: ${e.message}. Log in with the official \`claude\` once, then run /login again.`));
|
|
412
|
-
return;
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
const note = switchProvider('claude-code');
|
|
416
|
-
out(`Using the ${c.bold('Claude subscription')}: ${cfg.mainModel.label}${note}`);
|
|
417
|
-
return;
|
|
418
|
-
}
|
|
419
|
-
if (choice === 'codex') {
|
|
420
|
-
const codex = codexLoginSummary({ ...process.env, ...cfg.env });
|
|
421
|
-
if (!codex.ok) { out(c.red(`The Codex login cannot be used: ${codex.error}`)); return; }
|
|
422
|
-
const note = switchProvider('codex');
|
|
423
|
-
out(`Using the ${c.bold('Codex subscription')}${codex.email ? ` (${codex.email}${codex.plan ? `, ${codex.plan}` : ''})` : ''}: ${cfg.mainModel.label}${note}`);
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
376
|
+
const choice = args.trim().toLowerCase();
|
|
377
|
+
if (choice && choice !== 'gateway') { out(c.red(`Unknown login method "${choice}". Only gateway login is supported.`)); return; }
|
|
426
378
|
|
|
427
|
-
// The gateway: a saved key that still works is used as it is; otherwise log in through the browser.
|
|
428
379
|
const url = cfg.gatewayUrl;
|
|
429
380
|
const saved = readGatewayLogin(url);
|
|
430
381
|
if (saved) {
|
|
@@ -436,7 +387,7 @@ export function buildCommands(app) {
|
|
|
436
387
|
return;
|
|
437
388
|
} catch (e) {
|
|
438
389
|
if (e.status !== 401 && e.status !== 403) { out(c.red(`Cannot reach the gateway ${url}: ${e.message}`)); return; }
|
|
439
|
-
clearGatewayLogin();
|
|
390
|
+
clearGatewayLogin();
|
|
440
391
|
}
|
|
441
392
|
}
|
|
442
393
|
pendingLogin?.abort();
|
|
@@ -468,8 +419,8 @@ export function buildCommands(app) {
|
|
|
468
419
|
const wasOnline = Boolean(app.remote);
|
|
469
420
|
app.stopRemote(); // the other sessions of this computer and its computer service follow within seconds
|
|
470
421
|
out(had
|
|
471
|
-
? `Logged out of the gateway ${cfg.gatewayUrl}.${wasOnline ? ' This session is offline there now.' : ''}
|
|
472
|
-
: c.dim('There was no gateway login.
|
|
422
|
+
? `Logged out of the gateway ${cfg.gatewayUrl}.${wasOnline ? ' This session is offline there now.' : ''} Run /login to log in again.`
|
|
423
|
+
: c.dim('There was no gateway login. Run /login to log in.'));
|
|
473
424
|
},
|
|
474
425
|
});
|
|
475
426
|
|
|
@@ -488,10 +439,7 @@ export function buildCommands(app) {
|
|
|
488
439
|
row('cwd', app.cwd),
|
|
489
440
|
row('Provider', cfg.provider),
|
|
490
441
|
row('Endpoint', cfg.endpointLabel),
|
|
491
|
-
row('Auth', cfg.
|
|
492
|
-
: cfg.usesGateway ? (readGatewayLogin(cfg.gatewayUrl) ? `gateway key of ${readGatewayLogin(cfg.gatewayUrl).account?.email || 'this machine'} ${c.dim('(/cost shows the balance)')}` : c.red('not logged in (/login)'))
|
|
493
|
-
: cfg.usesCodex ? (() => { const s = codexLoginSummary({ ...process.env, ...cfg.env }); return s.ok ? `Codex login${s.email ? ` of ${s.email}` : ''}${s.plan ? ` (${s.plan})` : ''} ${c.dim(s.file)}` : c.red(s.error); })()
|
|
494
|
-
: cfg.authToken ? `ANTHROPIC_AUTH_TOKEN (${cfg.display('ANTHROPIC_AUTH_TOKEN')})` : cfg.apiKey ? `ANTHROPIC_API_KEY (${cfg.display('ANTHROPIC_API_KEY')})` : c.red('none')),
|
|
442
|
+
row('Auth', gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY) ? `gateway key of ${gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY).account?.email || 'this machine'} ${c.dim('(/cost shows the balance)')}` : c.red('not logged in (/login)')),
|
|
495
443
|
row('Model', `${cfg.mainModel.label} ${c.dim(`(sent as "${cfg.mainModel.id}", ${formatTokens(cfg.mainModel.contextWindow)} context)`)}`),
|
|
496
444
|
row('Sub-agent model', cfg.subagentModelChosen ? `chosen per task by difficulty ${c.dim(`(haiku, sonnet or opus; not chosen: ${cfg.subagentModel.label})`)}` : cfg.subagentModel.label),
|
|
497
445
|
row('Small model', cfg.smallModel.label),
|
|
@@ -544,7 +492,7 @@ export function buildCommands(app) {
|
|
|
544
492
|
`Session time: ${formatDuration(Date.now() - app.sessionStart)}`,
|
|
545
493
|
]);
|
|
546
494
|
const cfg = app.runtime.config;
|
|
547
|
-
const saved = cfg.usesGateway &&
|
|
495
|
+
const saved = cfg.usesGateway && gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
548
496
|
if (!saved) return;
|
|
549
497
|
try {
|
|
550
498
|
const account = await fetchGatewayAccount(saved);
|
|
@@ -665,21 +613,12 @@ export function buildCommands(app) {
|
|
|
665
613
|
...(remote.length ? [c.dim('On your other computers, through the gateway:'), ...remote.map((p) => `${c.bold('&' + p.label)} ${c.dim(`${p.cwd}${p.busy ? ' · busy' : ''}`)}`)] : []),
|
|
666
614
|
...(local.length || remote.length ? [] : [c.dim('No other session is running.')]),
|
|
667
615
|
c.dim(online
|
|
668
|
-
? 'Type "&" for the list, "&name task" to send a task; its answer is shown here. On another computer: "&computer/name task", or "&computer task" when it runs one session. /
|
|
616
|
+
? 'Type "&" for the list, "&name task" to send a task; its answer is shown here. On another computer: "&computer/name task", or "&computer task" when it runs one session. /rename names this session. The agent can use ListPeers / MessagePeer too.'
|
|
669
617
|
: 'Type "&" for the list, "&name task" to send a task; its answer is shown here. Sessions on your other computers show up here once this one is online at the gateway (/login; /status says why it is not).'),
|
|
670
618
|
]);
|
|
671
619
|
},
|
|
672
620
|
});
|
|
673
621
|
|
|
674
|
-
add({
|
|
675
|
-
name: 'sendfile',
|
|
676
|
-
aliases: ['sf'],
|
|
677
|
-
argHint: '&session <file...>',
|
|
678
|
-
argRequired: true,
|
|
679
|
-
description: 'Send files to another session, on this computer or on another one: it saves them in its Downloads folder',
|
|
680
|
-
async run(args) { await app.sendFiles(args); },
|
|
681
|
-
});
|
|
682
|
-
|
|
683
622
|
add({
|
|
684
623
|
name: 'tui',
|
|
685
624
|
argHint: '[fullscreen | default]',
|
|
@@ -916,11 +855,7 @@ export function buildCommands(app) {
|
|
|
916
855
|
`${c.green('✔')} Node ${process.versions.node}`,
|
|
917
856
|
`${app.runtime.shell.kind === 'bash' ? c.green('✔') : c.yellow('!')} Shell: ${app.runtime.shell.name} (${app.runtime.shell.path})`,
|
|
918
857
|
`${rg ? c.green('✔') : c.yellow('!')} ripgrep ${rg ? 'found' : 'not found (Grep uses the built-in JS scanner, which is slower; set CLAUDE_PRO_RIPGREP_PATH to use an rg.exe)'}`,
|
|
919
|
-
cfg.
|
|
920
|
-
? `${c.yellow('!')} Claude subscription: ${cfg.claudeCodeCredentialsFile} (checked by the request below)`
|
|
921
|
-
: cfg.usesGateway ? `${readGatewayLogin(cfg.gatewayUrl) ? c.green('✔') : c.red('✘')} Gateway login for ${cfg.gatewayUrl}${readGatewayLogin(cfg.gatewayUrl) ? '' : ' missing (/login)'}`
|
|
922
|
-
: cfg.usesCodex ? (() => { const s = codexLoginSummary({ ...process.env, ...cfg.env }); return `${s.ok ? c.green('✔') : c.red('✘')} Codex login ${s.ok ? s.file : s.error}`; })()
|
|
923
|
-
: `${cfg.authToken || cfg.apiKey ? c.green('✔') : c.red('✘')} Credentials ${cfg.authToken ? 'ANTHROPIC_AUTH_TOKEN' : cfg.apiKey ? 'ANTHROPIC_API_KEY' : 'missing'}`,
|
|
858
|
+
`${gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY) ? c.green('✔') : c.red('✘')} Gateway login for ${cfg.gatewayUrl}${gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY) ? '' : ' missing (/login)'}`,
|
|
924
859
|
];
|
|
925
860
|
out(lines);
|
|
926
861
|
app.busy = true;
|
package/src/config.js
CHANGED
|
@@ -15,7 +15,6 @@ import path from 'node:path';
|
|
|
15
15
|
import os from 'node:os';
|
|
16
16
|
import { fileURLToPath } from 'node:url';
|
|
17
17
|
import { normalizeTtl } from './cache.js';
|
|
18
|
-
import { codexModels, codexConfigDefaults } from './codex/client.js';
|
|
19
18
|
|
|
20
19
|
export const INSTALL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
21
20
|
// A source checkout (a git clone, also when npm links to one), as opposed to a copy installed from npm: the agent
|
|
@@ -23,48 +22,29 @@ export const INSTALL_DIR = path.resolve(path.dirname(fileURLToPath(import.meta.u
|
|
|
23
22
|
export const SOURCE_CHECKOUT = fs.existsSync(path.join(INSTALL_DIR, '.git'));
|
|
24
23
|
export const CONFIG_DIR = process.env.CLAUDE_PRO_CONFIG_DIR || path.join(os.homedir(), '.claude-pro');
|
|
25
24
|
export const APP_NAME = 'claude-pro';
|
|
26
|
-
export const PROVIDERS = ['
|
|
25
|
+
export const PROVIDERS = ['gateway'];
|
|
27
26
|
export const GATEWAY_DEFAULT_URL = 'https://gw.predix.icu';
|
|
28
|
-
// The codex provider's model when neither CLAUDE_PRO_CODEX_MODEL nor the Codex config.toml names one.
|
|
29
|
-
export const CODEX_DEFAULT_MODEL = 'gpt-6.1-sol';
|
|
30
27
|
export const VERSION = JSON.parse(fs.readFileSync(path.join(INSTALL_DIR, 'package.json'), 'utf8')).version;
|
|
31
28
|
|
|
32
29
|
// Every key we understand, with a short description (shown by /config).
|
|
33
30
|
export const KNOWN_KEYS = {
|
|
34
|
-
CLAUDE_PRO_PROVIDER: 'Authentication backend: gateway
|
|
35
|
-
CLAUDE_PRO_GATEWAY_URL: `codex-gateway address
|
|
31
|
+
CLAUDE_PRO_PROVIDER: 'Authentication backend: gateway only (codex-gateway account, /login)',
|
|
32
|
+
CLAUDE_PRO_GATEWAY_URL: `codex-gateway address (default https://gw.predix.icu)`,
|
|
33
|
+
CLAUDE_PRO_GATEWAY_API_KEY: 'Gateway API key (normally saved by /login in gateway.json)',
|
|
36
34
|
CLAUDE_PRO_GATEWAY_MODEL: 'Model with the gateway provider (default: opus; also sonnet, haiku, gpt-6.1-sol)',
|
|
37
|
-
CLAUDE_PRO_CODEX_MODEL: 'Model with the codex provider (default: the model in ~/.codex/config.toml, else gpt-6.1-sol)',
|
|
38
|
-
CLAUDE_PRO_CLAUDE_CONFIG_FILE: 'Claude subscription: the account metadata file of the claude command (default: ~/.claude.json)',
|
|
39
|
-
CLAUDE_PRO_CLAUDE_CREDENTIALS_FILE: 'Claude subscription: the credentials file of the claude command (default: ~/.claude/.credentials.json)',
|
|
40
|
-
CLAUDE_PRO_CLAUDE_CODE_VERSION: 'Claude subscription: the claude command version sent in the User-Agent (default: the installed one)',
|
|
41
|
-
CLAUDE_PRO_DISABLE_TOKEN_REFRESH: 'Set to 1 to stop this program renewing the Claude subscription login by itself (it then only reads what the official client keeps up to date)',
|
|
42
35
|
CLAUDE_PRO_ONLINE: 'Internal (the self-check and the tests set it): 0 keeps interactive sessions off the gateway. Otherwise a session is online there whenever this computer is logged in to the gateway: its 远程控制 page shows it, and sessions on your other computers can send it tasks (&computer/name)',
|
|
43
36
|
CLAUDE_PRO_HOST: 'Set to 0 so that sessions do not start the computer service (claude-pro host) by themselves; the service lets the gateway\'s 远程控制 page open new sessions on this computer',
|
|
44
|
-
CLAUDE_PRO_DOWNLOAD_DIR: 'Where files that other sessions send this one are saved (default: the Downloads folder)',
|
|
45
37
|
CLAUDE_PRO_MACHINE_NAME: 'This computer\'s name for sessions on your other computers (@公司 ...; default: the host name)',
|
|
46
38
|
CLAUDE_PRO_TUI: 'fullscreen (default: the input box fixed at the bottom, the conversation scrolled inside) or default (classic: it scrolls in the terminal); /tui switches',
|
|
47
39
|
CLAUDE_PRO_AUTO_RESTART: 'Restart by itself when a turn ends and claude-pro\'s own source files changed (default 1; 0 = only on /restart or the Restart tool)',
|
|
48
|
-
|
|
49
|
-
CLAUDE_CONFIG_DIR: 'Configuration directory of the claude command, for selecting its signed-in account (Claude subscription)',
|
|
50
|
-
ANTHROPIC_BASE_URL: 'API base URL (Anthropic compatible endpoint)',
|
|
51
|
-
ANTHROPIC_AUTH_TOKEN: 'Bearer token sent as Authorization header',
|
|
52
|
-
ANTHROPIC_API_KEY: 'API key sent as x-api-key header (used if no auth token)',
|
|
53
|
-
ANTHROPIC_CUSTOM_HEADERS: 'Extra headers, "Name: Value" separated by newlines',
|
|
54
|
-
ANTHROPIC_MODEL: 'Main model (name or alias opus/sonnet/haiku; suffix [1m] = 1M context)',
|
|
55
|
-
ANTHROPIC_DEFAULT_OPUS_MODEL: 'Model used for the "opus" alias',
|
|
56
|
-
ANTHROPIC_DEFAULT_SONNET_MODEL: 'Model used for the "sonnet" alias',
|
|
57
|
-
ANTHROPIC_DEFAULT_HAIKU_MODEL: 'Small/fast model (web page summarising, titles)',
|
|
58
|
-
ANTHROPIC_SMALL_FAST_MODEL: 'Deprecated alias of ANTHROPIC_DEFAULT_HAIKU_MODEL',
|
|
59
|
-
CLAUDE_CODE_SUBAGENT_MODEL: 'Model used by Task sub-agents (API providers; default: the main model)',
|
|
60
|
-
CLAUDE_PRO_CLAUDE_CODE_SUBAGENT_MODEL: 'Model used by Task sub-agents with the claude-code provider (default: sonnet)',
|
|
40
|
+
|
|
61
41
|
CLAUDE_CODE_EFFORT_LEVEL: 'Reasoning effort: none|minimal|low|medium|high|xhigh|max (sent as output_config.effort)',
|
|
62
42
|
CLAUDE_CODE_AUTO_COMPACT_WINDOW: 'Context size (tokens) used for auto-compaction calculations',
|
|
63
43
|
CLAUDE_AUTOCOMPACT_PCT_OVERRIDE: 'Percentage (1-100) of the window at which auto-compaction triggers',
|
|
64
44
|
DISABLE_AUTOCOMPACT: 'Set to 1 to disable auto-compaction',
|
|
65
|
-
CLAUDE_CODE_MAX_OUTPUT_TOKENS: 'max_tokens for each model response (default
|
|
45
|
+
CLAUDE_CODE_MAX_OUTPUT_TOKENS: 'max_tokens for each model response (default 48000; lowered automatically if the gateway allows less)',
|
|
66
46
|
MAX_THINKING_TOKENS: 'Thinking budget: 0 disables thinking, N enables with budget N',
|
|
67
|
-
CLAUDE_CODE_PROMPT_CACHE_TTL: 'Prompt cache TTL of the conversation itself: 5m or 1h (default: 1h with the
|
|
47
|
+
CLAUDE_CODE_PROMPT_CACHE_TTL: 'Prompt cache TTL of the conversation itself: 5m or 1h (default: 1h with the gateway; 1h writes cost more, they pay off when you pause for more than 5 minutes). Also the promptCacheTtl setting',
|
|
68
48
|
CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL: 'Prompt cache TTL of everything else (sub-agents, compaction, side queries): 5m (default) or 1h. Also the subagentPromptCacheTtl setting',
|
|
69
49
|
ENABLE_PROMPT_CACHING_1H: 'Set to 1 to request the 1-hour TTL for both (the two TTL variables above win over it)',
|
|
70
50
|
FORCE_PROMPT_CACHING_5M: 'Set to 1 to force the 5-minute TTL for both, over every other TTL setting',
|
|
@@ -89,7 +69,7 @@ export const KNOWN_KEYS = {
|
|
|
89
69
|
CLAUDE_PRO_DISABLE_TOPIC_TITLE: 'Set to 1 to stop asking the small model for the current topic after each message (the tab title then shows the first message of the session)',
|
|
90
70
|
};
|
|
91
71
|
|
|
92
|
-
const SECRET_KEYS = new Set(['
|
|
72
|
+
const SECRET_KEYS = new Set(['CLAUDE_PRO_GATEWAY_API_KEY']);
|
|
93
73
|
|
|
94
74
|
export function parseDotEnv(text) {
|
|
95
75
|
const env = {};
|
|
@@ -129,15 +109,7 @@ export function settingsFiles(cwd) {
|
|
|
129
109
|
};
|
|
130
110
|
}
|
|
131
111
|
|
|
132
|
-
|
|
133
|
-
// models, and how hard and how long that model works. The subscription provider (claude-code) does not take that
|
|
134
|
-
// tuning over: it starts from Claude Code's own defaults (the model's default effort, the model's whole context
|
|
135
|
-
// window), which is what makes it work without any setting. The same keys in a settings file, in the shell, as a
|
|
136
|
-
// flag, or chosen with /effort do apply there.
|
|
137
|
-
export const API_ONLY_DOTENV_KEYS = ['CLAUDE_CODE_EFFORT_LEVEL', 'CLAUDE_CODE_AUTO_COMPACT_WINDOW', 'CLAUDE_AUTOCOMPACT_PCT_OVERRIDE', 'CLAUDE_CODE_MAX_OUTPUT_TOKENS', 'MAX_THINKING_TOKENS'];
|
|
138
|
-
|
|
139
|
-
// The variable that holds the model, per provider.
|
|
140
|
-
const MODEL_KEYS = { api: 'ANTHROPIC_MODEL', 'claude-code': 'CLAUDE_PRO_CLAUDE_CODE_MODEL', gateway: 'CLAUDE_PRO_GATEWAY_MODEL', codex: 'CLAUDE_PRO_CODEX_MODEL' };
|
|
112
|
+
const MODEL_KEYS = { gateway: 'CLAUDE_PRO_GATEWAY_MODEL' };
|
|
141
113
|
|
|
142
114
|
export function loadConfig({ cwd = process.cwd(), flags = {}, dotEnvFile = path.join(INSTALL_DIR, '.env') } = {}) {
|
|
143
115
|
const env = {};
|
|
@@ -167,7 +139,7 @@ export function loadConfig({ cwd = process.cwd(), flags = {}, dotEnvFile = path.
|
|
|
167
139
|
for (const [event, entries] of Object.entries(json.hooks || {})) {
|
|
168
140
|
if (Array.isArray(entries)) (settings.hooks[event] ||= []).push(...entries);
|
|
169
141
|
}
|
|
170
|
-
if (json.model) { env.
|
|
142
|
+
if (json.model) { env.CLAUDE_PRO_GATEWAY_MODEL = json.model; sources.CLAUDE_PRO_GATEWAY_MODEL = `${file} (model)`; }
|
|
171
143
|
settings[scope] = json;
|
|
172
144
|
}
|
|
173
145
|
// Project level .mcp.json, same format as Claude Code.
|
|
@@ -180,24 +152,13 @@ export function loadConfig({ cwd = process.cwd(), flags = {}, dotEnvFile = path.
|
|
|
180
152
|
|
|
181
153
|
if (flags.provider) { env.CLAUDE_PRO_PROVIDER = flags.provider; sources.CLAUDE_PRO_PROVIDER = '--provider flag'; }
|
|
182
154
|
if (flags.model) {
|
|
183
|
-
const key = MODEL_KEYS[(env.CLAUDE_PRO_PROVIDER || '').trim().toLowerCase()] || '
|
|
155
|
+
const key = MODEL_KEYS[(env.CLAUDE_PRO_PROVIDER || 'gateway').trim().toLowerCase()] || 'CLAUDE_PRO_GATEWAY_MODEL';
|
|
184
156
|
env[key] = flags.model;
|
|
185
157
|
sources[key] = '--model flag';
|
|
186
158
|
}
|
|
187
159
|
if (flags.effort) { env.CLAUDE_CODE_EFFORT_LEVEL = flags.effort; sources.CLAUDE_CODE_EFFORT_LEVEL = '--effort flag'; }
|
|
188
160
|
|
|
189
|
-
|
|
190
|
-
if (!['', 'api'].includes((env.CLAUDE_PRO_PROVIDER || '').trim().toLowerCase())) {
|
|
191
|
-
for (const key of API_ONLY_DOTENV_KEYS) {
|
|
192
|
-
if (sources[key] !== dotEnvFile) continue;
|
|
193
|
-
delete env[key];
|
|
194
|
-
delete sources[key];
|
|
195
|
-
ignoredFromDotEnv.push(key);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
const config = new Config(env, sources, settings, cwd);
|
|
199
|
-
config.ignoredFromDotEnv = ignoredFromDotEnv; // shown by /config
|
|
200
|
-
return config;
|
|
161
|
+
return new Config(env, sources, settings, cwd);
|
|
201
162
|
}
|
|
202
163
|
|
|
203
164
|
const int = (v, d) => {
|
|
@@ -217,64 +178,19 @@ export class Config {
|
|
|
217
178
|
this.effortBoost = null; // set by the model with the Effort tool, for the rest of the user's current request
|
|
218
179
|
this.effortBoostKeepNext = false; // a restart continues the request: the next turn keeps the boost
|
|
219
180
|
this.verifyOverride = null; // set by /verify or --verify during a session
|
|
220
|
-
this.ignoredFromDotEnv = []; // .env keys that are not applied because of the provider (see API_ONLY_DOTENV_KEYS)
|
|
221
181
|
}
|
|
222
182
|
|
|
223
|
-
// Not set: an API endpoint, key or model that is configured (.env, settings) means the api provider, as before;
|
|
224
|
-
// otherwise the gateway, where /login gets an account in the browser.
|
|
225
183
|
get provider() {
|
|
226
|
-
const
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return value;
|
|
184
|
+
const value = (this.env.CLAUDE_PRO_PROVIDER || 'gateway').trim().toLowerCase();
|
|
185
|
+
if (value !== 'gateway') throw new Error(`Only the gateway provider is supported. Set CLAUDE_PRO_PROVIDER=gateway (received ${value}).`);
|
|
186
|
+
return 'gateway';
|
|
230
187
|
}
|
|
231
|
-
get
|
|
232
|
-
get usesGateway() { return this.provider === 'gateway'; }
|
|
233
|
-
get usesCodex() { return this.provider === 'codex'; }
|
|
188
|
+
get usesGateway() { return true; }
|
|
234
189
|
get gatewayUrl() { return (this.env.CLAUDE_PRO_GATEWAY_URL || GATEWAY_DEFAULT_URL).trim().replace(/\/+$/, ''); }
|
|
235
|
-
|
|
236
|
-
// Claude through a subscription login too).
|
|
237
|
-
get claudeIds() { return this.usesClaudeCode || this.usesGateway; }
|
|
238
|
-
get claudeCodeConfigFile() { return path.resolve(this.cwd, this.env.CLAUDE_PRO_CLAUDE_CONFIG_FILE || path.join(os.homedir(), '.claude.json')); }
|
|
239
|
-
get claudeCodeCredentialsFile() {
|
|
240
|
-
return path.resolve(this.cwd, this.env.CLAUDE_PRO_CLAUDE_CREDENTIALS_FILE || path.join(
|
|
241
|
-
this.env.CLAUDE_CONFIG_DIR || path.join(path.dirname(this.claudeCodeConfigFile), '.claude'), '.credentials.json'));
|
|
242
|
-
}
|
|
243
|
-
get endpointLabel() {
|
|
244
|
-
if (this.usesClaudeCode) return 'https://api.anthropic.com (Claude subscription)';
|
|
245
|
-
if (this.usesGateway) return `${this.gatewayUrl} (codex-gateway)`;
|
|
246
|
-
if (this.usesCodex) return 'https://chatgpt.com/backend-api/codex (Codex login)';
|
|
247
|
-
return this.baseURL;
|
|
248
|
-
}
|
|
249
|
-
get baseURL() { return this.env.ANTHROPIC_BASE_URL || 'https://api.anthropic.com'; }
|
|
250
|
-
get authToken() { return this.env.ANTHROPIC_AUTH_TOKEN || null; }
|
|
251
|
-
get apiKey() { return this.env.ANTHROPIC_API_KEY || null; }
|
|
252
|
-
get customHeaders() {
|
|
253
|
-
const headers = {};
|
|
254
|
-
for (const line of (this.env.ANTHROPIC_CUSTOM_HEADERS || '').split(/\n/)) {
|
|
255
|
-
const i = line.indexOf(':');
|
|
256
|
-
if (i > 0) headers[line.slice(0, i).trim()] = line.slice(i + 1).trim();
|
|
257
|
-
}
|
|
258
|
-
return headers;
|
|
259
|
-
}
|
|
190
|
+
get endpointLabel() { return `${this.gatewayUrl} (codex-gateway)`; }
|
|
260
191
|
|
|
261
192
|
aliasTarget(alias) {
|
|
262
|
-
|
|
263
|
-
return { opus: 'claude-opus-5-5', sonnet: 'claude-sonnet-5-5', haiku: 'claude-haiku-5-5' }[alias] || null;
|
|
264
|
-
}
|
|
265
|
-
// The gateway prices models by their undated names.
|
|
266
|
-
if (this.usesGateway) return { opus: 'claude-opus-5-5', sonnet: 'claude-sonnet-5-5', haiku: 'claude-haiku-5-5' }[alias] || null;
|
|
267
|
-
if (this.usesCodex) {
|
|
268
|
-
// No Claude here: the big aliases mean the Codex model, haiku the small one when the Codex install has it.
|
|
269
|
-
if (alias === 'haiku') return codexModels(this.env).models.some((m) => m.slug === 'gpt-6-luna') ? 'gpt-6-luna' : this.codexModelSpec;
|
|
270
|
-
return alias === 'opus' || alias === 'sonnet' ? this.codexModelSpec : null;
|
|
271
|
-
}
|
|
272
|
-
switch (alias) {
|
|
273
|
-
case 'opus': return this.env.ANTHROPIC_DEFAULT_OPUS_MODEL || 'claude-opus-4-5';
|
|
274
|
-
case 'sonnet': return this.env.ANTHROPIC_DEFAULT_SONNET_MODEL || 'claude-sonnet-4-5';
|
|
275
|
-
case 'haiku': return this.env.ANTHROPIC_DEFAULT_HAIKU_MODEL || this.env.ANTHROPIC_SMALL_FAST_MODEL || 'claude-haiku-4-5';
|
|
276
|
-
default: return null;
|
|
277
|
-
}
|
|
193
|
+
return { opus: 'claude-opus-5-5', sonnet: 'claude-sonnet-5-5', haiku: 'claude-haiku-5-5' }[alias] || null;
|
|
278
194
|
}
|
|
279
195
|
|
|
280
196
|
// Resolve a model spec (alias or name, maybe with [1m]) to {id, contextWindow, label}.
|
|
@@ -287,36 +203,18 @@ export class Config {
|
|
|
287
203
|
const inner = this.resolveModel(aliased);
|
|
288
204
|
return { ...inner, contextWindow: oneM ? 1_000_000 : inner.contextWindow, label: `${name}${oneM ? '[1m]' : ''} (${inner.label})` };
|
|
289
205
|
}
|
|
290
|
-
const nativeOneM =
|
|
291
|
-
//
|
|
292
|
-
|
|
293
|
-
if (/^gpt-/i.test(name)) {
|
|
294
|
-
const known = codexModels(this.env).models.find((m) => m.slug === name)?.contextWindow;
|
|
295
|
-
return { id: name, contextWindow: known || 272_000, label: name };
|
|
296
|
-
}
|
|
206
|
+
const nativeOneM = /^claude-(?:(?:sonnet|haiku)-5(?:-|$)|opus-(?:5(?:-|$)|4-[78](?:-|$)))/i.test(name);
|
|
207
|
+
// GPT models are served by the gateway's Codex backend and use its standard context window.
|
|
208
|
+
if (/^gpt-/i.test(name)) return { id: name, contextWindow: 272_000, label: name };
|
|
297
209
|
return { id: name, contextWindow: oneM || nativeOneM ? 1_000_000 : 200_000, label: `${name}${oneM ? '[1m]' : ''}` };
|
|
298
210
|
}
|
|
299
211
|
|
|
300
|
-
// The model the
|
|
301
|
-
get configuredModelSpec() {
|
|
302
|
-
if (this.usesGateway) return this.env.CLAUDE_PRO_GATEWAY_MODEL || 'opus';
|
|
303
|
-
if (this.usesCodex) return this.codexModelSpec;
|
|
304
|
-
return (this.usesClaudeCode ? this.env.CLAUDE_PRO_CLAUDE_CODE_MODEL : this.env.ANTHROPIC_MODEL) || 'sonnet';
|
|
305
|
-
}
|
|
306
|
-
get codexModelSpec() { return this.env.CLAUDE_PRO_CODEX_MODEL || codexConfigDefaults(this.env).model || CODEX_DEFAULT_MODEL; }
|
|
212
|
+
// The model the gateway is configured with, before any /model override.
|
|
213
|
+
get configuredModelSpec() { return this.env.CLAUDE_PRO_GATEWAY_MODEL || 'opus'; }
|
|
307
214
|
get mainModelSpec() { return this.modelOverride || this.configuredModelSpec; }
|
|
308
215
|
get mainModel() { return this.resolveModel(this.mainModelSpec); }
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
// well-specified subtasks they are given. CLAUDE_PRO_CLAUDE_CODE_SUBAGENT_MODEL (or a sub-agent's own model) changes it.
|
|
312
|
-
if (this.usesClaudeCode) return this.resolveModel(this.env.CLAUDE_PRO_CLAUDE_CODE_SUBAGENT_MODEL || 'sonnet');
|
|
313
|
-
// The gateway: no fixed sub-agent model. Under a Claude main model the main agent picks one for each Task by how
|
|
314
|
-
// hard the task is (see subagentModelChosen and the Task tool's description); this is what an agent runs on when
|
|
315
|
-
// it was not given one: the main model. A GPT main model keeps its own.
|
|
316
|
-
if (this.usesGateway) return this.mainModel;
|
|
317
|
-
if (this.usesCodex) return this.mainModel;
|
|
318
|
-
return this.env.CLAUDE_CODE_SUBAGENT_MODEL ? this.resolveModel(this.env.CLAUDE_CODE_SUBAGENT_MODEL) : this.mainModel;
|
|
319
|
-
}
|
|
216
|
+
// The gateway lets the main agent choose Claude sub-agent models by task difficulty.
|
|
217
|
+
get subagentModel() { return this.mainModel; }
|
|
320
218
|
// The main agent chooses each sub-agent's model (haiku, sonnet, opus) by the task, rather than one being set.
|
|
321
219
|
get subagentModelChosen() { return this.usesGateway && /^claude-/i.test(this.mainModel.id); }
|
|
322
220
|
get smallModel() { return this.resolveModel('haiku'); }
|
|
@@ -331,15 +229,14 @@ export class Config {
|
|
|
331
229
|
// The gateway holds back balance for max_tokens of output before each request, so a smaller default there keeps a
|
|
332
230
|
// modest balance usable. 48K: in 812 Opus requests through it (2026-10-12) p99 was 14K, three went over 24K (the
|
|
333
231
|
// longest that finished: 27K) and one was cut off at the old 32K; the hold is $0.96 on Opus instead of $0.64.
|
|
334
|
-
get maxOutputTokens() { return int(this.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS,
|
|
232
|
+
get maxOutputTokens() { return int(this.env.CLAUDE_CODE_MAX_OUTPUT_TOKENS, 48_000); }
|
|
335
233
|
get thinkingBudget() {
|
|
336
234
|
return this.env.MAX_THINKING_TOKENS === undefined ? null : int(this.env.MAX_THINKING_TOKENS, null);
|
|
337
235
|
}
|
|
338
236
|
// Prompt cache TTL for a request bucket, by Claude Code's rules: "main" is the conversation itself, "other"
|
|
339
237
|
// is everything else (sub-agents, compaction, side queries). In order: FORCE_PROMPT_CACHING_5M; the bucket's
|
|
340
|
-
// own variable or setting; ENABLE_PROMPT_CACHING_1H; then the default:
|
|
341
|
-
//
|
|
342
|
-
// usage); with an API key or another endpoint, and for everything else, 5 minutes.
|
|
238
|
+
// own variable or setting; ENABLE_PROMPT_CACHING_1H; then the gateway default: the conversation's own
|
|
239
|
+
// requests use 1 hour and everything else uses 5 minutes.
|
|
343
240
|
cacheTtl(bucket = 'main') {
|
|
344
241
|
if (isOn(this.env.FORCE_PROMPT_CACHING_5M)) return '5m';
|
|
345
242
|
// an invalid value is ignored, and the next rule applies (as in Claude Code)
|
|
@@ -350,7 +247,7 @@ export class Config {
|
|
|
350
247
|
if (isOn(this.env.ENABLE_PROMPT_CACHING_1H)) return '1h';
|
|
351
248
|
// The gateway too: measured on its usage records (533 Opus requests), pauses of 5 to 60 minutes rewrote the whole
|
|
352
249
|
// conversation 9 times at 1.25x, $14.77; writing every turn at 2x instead costs $2.80 more.
|
|
353
|
-
return bucket === 'main' &&
|
|
250
|
+
return bucket === 'main' && this.usesGateway ? '1h' : '5m';
|
|
354
251
|
}
|
|
355
252
|
// DISABLE_PROMPT_CACHING turns it off for everything; the per-model variables only for the model that
|
|
356
253
|
// their alias resolves to (a different version pinned as the model keeps its caching), wherever it runs.
|
|
@@ -394,11 +291,9 @@ export class Config {
|
|
|
394
291
|
get bashMaxOutput() { return int(this.env.BASH_MAX_OUTPUT_LENGTH, 60_000); }
|
|
395
292
|
// Tool results longer than this are saved to a file and only a preview is sent.
|
|
396
293
|
get maxToolResultChars() { return 100_000; }
|
|
397
|
-
// Clearing old tool results after a long pause (see Agent.clearAfterIdle):
|
|
398
|
-
//
|
|
399
|
-
get clearAfterIdle() {
|
|
400
|
-
return this.usesClaudeCode || this.usesGateway || /^https:\/\/api\.anthropic\.com\/?$/i.test(this.baseURL);
|
|
401
|
-
}
|
|
294
|
+
// Clearing old tool results after a long pause (see Agent.clearAfterIdle): the gateway prompt cache has
|
|
295
|
+
// expired by then, so retaining old tool payloads would only make the next request larger.
|
|
296
|
+
get clearAfterIdle() { return true; }
|
|
402
297
|
// How deep sub-agents may nest: the main agent is depth 0; an agent below this depth gets the Task tool.
|
|
403
298
|
get maxSubagentDepth() { return 2; }
|
|
404
299
|
|
package/src/gateway.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// The codex-gateway provider: model requests go to a shared gateway (https://gw.predix.icu by default) with an
|
|
2
|
-
// API key of the user's gateway account, which pays for them from its balance. /login
|
|
3
|
-
//
|
|
4
|
-
//
|
|
2
|
+
// API key of the user's gateway account, which pays for them from its balance. /login starts a local callback
|
|
3
|
+
// server, opens the gateway login page in the browser, and exchanges a one-time code for a key belonging to this machine
|
|
4
|
+
// (see handleCli in codex-gateway's server.mjs).
|
|
5
5
|
|
|
6
6
|
import crypto from 'node:crypto';
|
|
7
7
|
import fs from 'node:fs';
|
|
@@ -28,6 +28,12 @@ export function readGatewayLogin(url) {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
+
// A key supplied for a headless run is equivalent to a saved login for model and remote requests.
|
|
32
|
+
// It has no account metadata, so the UI uses a neutral account label.
|
|
33
|
+
export function gatewayLogin(url, apiKey = process.env.CLAUDE_PRO_GATEWAY_API_KEY) {
|
|
34
|
+
return readGatewayLogin(url) || (apiKey ? { url: normalizeGatewayUrl(url), apiKey, account: {} } : null);
|
|
35
|
+
}
|
|
36
|
+
|
|
31
37
|
export function saveGatewayLogin(login) {
|
|
32
38
|
const file = gatewayLoginFile();
|
|
33
39
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
package/src/host.js
CHANGED
|
@@ -27,7 +27,7 @@ import path from 'node:path';
|
|
|
27
27
|
import crypto from 'node:crypto';
|
|
28
28
|
import { spawn, spawnSync } from 'node:child_process';
|
|
29
29
|
import { CONFIG_DIR, INSTALL_DIR, VERSION, GATEWAY_DEFAULT_URL, loadConfig } from './config.js';
|
|
30
|
-
import {
|
|
30
|
+
import { gatewayLogin, normalizeGatewayUrl } from './gateway.js';
|
|
31
31
|
import { machineName, cleanName, listPeers } from './peers.js';
|
|
32
32
|
import { BackgroundSessions, markEnded, tailFile } from './background.js';
|
|
33
33
|
import { listConversations, deleteConversation, CONVERSATION_ID } from './history.js';
|
|
@@ -411,7 +411,7 @@ const shQuote = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
|
411
411
|
// The settings of this service's environment that a session it opens needs too (the config directory, the
|
|
412
412
|
// gateway's address, the computer's name ...): Windows Terminal starts the program with its own environment, and
|
|
413
413
|
// tmux and a desktop's terminal with theirs. Not the secrets: those stay where they were set.
|
|
414
|
-
const PASS_ENV = /^(CLAUDE_PRO_|
|
|
414
|
+
const PASS_ENV = /^(CLAUDE_PRO_|CLAUDE_CODE_)/;
|
|
415
415
|
const SECRET = /TOKEN|KEY|SECRET|PASSWORD|HEADERS/i;
|
|
416
416
|
export function passedEnv(env = process.env) {
|
|
417
417
|
const out = {};
|
|
@@ -527,7 +527,10 @@ export class HostService {
|
|
|
527
527
|
this.launch = launch;
|
|
528
528
|
this.home = home;
|
|
529
529
|
this.loadConfig = load || (() => loadConfig({ cwd: home }));
|
|
530
|
-
this.readLogin = readLogin || (() =>
|
|
530
|
+
this.readLogin = readLogin || (() => {
|
|
531
|
+
const cfg = this.cfg();
|
|
532
|
+
return gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
533
|
+
});
|
|
531
534
|
this.config = null;
|
|
532
535
|
this.configAt = 0;
|
|
533
536
|
this.login = null; // {url, apiKey, account} of gateway.json
|
|
@@ -1119,7 +1122,7 @@ export async function runHost({ background = false } = {}) {
|
|
|
1119
1122
|
|
|
1120
1123
|
async function gatewayRequest(method, route) {
|
|
1121
1124
|
const cfg = loadConfig({ cwd: os.homedir() });
|
|
1122
|
-
const login =
|
|
1125
|
+
const login = gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
1123
1126
|
if (!login) return false;
|
|
1124
1127
|
const res = await fetch(`${normalizeGatewayUrl(login.url || cfg.gatewayUrl)}${route}`, { method, headers: { authorization: `Bearer ${login.apiKey}` }, signal: AbortSignal.timeout(8000) });
|
|
1125
1128
|
return res.ok || res.status === 404;
|
|
@@ -1138,7 +1141,7 @@ async function startCommand() {
|
|
|
1138
1141
|
const now = readHostState();
|
|
1139
1142
|
if (hostRunning(now)) {
|
|
1140
1143
|
const cfg = loadConfig({ cwd: os.homedir() });
|
|
1141
|
-
const login =
|
|
1144
|
+
const login = gatewayLogin(cfg.gatewayUrl, cfg.env.CLAUDE_PRO_GATEWAY_API_KEY);
|
|
1142
1145
|
console.log(`claude-pro host started in the background (pid ${now.pid}). Log: ${hostFiles().log}`);
|
|
1143
1146
|
if (!login) console.log(`This computer is not logged in to the gateway ${cfg.gatewayUrl}: it waits until /login in a session.`);
|
|
1144
1147
|
return 0;
|