Skip to content

Commit bf92403

Browse files
floodsungFlood Sungclaude
authored andcommitted
fix(claude): only enable 1M context beta when model has [1m] suffix (xvirobotics#273)
Both executors unconditionally set: queryOptions.betas = ['context-1m-2025-08-07']; The comment acknowledged this was a no-op on OAuth / Pro-Max (where betas are ignored and the `[1m]` suffix is the actual lever), but on API-key auth the SDK honors the beta header — so every API-key user got 1M context for *every* model, including plain `opus-4-7`. Visible symptom: `/model claude-opus-4-7` showed a 1000k context window in the card footer (and billed at 2× the rate) instead of the expected 200k. The user only intended 1M on the explicit `claude-opus-4-7[1m]` form. Fix: only emit the beta flag when the model name contains `[1m]`. That makes the suffix the single canonical signal for both auth paths — SDK parses it directly, and we re-send the matching beta as belt-and-braces for any auth mode that needs the explicit header. Both `executor.ts` and `persistent-executor.ts` had the same unconditional line; both fixed. Comment notes they must stay in sync. No new tests — the SDK's beta dispatch is mocked away in vitest, and the change is one conditional. All 291 existing tests still pass. Co-authored-by: Flood Sung <floodsung@xvirobotics.ai> Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 30e4983 commit bf92403

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/engines/claude/executor.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,20 @@ export class ClaudeExecutor {
365365
queryOptions.resume = sessionId;
366366
}
367367

368-
// Beta flags are ignored by the SDK on OAuth/Pro-Max auth. For 1M context,
369-
// use the model-name suffix `[1m]` (e.g. `claude-opus-4-7[1m]`) instead.
370-
queryOptions.betas = ['context-1m-2025-08-07'];
368+
// 1M context window is opt-in via the `[1m]` model-name suffix
369+
// (`claude-opus-4-7[1m]`). The suffix is the canonical signal — the SDK
370+
// parses it directly on both OAuth and API-key auth paths.
371+
//
372+
// We *also* set the matching `betas` flag when the suffix is present,
373+
// belt-and-braces: harmless when the SDK already inferred it, and a
374+
// safety net if a future SDK rev only honors the explicit beta header
375+
// for some auth modes. Without the suffix, leave `betas` unset —
376+
// setting it unconditionally on API-key auth had the side-effect of
377+
// forcing every model (e.g. plain `opus-4-7`) into 1M context at 2×
378+
// the price, which the user never asked for.
379+
if (this.config.claude.model?.includes('[1m]')) {
380+
queryOptions.betas = ['context-1m-2025-08-07'];
381+
}
371382

372383
return queryOptions;
373384
}

src/engines/claude/persistent-executor.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,21 @@ export class PersistentClaudeExecutor extends EventEmitter {
365365
append: '\n\n' + appendSections.join('\n\n'),
366366
};
367367
}
368-
// Beta flags (parity with legacy executor)
369-
queryOptions.betas = ['context-1m-2025-08-07'];
368+
// 1M context window is opt-in via the `[1m]` model-name suffix
369+
// (`claude-opus-4-7[1m]`). The suffix is the canonical signal — the SDK
370+
// parses it directly on both OAuth and API-key auth paths.
371+
//
372+
// We *also* set the matching `betas` flag when the suffix is present,
373+
// belt-and-braces: harmless when the SDK already inferred it, and a
374+
// safety net if a future SDK rev only honors the explicit beta header
375+
// for some auth modes. Without the suffix, leave `betas` unset —
376+
// setting it unconditionally on API-key auth had the side-effect of
377+
// forcing every model (e.g. plain `opus-4-7`) into 1M context at 2×
378+
// the price, which the user never asked for. (Parity with legacy
379+
// executor; both spots must stay in sync.)
380+
if (this.options.model?.includes('[1m]')) {
381+
queryOptions.betas = ['context-1m-2025-08-07'];
382+
}
370383

371384
// Hooks: AskUserQuestion (mirrored from legacy executor — required so
372385
// that questions can be answered by users via Feishu cards) + Agent

0 commit comments

Comments
 (0)