fix: make OpenAI fallback context window configurable + support external model lookup (#861)
* fix: make OpenAI fallback context window configurable and support external lookup table Unknown OpenAI-compatible models fell back to a hardcoded 128k constant, causing auto-compact to fire prematurely on models with larger windows (issue #635 follow-up). Two escape hatches are added without touching the built-in table: - CLAUDE_CODE_OPENAI_FALLBACK_CONTEXT_WINDOW (number): overrides the 128k default for all unknown models. - CLAUDE_CODE_OPENAI_CONTEXT_WINDOWS (JSON object): per-model overrides that take precedence over the built-in OPENAI_CONTEXT_WINDOWS table; supports the same provider-qualified and prefix-matching lookup as the built-in path. - CLAUDE_CODE_OPENAI_MAX_OUTPUT_TOKENS (JSON object): same pattern for output token limits. This lets operators deploy new or private models without patching openaiContextWindows.ts on every model release. * docs: add new OpenAI context window env vars to .env.example Document CLAUDE_CODE_OPENAI_FALLBACK_CONTEXT_WINDOW, CLAUDE_CODE_OPENAI_CONTEXT_WINDOWS, and CLAUDE_CODE_OPENAI_MAX_OUTPUT_TOKENS with usage examples. Addresses reviewer feedback on PR #861. --------- Co-authored-by: opencode <dev@example.com>
This commit is contained in:
@@ -12,7 +12,12 @@ export const MODEL_CONTEXT_WINDOW_DEFAULT = 200_000
|
||||
// Fallback context window for unknown 3P models. Must be large enough that
|
||||
// the effective context (this minus output token reservation) stays positive,
|
||||
// otherwise auto-compact fires on every message (issue #635).
|
||||
export const OPENAI_FALLBACK_CONTEXT_WINDOW = 128_000
|
||||
// Override via CLAUDE_CODE_OPENAI_FALLBACK_CONTEXT_WINDOW env var to avoid
|
||||
// hardcoding when deploying models not yet in openaiContextWindows.ts.
|
||||
export const OPENAI_FALLBACK_CONTEXT_WINDOW = (() => {
|
||||
const v = parseInt(process.env.CLAUDE_CODE_OPENAI_FALLBACK_CONTEXT_WINDOW ?? '', 10)
|
||||
return !isNaN(v) && v > 0 ? v : 128_000
|
||||
})()
|
||||
|
||||
// Maximum output tokens for compact operations
|
||||
export const COMPACT_MAX_OUTPUT_TOKENS = 20_000
|
||||
|
||||
Reference in New Issue
Block a user