by noya21th
Claude Code v2.1.88 source analysis: system prompts, 87 hidden feature flags, cost optimization, architecture diagrams, undercover mode, and comparison with Cursor/Cline. No source code redistributed.
# Add to your Claude Code skills
git clone https://github.com/noya21th/claude-source-leakedThe first architecture deep-dive, hidden feature catalog, and cost optimization guide for Claude Code — based on v2.1.88 source analysis (1,884 files, 132K lines of TypeScript).
中文版 | English
On March 31, 2026, Claude Code's TypeScript source (1,884 files, ~132K lines) was exposed through an unstripped
.mapfile in the npm package. This repository includes the complete restored source code insrc/plus original analysis. This project extracts actionable insights — architecture patterns, hidden features, cost optimization, and best practices — all with source file references.
No comments yet. Be the first to share your thoughts!
Full document | Source:
src/constants/prompts.ts,src/utils/systemPrompt.ts
Priority 0: Override (loop mode, testing) ← highest
Priority 1: Coordinator (multi-worker orchestration)
Priority 2: Agent (subagent definitions)
Priority 3: Custom (--system-prompt flag)
Priority 4: Default (standard Claude Code) ← lowest
+ appendSystemPrompt (always appended unless override)
The system prompt is 9 major sections:
file_path:line_number format__SYSTEM_PROMPT_DYNAMIC_BOUNDARY__ splits static/dynamic partsThe prompt is split by __SYSTEM_PROMPT_DYNAMIC_BOUNDARY__:
| Model | Display Name | Cutoff | |-------|-------------|--------| | claude-opus-4-6 | Claude Opus 4.6 | May 2025 | | claude-sonnet-4-6 | Claude Sonnet 4.6 | August 2025 | | claude-haiku-4-5 | Claude Haiku 4.5 | February 2025 |
Full document | Source:
src/commands.ts, various
These are compile-time switches via bun:bundle feature(). Most are dead-code-eliminated in the public npm build.
| Codename | What It Does | Cross-file References | |----------|-------------|----------------------| | KAIROS | Autonomous assistant platform (assistant mode, brief, channels, cron, webhooks) | 210 files | | PROACTIVE | Proactive task planning and automation | Linked to KAIROS | | COORDINATOR_MODE | Multi-agent orchestration with workers | 45 files | | VOICE_MODE | Voice input/output with cross-platform binaries | 38 files | | BUDDY | AI companion sprite with animation system | 14 files, 1,298 lines | | ULTRATHINK | Extended deep reasoning mode | Compile-time | | ULTRAPLAN | Super planner with selection dialog | Compile-time | | TORCH | Inference enhancement | Compile-time | | BRIDGE_MODE | Mobile/web remote control | Compile-time | | CHICAGO_MCP | Computer-use MCP server | Internal |
| Flag | Purpose | |------|---------| | CONTEXT_COLLAPSE | Smart context folding | | REACTIVE_COMPACT | Reactive session compression | | CACHED_MICROCOMPACT | Micro cache compression | | HISTORY_SNIP | History message fragmentation | | BG_SESSIONS | Background session management | | AWAY_SUMMARY | Auto-summary when user is away |
Runtime flags use tengu_ + random word pairs to deliberately hide their purpose:
tengu_frond_boric → Analytics killswitch (Datadog/FirstParty)
tengu_passport_quail → Memory extraction gate
tengu_moth_copse → Memory extraction enable
tengu_bramble_lintel → Memory extraction frequency
tengu_cicada_nap_ms → Background refresh throttle
tengu_slate_prism → Connector text summarization
tengu_amber_json_tools → JSON tool format (token-efficient)
tengu_tool_pear → Structured output (strict tools)
Source:
src/commands.ts
These require specific feature flags to appear:
| Command | Function | Required Flag |
|---------|----------|---------------|
| /assistant | Assistant mode | KAIROS |
| /brief | Brief messages | KAIROS_BRIEF |
| /bridge | Remote control bridge | BRIDGE_MODE |
| /voice | Voice mode | VOICE_MODE |
| /buddy | AI companion sprite | BUDDY |
| /ultraplan | Super planner | ULTRAPLAN |
| /torch | Inference boost | TORCH |
| /workflows | Workflow scripts | WORKFLOW_SCRIPTS |
| /fork | Subagent branching | FORK_SUBAGENT |
| /peers | Peer messaging | UDS_INBOX |
| /proactive | Proactive planning | PROACTIVE |
| /force-snip | Force history snip | HISTORY_SNIP |
| /subscribe-pr | PR subscriptions | KAIROS_GITHUB_WEBHOOKS |
| /remote-setup | Remote CCR setup | CCR_REMOTE_SETUP |
| /remote-control-server | Remote control server | DAEMON + BRIDGE_MODE |
Condition:
USER_TYPE === 'ant' && !IS_DEMO
| Command | Function |
|---------|----------|
| /bughunter | Automated bug detection |
| /good-claude | Model evaluation tool |
| /commit | Hidden git commit |
| /commit-push-pr | One-click commit → push → create PR |
| /ctx-viz | Context visualization |
| /break-cache | Force cache invalidation |
| /mock-limits | Simulate rate limits |
| /reset-limits | Reset rate limits |
| /ant-trace | Anthropic internal tracing |
| /perf-issue | Performance diagnostics |
| /debug-tool-call | Tool call debugger |
| /agents-platform | Agents platform management |
| /autofix-pr | Auto-fix PR |
| /backfill-sessions | Backfill session data |
| /share | Session sharing |
| /summary | Session summary |
| /onboarding | Onboarding flow |
| /init-verifiers | Initialize verifiers |
| /bridge-kick | Kick bridge connection |
| /version | Version display |
| /oauth-refresh | OAuth token refresh |
| /env | Environment variables |
| /issue | Issue tracking |
| /teleport | Session teleport |
| /tags | Session tags |
Full document | Source:
src/utils/undercover.ts
When Anthropic employees (USER_TYPE=ant) work in public repositories, Claude Code automatically hides all internal information.
isUndercover() check:
USER_TYPE !== 'ant' → always OFF (external users unaffected)
USER_TYPE === 'ant' →
CLAUDE_CODE_UNDERCOVER=1 → forced ON
Repo in internal allowlist → OFF
Repo is public/unknown → ON (safe default)
There is NO force-OFF option. If Claude Code can't confirm it's an internal repo, undercover stays ON.
## UNDERCOVER MODE — CRITICAL
You are operating UNDERCOVER in a PUBLIC/OPEN-SOURCE repository.
NEVER include in commit messages or PR descriptions:
- Internal model codenames (Capybara, Tengu, etc.)
- Unreleased model version numbers
- Internal repo or project names
- The phrase "Claude Code" or any mention that you are an AI
- Co-Authored-By lines or any other attribution
anthropics/claude-cli-internal, anthropics/anthropic, anthropics/apps,
anthropics/casino, anthropics/dbt, anthropics/dotfiles,
anthropics/terraform-config, anthropics/hex-export, anthropics/feedback-v2,
anthropics/labs, anthropics/argo-rollouts, anthropics/starling-configs,
anthropics/ts-tools, anthropics/ts-capsules, anthropics/feldspar-testing,
anthropics/trellis, anthropics/claude-for-hiring, anthropics/forge-web,
anthropics/infra-manifests, anthropics/mycro_manifests,
anthropics/mycro_configs, anthropics/mobile-apps
Source: src/utils/commitAttribution.ts lines 30-75
Full document | Sources:
src/utils/modelCost.ts,src/utils/context.ts,src/services/compact/
| Model | Input | Output | Cache Read | Cache Write | |-------|-------|--------|------------|------------| | Haiku 4.5 | $1 | $5 | $0.10 | $1.25 | | Sonnet 4.6 | $3 | $15 | $0.30 | $3.75 | | Opus 4.6 | $5 | $25 | $0.50 | $6.25 | | Opus 4.6 Fast | $30 | $150 | $3.00 | $37.50 |
Fast mode is 6x the price. Use it only for short, time-sensitive tasks.
Source: src/utils/modelCost.ts lines 36-69
| # | Tip | Source Evide