{"id":47875549,"url":"https://github.com/alanisme/claude-code-decompiled","last_synced_at":"2026-04-07T04:00:56.185Z","repository":{"id":348318671,"uuid":"1197444001","full_name":"alanisme/claude-code-decompiled","owner":"alanisme","description":"🔍  Deep research reports based on Claude Code source analysis: architecture, agent loop, tool system, system prompts, telemetry, permissions, MCP integration, context management,   persistence, and hidden features.","archived":false,"fork":false,"pushed_at":"2026-04-01T01:58:12.000Z","size":415,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-04T01:21:28.510Z","etag":null,"topics":["ai-agents","anthropic","claude-code","code-analysis","mcp","reverse-engineering","security-research","source-analysis","source-code","system-prompts","telemetry"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@anthropic-ai/claude-code","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alanisme.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-31T15:29:40.000Z","updated_at":"2026-04-03T15:48:36.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alanisme/claude-code-decompiled","commit_stats":null,"previous_names":["alanisme/claude-code-decompiled"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alanisme/claude-code-decompiled","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanisme%2Fclaude-code-decompiled","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanisme%2Fclaude-code-decompiled/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanisme%2Fclaude-code-decompiled/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanisme%2Fclaude-code-decompiled/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alanisme","download_url":"https://codeload.github.com/alanisme/claude-code-decompiled/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alanisme%2Fclaude-code-decompiled/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31421869,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T00:25:07.052Z","status":"online","status_checked_at":"2026-04-05T02:00:05.211Z","response_time":75,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","anthropic","claude-code","code-analysis","mcp","reverse-engineering","security-research","source-analysis","source-code","system-prompts","telemetry"],"created_at":"2026-04-04T01:12:46.798Z","updated_at":"2026-04-05T02:00:29.670Z","avatar_url":"https://github.com/alanisme.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Claude Code Research Reports\n\n[![Version](https://img.shields.io/badge/Claude_Code-v2.1.88-blueviolet?style=for-the-badge)](https://www.npmjs.com/package/@anthropic-ai/claude-code)\n[![Reports](https://img.shields.io/badge/Research_Reports-20-red?style=for-the-badge)](docs/)\n\nIndependent research reports on **Claude Code v2.1.88**, focused on architecture, agent behavior, permission design, prompt assembly, MCP integration, and context management.\n\nThis repository is intentionally **documentation-only**. It collects original analysis and commentary about a publicly distributed software package. It is not presented as a runnable source release or supported CLI build.\n\n**Language**: **English** | [中文](README_CN.md) | [日本語](README_JA.md) | [한국어](README_KO.md) | [Español](README_ES.md)\n\n---\n\n## Why This Repo Exists\n\nClaude Code is one of the most sophisticated production AI coding agents available today. These reports aim to make its architecture and behavior easier to study:\n\n- **Agent developers** can study production patterns for tool orchestration, context management, and recovery logic.\n- **Security researchers** can inspect telemetry, remote control mechanisms, and permission boundaries.\n- **AI researchers** can examine prompt assembly, model routing, and agent loop design.\n- **Engineers** can use the reports as references when building CLI-based agent systems.\n\nThese reports are based on technical analysis of a **publicly distributed npm package** and are presented here as research commentary.\n\n---\n\n## What This Repository Covers\n\nThis repository is designed to answer a fairly specific set of questions about Claude Code:\n\n- How is Claude Code architected internally?\n- How does the main agent loop actually work?\n- How are tools registered, validated, permission-checked, and executed?\n- How is the system prompt assembled from static and dynamic parts?\n- What telemetry and privacy-relevant data paths exist?\n- How does the permission model work in practice?\n- How does Claude Code integrate with MCP servers and external tools?\n- How does it manage context pressure, compaction, and session persistence?\n- What hidden features, internal codenames, and remote control mechanisms exist in the codebase?\n\nIf someone lands here searching for Claude Code internals, Claude Code architecture, Claude Code source analysis, Claude Code system prompts, Claude Code telemetry, or Claude Code MCP integration, this repository is meant to be a useful entry point.\n\n---\n\n## Research Reports\n\n### Core Architecture Analysis\n\n| # | Report | What You'll Learn | Link |\n|---|--------|-------------------|------|\n| 13 | **Architecture Overview** | A system-level synthesis of how Claude Code fits together across prompt assembly, agent loop, tools, permissions, compaction, persistence, and MCP | [Read →](docs/en/13-claude-code-architecture-overview.md) |\n| 14 | **BashTool Security \u0026 Execution** | How Claude Code validates shell input, classifies read-only commands, routes sandboxed execution, and turns Bash into a controllable tool surface | [Read →](docs/en/14-bash-tool-security-and-execution.md) |\n| 15 | **Memory \u0026 Instruction System** | How CLAUDE.md, MEMORY.md, session memory, and instruction layering shape long-session behavior and prompt continuity | [Read →](docs/en/15-memory-and-instruction-system.md) |\n| 16 | **Transcripts, Compaction \u0026 Resume** | How transcript chains, sidechains, compact boundaries, resume, and session continuity work under the hood | [Read →](docs/en/16-transcripts-compaction-and-session-resume.md) |\n| 06 | **Agent Loop Deep Dive** | The 785KB `query.ts` dissected — message flow, streaming tool execution, auto-compaction, error recovery, sub-agent spawning | [Read →](docs/en/06-agent-loop-deep-dive.md) |\n| 07 | **Tool System Architecture** | How 40+ tools are registered, validated, permission-checked, and executed in parallel. The `buildTool` factory pattern. | [Read →](docs/en/07-tool-system-architecture.md) |\n| 08 | **Permission \u0026 Security Model** | Allowlists, blocklists, auto-approve rules, YOLO mode, sandbox integration, and the permission decision tree | [Read →](docs/en/08-permission-security-model.md) |\n| 09 | **System Prompt Engineering** | How the 15,000+ token system prompt is assembled from 20+ parts — context injection, tool descriptions, memory, and dynamic rules | [Read →](docs/en/09-system-prompt-engineering.md) |\n| 10 | **MCP Integration \u0026 Plugin System** | Model Context Protocol client implementation — server lifecycle, tool discovery, OAuth, and transport layers | [Read →](docs/en/10-mcp-integration.md) |\n| 11 | **Context Window Management** | Auto-compaction, conversation compression, token counting, and how Claude Code fights the context limit | [Read →](docs/en/11-context-window-management.md) |\n| 12 | **State Management \u0026 Persistence** | Session state, conversation history, memory system, file persistence, and cross-session data flow | [Read →](docs/en/12-state-management.md) |\n| 17 | **Bridge System \u0026 Remote Sessions** | How Claude Desktop talks to the CLI — session lifecycle, JWT auth, work secrets, multi-session coordination, capacity management | [Read →](docs/en/17-bridge-system-and-remote-sessions.md) |\n| 18 | **React/Ink Terminal UI** | Using React to render a TUI — Yoga layout, custom components, event system, streaming output, performance optimization | [Read →](docs/en/18-react-ink-terminal-ui.md) |\n| 19 | **Streaming \u0026 Transport Layers** | WebSocket/SSE/HTTP hybrid transport, batch uploading, backpressure, NDJSON protocol, reconnection logic | [Read →](docs/en/19-streaming-and-transport-layers.md) |\n| 20 | **Slash Commands \u0026 Cost Tracking** | 80+ command registry, fuzzy search, feature-gated commands, token-to-USD cost tracking, billing integration | [Read →](docs/en/20-slash-commands-and-cost-tracking.md) |\n\n### Discovery \u0026 Investigation Reports\n\n| # | Report | What You'll Learn | Link |\n|---|--------|-------------------|------|\n| 01 | **Telemetry \u0026 Data Collection** | Dual analytics pipeline, environment fingerprinting, what gets collected and how | [Read →](docs/en/01-telemetry-and-privacy.md) |\n| 02 | **Hidden Features \u0026 Codenames** | Animal codenames, feature flags, and internal vs external build differences | [Read →](docs/en/02-hidden-features-and-codenames.md) |\n| 03 | **Undercover Mode** | How Anthropic employees can hide AI authorship signals in public repos | [Read →](docs/en/03-undercover-mode.md) |\n| 04 | **Remote Control \u0026 Killswitches** | Server-side settings, blocking dialogs, GrowthBook flags, and emergency controls | [Read →](docs/en/04-remote-control-and-killswitches.md) |\n| 05 | **Future Roadmap** | KAIROS, Numbat, future model hints, unreleased tools, and roadmap clues | [Read →](docs/en/05-future-roadmap.md) |\n\n---\n\n## Reading Guide\n\n### Start here if you want the big picture\n\n- [Architecture Overview](docs/en/13-claude-code-architecture-overview.md)\n- [Agent Loop Deep Dive](docs/en/06-agent-loop-deep-dive.md)\n- [Tool System Architecture](docs/en/07-tool-system-architecture.md)\n- [Permission \u0026 Security Model](docs/en/08-permission-security-model.md)\n- [BashTool Security](docs/en/14-bash-tool-security-and-execution.md)\n\n### Read these if you care about prompts, memory, and context\n\n- [System Prompt Engineering](docs/en/09-system-prompt-engineering.md)\n- [Memory \u0026 Instruction System](docs/en/15-memory-and-instruction-system.md)\n- [Context Window Management](docs/en/11-context-window-management.md)\n- [State Management](docs/en/12-state-management.md)\n- [Transcripts, Compaction \u0026 Resume](docs/en/16-transcripts-compaction-and-session-resume.md)\n\n### Read these if you care about infrastructure and networking\n\n- [Bridge System \u0026 Remote Sessions](docs/en/17-bridge-system-and-remote-sessions.md)\n- [React/Ink Terminal UI](docs/en/18-react-ink-terminal-ui.md)\n- [Streaming \u0026 Transport Layers](docs/en/19-streaming-and-transport-layers.md)\n- [Slash Commands \u0026 Cost Tracking](docs/en/20-slash-commands-and-cost-tracking.md)\n- [MCP Integration](docs/en/10-mcp-integration.md)\n\n### Read these if you care about security, privacy, or control surfaces\n\n- [Telemetry \u0026 Privacy](docs/en/01-telemetry-and-privacy.md)\n- [Remote Control \u0026 Killswitches](docs/en/04-remote-control-and-killswitches.md)\n- [Permission \u0026 Security Model](docs/en/08-permission-security-model.md)\n\n### Read these if you care about unusual or hidden behavior\n\n- [Hidden Features \u0026 Codenames](docs/en/02-hidden-features-and-codenames.md)\n- [Undercover Mode](docs/en/03-undercover-mode.md)\n- [Future Roadmap](docs/en/05-future-roadmap.md)\n\nFor a topic-based report index, see [docs/en/README.md](docs/en/README.md).\n\n---\n\n## Analyzed Codebase Snapshot\n\nThese figures refer to the **analyzed Claude Code codebase snapshot**, not to the contents of this documentation repository.\n\n| Metric | Value |\n|--------|-------|\n| TypeScript Source Files | **1,884** |\n| Total Lines of Code | **512,664** |\n| Largest Single File | `query.ts` — **785KB** |\n| Built-in Tools | **40+** |\n| Slash Commands | **80+** |\n| npm Dependencies | **192 packages** |\n| Feature-Gated Modules | **108** |\n| Runtime Model | Bun-built package targeting Node.js |\n\n---\n\n## Architecture Overview\n\n```\n                          ┌─────────────────┐\n                          │   User Input     │\n                          │ (CLI / SDK / IDE)│\n                          └────────┬────────┘\n                                   │\n                    ┌──────────────▼──────────────┐\n                    │        Entry Layer           │\n                    │                              │\n                    │  cli.tsx → main.tsx → REPL   │\n                    │              └→ QueryEngine   │\n                    └──────────────┬──────────────┘\n                                   │\n              ┌────────────────────▼────────────────────┐\n              │           Query Engine Core              │\n              │                                         │\n              │  ┌─────────────────────────────────┐    │\n              │  │  System Prompt Assembly          │    │\n              │  │  (15K+ tokens, 20+ parts)       │    │\n              │  └─────────────┬───────────────────┘    │\n              │                │                         │\n              │  ┌─────────────▼───────────────────┐    │\n              │  │  Agent Loop (query.ts — 785KB)  │    │\n              │  │                                  │    │\n              │  │  User msg → Claude API → Response│    │\n              │  │       ↑                    │     │    │\n              │  │       │    tool_use? ──→ YES     │    │\n              │  │       │         │               │    │\n              │  │       │    Execute tools        │    │\n              │  │       │    (parallel)           │    │\n              │  │       │         │               │    │\n              │  │       └─── tool_result ◄────┘   │    │\n              │  └─────────────────────────────────┘    │\n              │                                         │\n              │  ┌─────────────────────────────────┐    │\n              │  │  Harness Layer                   │    │\n              │  │  • Permission checks             │    │\n              │  │  • Streaming \u0026 concurrency       │    │\n              │  │  • Auto-compaction               │    │\n              │  │  • Sub-agent management          │    │\n              │  │  • Cost tracking                 │    │\n              │  │  • Error recovery                │    │\n              │  │  • MCP orchestration             │    │\n              │  │  • Telemetry \u0026 logging           │    │\n              │  └─────────────────────────────────┘    │\n              └────────────────────┬────────────────────┘\n                                   │\n         ┌─────────────────────────▼─────────────────────────┐\n         │              Tool Layer (40+ tools)               │\n         │                                                     │\n         │  Read / Write / Edit / Bash / Glob / Grep / Agent  │\n         │  MCP tools / task tools / notebook tools / more    │\n         └─────────────────────────────────────────────────────┘\n```\n\n---\n\n## Observed Module Layout\n\nThe following tree describes the **analyzed source layout** discussed throughout the reports:\n\n```\nsrc/\n├── main.tsx\n├── QueryEngine.ts\n├── query.ts\n├── Tool.ts\n├── Task.ts\n├── tools.ts\n├── commands.ts\n├── context.ts\n├── cost-tracker.ts\n├── setup.ts\n├── bridge/\n├── cli/\n├── commands/\n├── components/\n├── entrypoints/\n├── hooks/\n├── services/\n├── state/\n├── tasks/\n├── tools/\n├── types/\n├── utils/\n└── vendor/\n```\n\nThis repository itself remains documentation-only:\n\n```\ndocs/\n├── en/\n└── zh/\n\nREADME.md\nREADME_CN.md\nREADME_JA.md\nREADME_KO.md\nREADME_ES.md\nQUICKSTART.md\n```\n\n---\n\n## Usage\n\n- Read reports directly from `docs/`\n- Share links to individual reports\n- Treat this repository as a documentation archive, not a software distribution\n\nSee [QUICKSTART.md](QUICKSTART.md) for a minimal reading guide.\n\n---\n\n## Keywords\n\nClaude Code, Anthropic, Claude Code source analysis, Claude Code architecture, Claude Code agent loop, Claude Code system prompts, Claude Code telemetry, Claude Code permission model, Claude Code MCP, Claude Code hidden features, Claude Code reverse engineering, AI coding agent architecture, Model Context Protocol, prompt engineering, context management, persistence, security research\n\n---\n\n## Legal Note\n\nThis project constitutes **research, commentary, and educational analysis** of a publicly distributed software package (the npm package `@anthropic-ai/claude-code`).\n\nThe original reports in `docs/` are the repository maintainer's own commentary and analysis. If you believe any content here infringes your rights, please open an issue for prompt review.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanisme%2Fclaude-code-decompiled","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falanisme%2Fclaude-code-decompiled","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falanisme%2Fclaude-code-decompiled/lists"}