AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
MCP verified MIT Self-run

Inside Claude Code

mcp-luxshan2000-inside-claude-code ยท by Luxshan2000

๐Ÿ” Inside Claude Code โ€” Architecture Deep Dive | Flow Diagrams, UML, Sequence Diagrams | How Memory Shrinking, Tool Execution, Permissions & MCP Work Under the Hood

โ€” No reviews yet
0 installs
31 views
0.0% viewโ†’install

Install

$ agentstack add mcp-luxshan2000-inside-claude-code

โœ“ scanned ยท โœ“ verified, works with Claude Code, Cursor, and more.

Security review

โœ“ Passed

No 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.

View the full security report โ†’

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/mcp-luxshan2000-inside-claude-code)

Reliability & compatibility

โœ“ Security review passed
0 installs to date
โ€” no reviews yet
โ—‹ 5mo ago

Declared compatibility

Claude CodeClaude DesktopCursorWindsurf

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

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 โ†’
Are you the author of Inside Claude Code? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

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:

  1. Build your own agentic coding tools
  2. Debug issues when things go wrong
  3. Extend and customize existing tools
  4. 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!

  1. Fork the repo
  2. Create a feature branch
  3. Add or improve docs in the docs/ folder
  4. Use Mermaid for diagrams
  5. 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.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.