On March 31, 2026, Anthropic accidentally exposed 512,000+ lines of Claude Code's TypeScript source via an npm source map. Within hours, thousands of developers had reverse-engineered the entire architecture. This is what they found — and how you should build based on it.
A packaging bug led to the largest accidental source code exposure in the AI coding tool space.
oven-sh/bun#28001 reported: Bun serves source maps in production mode despite docs stating otherwise. The ticking time bomb.@anthropic-ai/claude-code was published with a 59.8 MB source map file (.map) accidentally bundled. The .map file contained full paths back to the original TypeScript source.The leak spawned an ecosystem of mirrors, reimplementations, and analysis repos.
Not your typical Node.js CLI. Claude Code uses game-engine-level optimizations for terminal rendering.
cch=00000 header).The entire Claude Code architecture decomposes into five major subsystems, each responsible for a critical dimension of the agent experience.
ToolSearchTool for elastic discovery, keeping base prompts under 200K tokens. Each tool definition includes a JSON schema, permission requirements, and execution handler.autoDream process runs memory merging while idle.How Claude Code keeps conversations going without losing critical information.
At its heart, Claude Code runs a deceptively simple loop. The complexity is in the subsystems, not the orchestration.
At its core, Claude Code proves that a powerful AI coding agent can be built from a surprisingly simple foundation: an LLM with bash access and a well-designed tool system. The 512K lines exist not because the core idea is complex, but because production-grade execution demands engineering depth. Simple core idea, complex execution.
The old playbook is obsolete. Here's what replaced it.
512K lines taught us the future of software isn't the model — it's the harness.
Forget the 512K lines. Here's what YOUR project looks like when you git init today.
This is not Claude Code's loop. This is your loop — the simplest version that actually works with the Anthropic SDK. Ship this, then iterate.
Claude Code ships 40+ tools. You ship 5. These cover 90% of what an AI agent needs on day one.
readOnly: true or false. Read-only tools are auto-approved. Write tools ask the user. That's your entire permission system on day one. Grow it later — see the Security deep-dive (Tab 5) for what "later" looks like.
Don't over-engineer. Add each layer when you actually feel the pain.
tools/, skills/, permissions/, memory/. Not before.ls skills/. Each skill is 3 files in a folder. This tab shows you how to build and ship your first skill in under an hour, then wire it into an interface that builds user trust through progressive disclosure.
A skill is just 3 files in a folder. Here's a complete, working example you can copy right now. When a user types /review, this skill activates.
{{variables}} are filled by your handler.mkdir skills/deploy.skill and create the same 3 files. The core loop doesn't change. Your product grows by adding folders, not by rewriting code. That's the entire point of this architecture.
In this order. Each one teaches you something about the architecture.
git commit. Teaches you: write permissions, user approval flow, multi-step tool chains./review → /fix (if issues) → tests → deploys. Teaches you: skill composition — the moment your architecture pays off.Start with a CLI. Build trust through progressive disclosure. Add web and API later.
readline loop or React+Ink terminal UI. Users type, AI responds. Fastest way to iterate on your core loop without building UI.autoApprove: true for all tool permissions within a sandbox.A three-tier cascade with fail-closed defaults. Sources: [sathwick.xyz] [Straiker]
validateInput()checkPermissions()PermissionResult{ behavior: 'allow', updatedInput? } | { behavior: 'ask', message } | { behavior: 'deny', message }buildTool() factory defaults to "ask" if a tool doesn't declare its permission level.
| Mode | Type | Behavior |
|---|---|---|
default | Public | Prompts user for permission on first use of each tool |
plan | Public | Read-only — Claude can analyze but not modify files or execute commands |
acceptEdits | Public | Auto-approves file edit permissions for the session |
dontAsk | Public | Auto-denies tools unless pre-approved via /permissions or permissions.allow rules |
bypassPermissions | Public | Skips permission prompts (writes to .git, .claude, .vscode, .idea still prompt) |
auto | Internal | Uses a classifier model to decide safety per action. Reads autoMode config and uses prose-based environment descriptions for "trusted infrastructure" determination. Research preview. |
bubble | Internal | Delegates permission decision to parent agent in multi-agent orchestration scenarios |
Bash(git push *), Bash(npm run *), Bash(* --version)* enforces word boundaries — Bash(ls *) matches ls -la but NOT lsof.&&, so Bash(safe-cmd *) will NOT permit safe-cmd && rm -rf /.//path (filesystem root), ~/path (home), /path (project root), ./path (CWD).
PreToolUse hooks run before the permission prompt and can force-deny, force-allow, or force-ask.sandbox-exec) framework for process-level enforcement.bwrap) for filesystem/network isolation. WSL2 uses bubblewrap; WSL1 is unsupported.allowWrite/denyWrite/denyRead/allowRead paths.dangerouslyDisableSandbox (goes through normal permissions flow).BashSecurity.ts implements a comprehensive defense layer against shell injection and escape attacks.
=command expansion attacks unique to Zsh's extended globbing — a vector most security tooling misses.../ sequences and symlink attacks.Source code comments and error tracking revealed real production metrics.
SYSTEM_PROMPT_DYNAMIC_BOUNDARY marker to split the two.tengu_). No deactivate() method — intentional.shouldDefer: true, discovered on-demand via ToolSearchTool. Keeps base prompts under 200K tokens.DANGEROUS_uncachedSystemPromptSection() explicitly marks sections as cache-volatile. The DANGEROUS_ naming warns developers against carelessly adding volatile content.Don't skip ahead. Each step builds on the previous one.
readOnly flag. Claude Code started with core tools and grew to 40+.validateInput() → checkPermissions() → allow|ask|deny. Default to "ask." Fail closed.MAX_CONSECUTIVE_FAILURES = 3 circuit breaker from the start.Non-negotiable principles for every decision.
Array.sort(). Save LLM calls for reasoning.Every blog post, forum thread, news article, and repository referenced in this analysis.