Sandbox
@cablate/claude-code-research

Claude Code internals research and reverse-engineering reports

This repo documents how Claude Code and the Claude Agent SDK behave, based on source-code analysis and bundle reverse-engineering. The material is organized into a large architecture study plus smaller reports on cache invalidation, system prompts, memory, security, and tool serialization.

167 stars71 forksHTMLUpdated 5mo ago
Who it's for

Builders who want to study Claude Code internals, prompt caching, and agent behavior before building around them.

What it delivers

You can reason about Claude Code’s hidden behavior instead of treating it like a black box.

What it does

Source code analysis archive

A 10-domain, 75-report breakdown of Claude Code architecture, including system prompts, tool definitions, agent architecture, memory, security, and model selection.

Behavioral reports

Focused investigations into prompt cache architecture, cache invalidation, system-reminder injection, context lifecycle, and auto mode cost.

Reverse-engineering guide

A guide for locating functions and search patterns in the minified `cli.js` bundle.

Interactive HTML viewer

`source-code-analysis/index.html` lets you browse the embedded reports without running a server.

How to get it

  1. 1sanbuphy/claude-code-source-code — source code archive
    CabLate, "Claude Code Research," GitHub, 2026.
    https://github.com/cablate/claude-code-research

README

Claude Code Research

Contributions Welcome

Independent research on Claude Code internals.

What's in this repo

DirectoryWhatSourceCount
source-code-analysis/Full architecture reverse-engineeringLeaked TypeScript source (v2.1.88)75 reports
reports/Problem-oriented investigations (cache, cost, injection)Minified npm bundle (cli.js)8 reports

Looking for the source code analysis? Go to source-code-analysis/. Looking for specific bug/cost investigations? Go to reports/.


Source Code Analysis (source-code-analysis/)

On 2026-03-31, the full source code of Claude Code was exposed via a sourcemap file in the npm registry (discovered by Chaofan Shou, archived by Kuberwastaken and sanbuphy).

We performed a 10-domain, 75-report analysis — the most thorough publicly available breakdown of how a production AI coding agent works.

Browse all reports →

Interactive viewer — open source-code-analysis/index.html in your browser (all 75 reports are embedded, no server needed).

Key Findings

DomainReportsHighlights
Harness Engineering7Agent Loop reverse-engineering, 12 transferable harness design principles
System Prompt6Complete 13-section prompt with dynamic assembly logic, 17 prompt engineering patterns
Cost & Quota8Cost envelope, prompt cache break detection (12 causes), Haiku→Opus 37.5x cost gap
Tool Definitions8All 36 tool prompts, read/write concurrency separation, ant vs public prompt variants
Agent Architecture76 built-in agents, Coordinator mode, Swarm multi-agent, 50-message cap (from 36.8GB incident)
Security87-layer defense-in-depth, 23 Bash validators, Parser Differential threat model
Skills System516 bundled skills, 12 design patterns + 5 anti-patterns
Memory & Context96 memory subsystems, AutoDream consolidation, Team Memory dual-layer security
API & Models717 beta headers, 4 providers, model selection 5-layer priority
Hidden Features1082 feature flags, KAIROS proactive mode, Buddy AI pet, UltraPlan, anti-distillation

Behavioral Reports (reports/)

Problem-oriented investigations based on reverse engineering the minified cli.js from npm. Each includes English and Chinese versions.

#TopicTL;DR
1Agent SDK Cache InvalidationSDK query() costs 3–10x more than CLI — process-per-call kills prompt cache
2System-Reminder Injection15+ hidden injection types, 4 root-cause bugs
3Prompt Cache ArchitectureStatic/dynamic zone split, sliding window, byte-prefix matching
4Tool Serialization & Cache StabilityZero .sort() on tools, deferred loading busts cache mid-conversation
5Context Lifecycle Management5 threshold constants, 10-step compaction flow, chain reactions
6Production Cache Optimization3 concrete cli.js patches + monitoring strategies
7Cache Invalidation Verificationdefer_loading excludes deferred tools from cache prefix entirely
8Auto Mode Classifier CostHidden Opus-level call before every side-effecting tool use

Resources

Source Code Archives

The analysis is based on the full TypeScript source of Claude Code v2.1.88. The source code itself is not included in this repo.

Version Baseline

ScopeVersion
Source Code Analysisv2.1.88 (sourcemap leak, 2026-03-31)
Behavioral Reports #1–2v2.1.71
Behavioral Reports #3–6Agent SDK v0.2.76 (build 2026-03-14)
Behavioral Reports #7–8v2.1.85 / v2.1.88

How to Cite

CabLate, "Claude Code Research," GitHub, 2026.
https://github.com/cablate/claude-code-research

Disclaimer

This is independent research, not affiliated with or endorsed by Anthropic. Behavioral reports analyze publicly distributed npm packages. Source code analysis is based on code exposed through npm registry sourcemaps.

Files in the repo

Repository payload6 top-level entries
  • reports
  • research
  • source-code-analysis
  • CODE_OF_CONDUCT.md
  • CONTRIBUTING.md
  • README.md

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More other

HKUDS/
Vibe-Trading

"Vibe-Trading: Your Personal Trading Agent"

33k
tinyhumansai/
openhuman

OpenHuman is an open source personal AI for Mac, Windows and Linux — local-first memory, agent orchestration, and deep research.

40k

AIPOCH Open-Science is an open-source, local-first, model-agnostic AI research workbench for macOS, Windows, and Linux, with scientific agents, Python/R notebooks, data connectors, and reproducible provenance.

4k
eigent-ai/
eigent

Eigent: The Open Source Cowork Desktop - Local and Free Alternative to Claude Cowork and Codex

15k
op7418/
CodePilot

A multi-model AI agent desktop client — connect any AI provider, extend with MCP & skills, control from your phone. Built with Electron + Next.js.

6.5k