Skip to content
Flows
Tier 1 · Claude Code internals Claude Code internals · fetched 2026-07-02

claude-code-decompiled (research reports)

A documentation-only collection of 20 independent research reports on Claude Code v2.1.88 covering architecture, agent behavior, permission design, prompt assembly, MCP integration, and context management. Deliberately ships analysis rather than extracted code.

View source on GitHub

Key takeaways

  • 01

    Report set spans permissions, prompt assembly, MCP, and context management

  • 02

    Documentation-only approach is the cleanest for attribution

  • 03

    Strong specifics on permission tiers around dangerous tools

Flows built on this research

From the archive

Verbatim excerpts mined from our local archive of this repository — the prompts, schemas, and patterns worth stealing.

Agent pattern

The system prompt is an array, and the boundary is infrastructure

return [
  // --- Static content (cacheable) ---
  getSimpleIntroSection(outputStyleConfig),
  getSimpleSystemSection(),
  getActionsSection(),
  getUsingYourToolsSection(enabledTools),
  getSimpleToneAndStyleSection(),
  getOutputEfficiencySection(),
  // === BOUNDARY MARKER - DO NOT MOVE OR REMOVE ===
  ...(shouldUseGlobalCacheScope() ? [SYSTEM_PROMPT_DYNAMIC_BOUNDARY] : []),
  ...resolvedDynamicSections,
].filter(s => s !== null)

Before the boundary: cacheScope 'global' - shared across the entire Anthropic fleet, prefill cost amortized across millions of requests. After: per-session content.

getSystemPrompt() returns string[] not string - each segment becomes an API block with its own cache scope, and one literal marker decides what the whole fleet can share.

docs/en/09-system-prompt-engineering.md

Insight

Nine exit reasons, each one a production scar

The Terminal return value carries the reason the loop exited: 'completed', 'aborted_streaming', 'aborted_tools', 'max_turns', 'prompt_too_long', 'model_error', 'image_error', 'hook_stopped', or 'stop_hook_prevented'. Each of those exit paths was added because of a real bug in production.

The outer query() is a thin wrapper: command lifecycle notifications only fire on successful completion - not on throws or .return() calls that abort the generator.

From the 1,729-line query.ts: an agent loop's maturity is measured by how many distinct ways it knows how to stop.

docs/en/06-agent-loop-deep-dive.md

MCP & tools

MCP connections as a five-state discriminated union

export type MCPServerConnection =
  | ConnectedMCPServer
  | FailedMCPServer
  | NeedsAuthMCPServer
  | PendingMCPServer
  | DisabledMCPServer

Connection results are memoized (lodash memoize, keyed on server name + serialized config) - repeated calls return the cached connection. When a connection drops, the cache entry is explicitly deleted in the onclose handler so the next call triggers a fresh connection.

Production MCP clients don't model 'connected or not' - they model five states so the UI, retry logic, and auth flows each know exactly what to do.

docs/en/10-mcp-integration.md