A sourcemap, 390,000 lines, and everything Anthropic didn't want you to see
Json
What Claude Code actually is
User → messages[] → Claude API → response
If tool_use → execute → append result → loop back
This is the minimal agent loop. You send a prompt, the model responds, and if it wants to use a tool, you execute it, feed the result back, and loop. 50 lines of code will do it.
The other 389,950 lines make this loop reliable in production.
If tool_use → execute → append result → loop back
The patterns of a production AI agent
1. Prompt cache architecture
2. Context compaction
3. Permission cascading
The code also handles attacks. A malicious prompt can ask to access ../../etc/passwd to climb the directory tree and escape the project. Another can encode a file path in Unicode to bypass a protection rule. Each vector has its own countermeasure.
What is coming next
1. Memory consolidation ("Dream")
- Orient: scan the memory directory, read existing topic files
- Gather: identify new information worth persisting
- Consolidate: write or update memory files, convert relative dates to absolute, delete contradicted facts
- Prune: keep the memory index under 200 lines and 25KB