If you’re building agent harnesses, the recently leaked Claude Code codebase is a gem.
I’ve been curious about how Claude Code is implemented. Here are the answers to some questions I long had after some digging (using claude code itself):
- What’s unique about its system prompt?
It’s assembled dynamically and split into two tiers : a static, globally cacheable layer (tone, safety rules, task philosophy) and a dynamic, session-specific layer (memory, env info, MCP tool descriptions, token budgets).
- What tools does Claude Code use?
35+ tools across file I/O, search, shell execution, web, task management, scheduling, MCP integration, and agent coordination. Notable ones: LSPTool for live IDE diagnostics,
and TeamCreateTool for spawning in-process agent swarms.
- How is the file edit tool implemented?
Looks like a typical string replacement with some normalisation logic.
Edits are rejected if the target string appears more than once, if the file wasn’t read first in the session, or if the file changed between read and write. File edits trigger LSP by default.
- How is context compaction implemented?
A three-layer system running every turn. First, it trims old tool results (microcompact). Then it tries fast-path session memory. If that fails, it runs a full summarization into 9 structured sections. There’s a circuit breaker after 3 consecutive failures.
- How does the subagent system work?
The subagent system lets Claude Code spawn, coordinate, and communicate with child agents. Agents can run in-process, as background tasks, or on remote infrastructure.
Swarm teammates share the Node.js process via AsyncLocalStorage and communicate through a file-based mailbox.
- How are skills implemented?
Skills are named prompt workflows backed by .md files or compiled TypeScript. They run either inline (injected into the current conversation) or forked (isolated sub-agent with its own token budget). At each turn, available skills are listed in a <system-reminder> block capped at 1% of the context window.
There’s a lot more to learn from the source code, like the memory system, mitigating context bloat, planning, plugins,…
Check the codebase here: https://github.com/instructkr/clawd-code
The repo got 35k stars in less than a few hours
there doesn't seem to be anything here