Install
$ agentstack add mcp-luxshan2000-inside-claude-code โ scanned ยท โ verified, works with Claude Code, Cursor, and more.
Security review
โ PassedNo issues found. Passed automated security review. ยท v0.1.0 How review works โ
- โ Prompt-injection patterns
- โ Secret / credential exfiltration
- โ Dangerous shell & filesystem operations
- โ Untrusted network calls
- โ Known-malicious package signatures
What it can access
- โ Network access Used
- โ Filesystem access No
- โ Shell / process execution No
- โ Environment & secrets No
- โ Dynamic code execution No
From automated source analysis of v0.1.0. โUsedโ means the capability is present in the source โ more access means more to trust, not that itโs unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work โAbout
๐ Inside Claude Code
Architecture Deep Dive • Flow Diagrams • How Every Feature Works Under the Hood
Ever wondered how Claude Code actually works? How it shrinks memory, executes tools, manages permissions, or streams responses? This repo breaks it all down โ one diagram at a time.
๐ง What Is This?
Claude Code (and its open-source sibling Claw Code) is an agentic AI coding assistant that lives in your terminal. It can read files, write code, run commands, search the web, and orchestrate complex multi-step tasks โ all while managing context, permissions, and tool execution autonomously.
This repository is a visual architecture guide. No code. Just diagrams, explanations, and deep dives into every subsystem that makes the magic happen.
Whether you're:
- ๐๏ธ Building your own AI agent and want to learn from Claude Code's architecture
- ๐ Curious about how agentic loops work under the hood
- ๐ Studying software architecture patterns in production AI systems
- ๐ ๏ธ Contributing to Claw Code / Claude Code and need to understand the internals
...this repo is for you.
๐๏ธ Architecture Map
> The 30,000-foot view. How all the pieces fit together.
graph TB
subgraph "๐ฅ๏ธ User Interface"
CLI["CLI / REPL"]
SLASH["Slash Commands/compact /model /help"]
end
subgraph "๐ง Core Runtime"
LOOP["Agentic Conversation Loop"]
PROMPT["System Prompt Builder"]
COMPACT["Memory Compaction"]
SESSION["Session Manager"]
end
subgraph "๐ง Tool Ecosystem"
TOOLS["Built-in Toolsbash, read, write, edit, glob, grep"]
MCP["MCP Serversstdio, SSE, WebSocket"]
HOOKS["Hook SystemPreToolUse / PostToolUse"]
end
subgraph "๐ Security Layer"
PERMS["Permission ModelReadOnly โ WorkspaceWrite โ DangerFull"]
SANDBOX["Sandbox Execution"]
AUTH["Auth: OAuth PKCE + API Keys"]
end
subgraph "๐ External"
API["Anthropic APIStreaming SSE"]
CONFIG["Config HierarchyUser โ Project โ Local"]
GIT["Git Integration"]
end
CLI --> LOOP
SLASH --> LOOP
LOOP --> PROMPT
LOOP --> COMPACT
LOOP --> SESSION
LOOP --> TOOLS
LOOP --> MCP
TOOLS --> HOOKS
TOOLS --> PERMS
TOOLS --> SANDBOX
LOOP --> API
PROMPT --> CONFIG
PROMPT --> GIT
API --> AUTH
[๐ Full Architecture Overview โ](docs/00-architecture-overview/README.md)
๐ฌ Deep Dives
Each doc below zooms into one specific feature with flow diagrams, sequence diagrams, and detailed explanations.
| # | Feature | What You'll Learn | Status | |---|---------|-------------------|--------| | 00 | [Architecture Overview](docs/00-architecture-overview/README.md) | High-level system design, crate structure, data flow | โ | | 01 | [The Agentic Conversation Loop](docs/01-conversation-loop/README.md) | How the core loop streams, calls tools, and iterates | โ | | 02 | [Memory Shrinking & Context Compaction](docs/02-memory-and-context/README.md) | How Claude Code fits infinite conversations into finite context | โ | | 03 | [Tool System](docs/03-tool-system/README.md) | Tool registration, execution, input schemas, built-in tools | โ | | 04 | [Permission Model](docs/04-permission-model/README.md) | Three-tier authorization, interactive prompting, escalation | โ | | 05 | [MCP Integration](docs/05-mcp-integration/README.md) | Model Context Protocol โ extending tools via external servers | โ | | 06 | [Hook System](docs/06-hook-system/README.md) | Pre/Post tool hooks, exit codes, environment variables | โ | | 07 | [Session Management](docs/07-session-management/README.md) | Persistence, resume, message serialization | โ | | 08 | [Streaming & SSE Parsing](docs/08-streaming-and-sse/README.md) | Server-Sent Events, incremental parsing, real-time output | โ | | 09 | [Configuration System](docs/09-config-system/README.md) | Multi-level config, deep merge, feature extraction | โ | | 10 | [Authentication](docs/10-authentication/README.md) | OAuth PKCE flow, API keys, token refresh | โ | | 11 | [CLI & REPL](docs/11-cli-and-repl/README.md) | Terminal rendering, markdown output, input handling | โ | | 12 | [Sandbox Execution](docs/12-sandbox-execution/README.md) | Linux namespace isolation, container detection | โ | | 13 | [System Prompt Building](docs/13-system-prompt-building/README.md) | Dynamic prompt construction, CLAUDE.md discovery | โ | | 14 | [Slash Commands](docs/14-slash-commands/README.md) | Command registry, parsing, execution | โ | | 15 | [Error Handling & Retry](docs/15-error-handling-and-retry/README.md) | Error types, exponential backoff, retryability | โ | | 16 | [Bootstrap Lifecycle](docs/16-bootstrap-lifecycle/README.md) | Startup phases, initialization sequence | โ |
๐งฉ Key Concepts at a Glance
The Conversation Loop โ The beating heart
graph LR
A["๐ค User Message"] --> B["๐ก Stream to API"]
B --> C{"๐ค Response Type?"}
C -->|"Text"| D["๐ฌ Display Text"]
C -->|"Tool Use"| E["๐ง Execute Tool"]
E --> F["๐ Check Permission"]
F --> G["โก Run Hook: PreToolUse"]
G --> H["๐ Execute"]
H --> I["โก Run Hook: PostToolUse"]
I --> J["๐จ Send Result to API"]
J --> C
C -->|"End Turn"| K["โ
Done"]
Memory Compaction โ How infinite conversations fit in finite context
graph TD
A["Token Count Check"] --> B{"Exceeds Budget?default: 200K tokens"}
B -->|"No"| C["Continue Normally"]
B -->|"Yes"| D["Identify Old Messages"]
D --> E["Generate Summaryof Removed Turns"]
E --> F["Inject Summary asSystem Context"]
F --> G["Preserve Recent NMessages Intact"]
G --> H["Resume withCompacted Context"]
Permission Tiers โ Security by design
graph LR
RO["๐ข ReadOnlyread files, glob, grep"]
WW["๐ก WorkspaceWrite+ write files, edit"]
DA["๐ด DangerFullAccess+ bash, network, web"]
RO --> WW --> DA
๐ System at a Glance
| Component | Details | |-----------|---------| | Modular Architecture | Separate modules for API, commands, runtime core, CLI, and tools | | Built-in Tools | 18 tools โ file ops, shell, search, web, orchestration | | MCP Transports | 6 types โ stdio, SSE, HTTP, WebSocket, SDK, proxy | | Permission Tiers | 3 levels โ ReadOnly, WorkspaceWrite, DangerFullAccess | | Config Sources | 5 locations โ user, project, local, CLI flags, env vars | | Slash Commands | 15+ โ /compact, /model, /permissions, /cost, /diff, and more | | Bootstrap Phases | 12 ordered startup phases | | Supported Models | Opus, Sonnet, Haiku model families |
๐๏ธ Repository Structure
inside-claude-code/
โโโ README.md โ You are here
โโโ LICENSE
โโโ assets/
โ โโโ banner.svg
โโโ docs/
โ โโโ 00-architecture-overview/ โ Start here
โ โโโ 01-conversation-loop/
โ โโโ 02-memory-and-context/
โ โโโ 03-tool-system/
โ โโโ 04-permission-model/
โ โโโ 05-mcp-integration/
โ โโโ 06-hook-system/
โ โโโ 07-session-management/
โ โโโ 08-streaming-and-sse/
โ โโโ 09-config-system/
โ โโโ 10-authentication/
โ โโโ 11-cli-and-repl/
โ โโโ 12-sandbox-execution/
โ โโโ 13-system-prompt-building/
โ โโโ 14-slash-commands/
โ โโโ 15-error-handling-and-retry/
โ โโโ 16-bootstrap-lifecycle/
๐ Why This Exists
The agentic AI coding assistant space is exploding. Claude Code, Cursor, Windsurf, Copilot โ they all share similar architectural patterns. Understanding how one works gives you superpowers to:
- Build your own agentic coding tools
- Debug issues when things go wrong
- Extend and customize existing tools
- Learn production architecture patterns for AI systems
This repo distills thousands of lines of Rust into clear, visual documentation anyone can understand.
๐ค Contributing
Found a mistake? Want to add a diagram? PRs welcome!
- Fork the repo
- Create a feature branch
- Add or improve docs in the
docs/folder - Use Mermaid for diagrams
- Submit a PR
๐ License
MIT โ Use these docs however you like.
โญ Star History
If this helped you understand how AI coding assistants work, drop a star!
[](https://star-history.com/#Luxshan2000/inside-claude-code&Date)
Built with ๐ curiosity and ๐ diagrams By @Luxshan2000
Source & license
This open-source MCP server is cataloged on AgentStack and links to its original source โ we do not rehost the code.
- Author: Luxshan2000
- Source: Luxshan2000/inside-claude-code
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.