Patching the 249 MB Claude Code Binary: Custom Subagent Models and an 89% Turn-1 Context Diet

· 4 min readPost views
Claude CodeReverse EngineeringBunTypeScriptAI InfraNPM

Over the last week I hit two walls inside Claude Code that configuration files could not fix. First, the Agent tool refused to spawn subagents on non-Anthropic gateway models like oc/exo-free, deepseek/deepseek-reasoner, or glm/glm-4.5, and even when I bypassed the schema check, non-Claude subagents thrashed autocompact on every single turn. Second, every new session on my machine started with 211,672 tokens already in the prompt before I typed a single word.

Starting with @anthropic-ai/claude-code 2.1.113, the npm package stopped shipping a plain cli.js file and switched to a 249 MB Bun-compiled native executable (claude.exe on Windows, Mach-O/ELF on macOS and Linux). Inside that PE binary sits a .bun section holding 2,394 embedded JavaScript modules alongside precompiled JSC bytecode pointers. If you edit the JavaScript strings in the binary without zeroing the corresponding bytecode offset and length fields in the Bun module table, the runtime ignores your JavaScript changes and executes the stale bytecode anyway.

To fix subagents first, I built cc-subagent-models. In Claude Code v2.1.280+, the Agent tool validates its model input against a fixed Zod v4 enum (sonnet, opus, haiku, fable) in chunk-hfa2ex8h.js, then checks an internal availableModels allowlist before falling back to the default model. Patching those checks let me pass gateway IDs like oc/exo-free, but immediately exposed a nastier bug: every non-Claude subagent compacted its context after Turn 1 and tripped the rapid-refill circuit breaker three turns later.

Tracing the context window resolver inside chunk-89f1nz22.js explained why. Claude Code calculates a model's context limit by checking for a [1m] tag or matching a hardcoded Claude 5 catalog, and falls back to 200,000 tokens for everything else. Because Math.min clamps that 200,000 fallback against your auto-compact threshold (around 167,000 effective tokens), and my fixed Turn-1 prefix was already over 150,000 tokens, every non-Claude subagent had less than 13,000 tokens of breathing room before autocompacting. In cc-subagent-models v1.1.0, I hooked the context window resolver so any gateway model defaults to 1,000,000 tokens and accepts per-call suffixes like oc/exo-free[1m] or deepseek/deepseek-reasoner[500k], which Claude Code uses for its local compaction math and strips right before sending req.body.model over the wire.

That still left the bigger question: why was Turn 1 costing 211,672 tokens in the first place? Writing an auditor over my ~/.claude directory and inspecting the request builder in chunk-hgy5nkw2.js uncovered four separate bottlenecks compounding on top of each other.

Bottleneck one: in chunk-6mab4ynv.js, the ToolSearch gate checks whether ANTHROPIC_BASE_URL points to api.anthropic.com. Because I route through a local 9Router gateway (http://localhost:20128), Claude Code silently disabled ToolSearch and dumped the full JSON schemas of all 388 MCP tools across 14 servers (160,400 tokens across DaVinci Resolve, Figma, Atlassian, Slack, Playwright, Chrome DevTools, and MongoDB) into every request.

Bottleneck two: even if you force ENABLE_TOOL_SEARCH=true in your environment, Claude Code attaches defer_loading: true and a DeferredToolPlaceholder entry to the wire tools array, and emits proprietary { type: "tool_reference" } blocks inside tool_result messages. Non-Anthropic models and OpenAI/Gemini translators reject those fields with HTTP 400 errors.

Bottleneck three: while MCP tools have ToolSearch, skills have no SkillSearch equivalent (tracked in anthropics/claude-code issues #43816 and #14882). Having 454 skills installed across user skills, pstack, oh-my-claudecode, and superpowers meant 30,822 tokens of multi-line descriptions were injected into the skill_listing attachment at startup. Worse, bottleneck four (issue #60141) meant every spawned subagent re-materialized that entire skill catalog from scratch.

Existing community tools either act as static disk scanners that tell you to uninstall your plugins, or require moving SKILL.md files out of ~/.claude/plugins into an external MCP vault, which breaks native /skill slash-command autocomplete and plugin updates.

So I built cc-context-diet (cc-diet), a second binary and JS bundle patcher that coexists cleanly alongside cc-subagent-models on the same claude.exe binary. It injects eight surgical hooks across four embedded Bun chunks. First, it unlocks ToolSearch across all custom gateways and model families, strips defer_loading and DeferredToolPlaceholder from the outgoing tools array in chunk-kfmrn92f.js, and converts wire tool_reference blocks into plain text while keeping tool_reference in memory so discovered MCP schemas still hydrate on the next turn. Second, it hooks the skill catalog formatter in chunk-hgy5nkw2.js so pinned and high-frequency skills keep their full descriptions while the other 436 skills collapse into a 19-line namespace index, and hooks validateInput in the native Skill tool (chunk-2xyd01k5.js) to handle Skill({ skill: "search:<keyword>" }) and Skill({ skill: "list:<namespace>" }) in-process with zero permission prompts. Third, it skips the skill_listing attachment inside subagents and groups deferred_tools_delta announcements by server prefix.

Running claude.exe -p against oc/exo-free on my live install confirmed both patches working together: Turn-1 prompt overhead dropped from 211,672 tokens to 22,433 tokens (-89%), per-subagent spawn overhead dropped from 191,222 tokens to 1,530 tokens, SkillSearch returned matching skills in one turn, and not a single plugin or MCP server had to be deleted. Both packages are open source and live on npm as cc-subagent-models and cc-context-diet (GitHub).

Patching the 249 MB Claude Code Binary: Custom Subagent Models and an 89% Turn-1 Context Diet — image 1
Patching the 249 MB Claude Code Binary: Custom Subagent Models and an 89% Turn-1 Context Diet — image 2