89 Feature Flags, a YOLO Classifier, and the Cache Tricks Inside Claude Code's Leaked Source
These are production engineering patterns from a leading AI coding tool, not speculative best practices. The caching rules, classifier design, and token-budget discipline are directly applicable to anyone building on top of LLM APIs or shipping an AI agent.
A source-map leak made Claude Code's TypeScript source restorable, and the resulting analysis surfaces 89 build-time feature flags that map out a product roadmap spanning autonomous background agents, multi-agent orchestration, and distributed execution. The permission system relies on a YOLO classifier that uses a fast/slow AI pipeline to audit AI actions, defaulting to deny when uncertain and falling back to manual confirmation after repeated rejections.
Prompt caching is treated as core infrastructure, governed by five principles: keep static content first, update via appended messages rather than edits, never switch models mid-session, manage tool definitions carefully to avoid prefix invalidation, and move cache breakpoints to the latest message. One optimization—moving the agent list from the system prompt to a system-reminder—alone reduced global cache_creation by 10.2%.
Context management operates under hard token budgets. The system prompt consumes 15-20K tokens, auto-compaction triggers at 167K, and every tool result is capped at 50K characters. When content is truncated, the model is told where to find the full version on disk rather than being left to reason on incomplete data.
The 89 feature flags are not just toggles—they are a de facto public product roadmap, showing that Anthropic is actively building toward autonomous background agents, multi-agent systems, and a distributed execution platform.
Using AI to classify the safety of another AI's actions is a recursive trust problem. The two-stage design with a hard fallback to human judgment after repeated rejections is a pragmatic admission that the classifier itself is fallible.
The cache optimization that saved 10.2% globally came from moving a single piece of data between message roles—an almost trivial change with outsized cost impact, suggesting many LLM applications are leaving similar savings on the table.
Hard token budgets on every input—system prompts, tool results, context windows—contradict the 'just throw it all in the context' approach common in early LLM integrations. The cheapest token is the one never sent.
Telling the model that content was truncated and where to find it, rather than silently dropping it, treats the model as an agent capable of information retrieval rather than a passive inference engine. This is a subtle but important design choice for agent architectures.