Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
support [1m] model suffix for larger context windows
Raine Virta65939c5aa47f
diff --git a/README.md b/README.mdindex 73c69cf..b699648 100644--- a/README.md+++ b/README.md@@ -104,16 +104,16 @@ would 400 because no provider claims it, so set# CodexANTHROPIC_BASE_URL=http://localhost:18765 \ANTHROPIC_AUTH_TOKEN=unused \-ANTHROPIC_MODEL=gpt-5.4 \-ANTHROPIC_SMALL_FAST_MODEL=gpt-5.4-mini \+ANTHROPIC_MODEL=gpt-5.4[1m] \+ANTHROPIC_SMALL_FAST_MODEL=gpt-5.4-mini[1m] \CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \claude# KimiANTHROPIC_BASE_URL=http://localhost:18765 \ANTHROPIC_AUTH_TOKEN=unused \-ANTHROPIC_MODEL=kimi-for-coding \-ANTHROPIC_SMALL_FAST_MODEL=kimi-for-coding \+ANTHROPIC_MODEL=kimi-for-coding[1m] \+ANTHROPIC_SMALL_FAST_MODEL=kimi-for-coding[1m] \CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \claude```@@ -125,52 +125,28 @@ Or set it persistently in `~/.claude/settings.json`:"env": {"ANTHROPIC_BASE_URL": "http://127.0.0.1:18765","ANTHROPIC_AUTH_TOKEN": "unused",- "ANTHROPIC_MODEL": "gpt-5.4",- "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.4-mini",+ "ANTHROPIC_MODEL": "gpt-5.4[1m]",+ "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.4-mini[1m]","CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1}}```-### 5. Optional: disable Claude Code auto-compact+### 5. Context window size-Claude Code decides auto-compaction locally based on the model context window it-thinks it has. If the upstream model supports a larger window than Claude Code-assumes, it may compact earlier than necessary.+Claude Code decides auto-compaction based on the model's context window. For+unknown models (like the ones the proxy uses) it defaults to 200K tokens, which+is smaller than what the upstream models actually support (GPT-5.4: 400K+,+Kimi: 256K). This causes auto-compact to fire earlier than necessary.-Disable only automatic compaction while keeping manual `/compact` available:+The `[1m]` suffix on the model name (shown in the examples above) is a Claude+Code convention that tells it to use a 1M-token context window instead. This+raises the auto-compact threshold without disabling it entirely.-```sh-DISABLE_AUTO_COMPACT=1 \-ANTHROPIC_BASE_URL=http://localhost:18765 \-ANTHROPIC_AUTH_TOKEN=unused \-ANTHROPIC_MODEL=gpt-5.4 \-ANTHROPIC_SMALL_FAST_MODEL=gpt-5.4-mini \-CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 \- claude-```--Or add it to `~/.claude/settings.json`:--```json-{- "env": {- "ANTHROPIC_BASE_URL": "http://127.0.0.1:18765",- "ANTHROPIC_AUTH_TOKEN": "unused",- "ANTHROPIC_MODEL": "gpt-5.4",- "ANTHROPIC_SMALL_FAST_MODEL": "gpt-5.4-mini",- "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": 1,- "DISABLE_AUTO_COMPACT": 1- }-}-```--Tradeoffs:--- Claude Code will stop proactively compacting before a turn.-- Manual `/compact` still works.-- If you let the session grow too far, you may hit prompt-too-long failures- instead of a graceful auto-compact.+If you'd rather disable auto-compact completely, set+`DISABLE_AUTO_COMPACT=1` in your env or `~/.claude/settings.json`. Manual+`/compact` still works, but you risk hitting real upstream limits before+Claude Code can compact for you.## Toggling between proxy and direct Anthropic@@ -190,10 +166,9 @@ the default.if [ -f "$HOME/.claude/claude-code-proxy-enabled" ]; thenexport ANTHROPIC_BASE_URL="http://localhost:18765"export ANTHROPIC_AUTH_TOKEN="unused"- export ANTHROPIC_MODEL="gpt-5.4"- export ANTHROPIC_SMALL_FAST_MODEL="gpt-5.4-mini"+ export ANTHROPIC_MODEL="gpt-5.4[1m]"+ export ANTHROPIC_SMALL_FAST_MODEL="gpt-5.4-mini[1m]"export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"- export DISABLE_AUTO_COMPACT=1fiexec "$HOME/.local/bin/claude" "$@"diff --git a/src/cli.ts b/src/cli.tsindex f873bf1..3705186 100755--- a/src/cli.ts+++ b/src/cli.ts@@ -38,8 +38,8 @@ async function main() {console.log("Configure Claude Code (pick a model from above):")console.log(` export ANTHROPIC_BASE_URL="http://localhost:${port}"`)console.log(` export ANTHROPIC_AUTH_TOKEN="anything"`)- console.log(` export ANTHROPIC_MODEL="kimi-for-coding" # or gpt-5.4, etc.`)- console.log(` export ANTHROPIC_SMALL_FAST_MODEL="kimi-for-coding" # background / title-gen`)+ console.log(` export ANTHROPIC_MODEL="kimi-for-coding[1m]" # or gpt-5.4[1m], etc.`)+ console.log(` export ANTHROPIC_SMALL_FAST_MODEL="kimi-for-coding[1m]" # background / title-gen`)console.log(` export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC="1"`)return}diff --git a/src/server.ts b/src/server.tsindex 54b56c6..32c5c1b 100644--- a/src/server.ts+++ b/src/server.ts@@ -100,6 +100,15 @@ function buildCtx(req: Request, reqId: string, providerName: string): RequestCon}}+// Claude Code uses a [1m] suffix convention (e.g. "gpt-5.4[1m]") to+// signal that the model should be treated as having a 1M-token context+// window. Claude Code normalizes this away before sending requests to+// the API, but we strip it here too as defense-in-depth in case a+// future version or a different client includes it.+function normalizeIncomingModel(model: string): string {+ return model.replace(/\[1m\]$/i, "")+}+function routeProvider(body: AnthropicRequest, reqId: string): Provider | Response {if (!body.model) {return jsonError(@@ -108,6 +117,7 @@ function routeProvider(body: AnthropicRequest, reqId: string): Provider | Respon`Missing "model" in request body. ${knownModelsMessage()}`,)}+ body.model = normalizeIncomingModel(body.model)const provider = providerForModel(body.model)if (!provider) {rootLog.warn("unknown model", { reqId, model: body.model })