# andytonglove/claude-code-leak architecture

> Architecture diagram of the GitHub repository andytonglove/claude-code-leak, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andytonglove/claude-code-leak
- Repository: https://github.com/andytonglove/claude-code-leak

## Overview

1. **Overall shape**
   - This is a Bun + TypeScript terminal application built around a React/Ink UI.
   - The architecture is not a simple command runner: it is an interactive agent workspace with a persistent app state, a tool-execution loop, many slash commands, and multiple integration surfaces.

2. **Startup and bootstrapping**
   - `src/main.tsx`, `src/entrypoints/`, and `src/bootstrap/` form the startup path.
   - Startup does early environment setup, settings loading, keychain/prefetch work, feature-flag decisions, and then routes into either the main REPL/session UI or specialized entrypoints like CLI, MCP, or sandbox-related modes.

3. **Core orchestration**
   - `src/QueryEngine.ts`, `src/Task.ts`, `src/Tool.ts`, and `src/tools.ts` are the central engine boundary.
   - The query engine manages the LLM conversation loop, streaming assistant responses, tool calls, retries, and turn completion.
   - Tools are typed modules with schemas, permissions, and result rendering; tasks represent running work units across local, remote, shell, and teammate contexts.

4. **Interactive terminal UI**
   - `src/components/`, `src/screens/`, `src/ink/`, `src/context/`, and `src/state/` provide the terminal application shell.
   - Ink is the rendering/runtime layer; React components implement prompt input, message timelines, dialogs, status lines, diff views, permission prompts, onboarding, and background task views.
   - Global app state is centralized and shared through state/context hooks rather than ad hoc component-local state.

5. **User input to agent loop**
   - User input flows through prompt handling, slash-command processing, and tool/request creation.
   - The main path is: terminal input → command/prompt parsing → context assembly → query engine call → streamed assistant output → tool invocation(s) → UI updates.
   - This is the primary architecture boundary between interactive front-end behavior and backend agent execution.

6. **Tool execution and safety**
   - `src/tools/` contains the operational surface area: shell, file edit/read/write, grep/glob, web fetch/search, MCP, LSP, notebook editing, agent spawning, task management, messaging, scheduling, and plan/worktree controls.
   - Tool execution is mediated by `src/services/tools/` and extensive validation in `src/utils/permissions/`, `src/hooks/toolPermission/`, and tool-specific validation helpers.
   - Permissioning is a first-class boundary: every potentially dangerous action can be rejected, auto-resolved, or routed through a UI approval dialog.

7. **Command system**
   - `src/commands/` is the user-facing slash-command layer.
   - Commands cover session lifecycle, config, login/logout, memory, tasks, review, diff, cost, theme, sandbox, plugins, MCP, resume, and many workflow-oriented operations.
   - Many commands are thin orchestration wrappers around shared services and UI flows rather than self-contained business logic.

8. **External integrations and service layer**
   - `src/services/` contains the integrations that leave the local process boundary: Anthropic API, OAuth, analytics, plugin loading, LSP server management, MCP connection management, compacting/context reduction, policy limits, and remote-managed settings.
   - This layer is where the app talks to network services, background daemons, auth providers, and external plugin or protocol servers.
   - It is the main separation between core agent logic and infrastructure concerns.

9. **Bridge and remote-control path**
   - `src/bridge/`, `src/remote/`, and `src/server/` implement remote/IDE-connected operation.
   - The bridge subsystem provides bidirectional messaging, session control, permissions callbacks, and transport adaptation for IDE integrations and REPL-style remote control.
   - Remote sessions, direct-connect server mode, and session resume are separate from the local terminal UI but reuse the same underlying task/query model.

10. **Multi-agent and task coordination**
   - `src/coordinator/`, `src/tasks/`, `src/tools/AgentTool/`, `src/utils/swarm/`, and `src/components/tasks/` together implement parallel work and agent swarms.
   - A “leader” session can spawn subagents, create teams, send messages, track background shell jobs, and surface progress in the UI.
   - These flows introduce a second execution dimension besides the main conversation: asynchronous work items with their own state, outputs, and lifecycle.

11. **Plugins, skills, and MCP extensibility**
   - `src/plugins/`, `src/skills/`, and `src/services/mcp/` are the extension system.
   - Skills are reusable workflows invoked by tools/commands; plugins contribute commands, tools, hooks, and output styles; MCP connects Claude Code to external tool servers.
   - The architecture treats these as loadable capability bundles, with trust, validation, and startup checks forming the boundary before activation.

12. **Memory, context, and session persistence**
   - `src/context.ts`, `src/history.ts`, `src/assistant/sessionHistory.ts`, `src/memdir/`, `src/services/SessionMemory/`, and `src/services/extractMemories/` manage long-lived conversational and project memory.
   - Context is assembled from user input, file history, repository state, memory files, session history, and tool outputs before each model call.
   - Compacting, extraction, and memory sync are designed to reduce context growth while preserving useful project knowledge.

13. **Configuration, permissions, and policy**
   - `src/utils/settings/`, `src/migrations/`, `src/constants/`, and permission-related utilities govern runtime behavior.
   - Settings are versioned and migrated; policy limits and managed settings can override local choices; permission rules constrain shell/filesystem/network actions.
   - This is a strong architectural boundary because it determines what the agent is allowed to do, not just what it can do.

14. **Observability and operational support**
   - `src/services/analytics/`, `src/utils/telemetry/`, `src/cost-tracker.ts`, and diagnostic/doctor commands provide runtime visibility.
   - The app tracks usage, token/cost metrics, internal events, and health checks, and exposes them through commands and status views.
   - Operational modules are deliberately separate from agent logic so they can be enabled, disabled, or gated independently.

15. **What an architecture diagram should emphasize**
   - The central hub is the **query/tool loop**: UI input and session state feed the query engine, which delegates to tools, permissions, and services, then streams results back into the UI.
   - The major surrounding rings are **interactive UI**, **integrations/services**, **remote/bridge connectivity**, and **extension mechanisms**.
   - The most important boundaries are: terminal UI vs. agent engine, engine vs. external services, and local session vs. remote/IDE-connected session.

Main entry points: [`src/services`](https://github.com/andytonglove/claude-code-leak/tree/main/src/services) (Services), [`src/QueryEngine.ts`](https://github.com/andytonglove/claude-code-leak/blob/main/src/QueryEngine.ts) (Query Engine), [`src/commands`](https://github.com/andytonglove/claude-code-leak/tree/main/src/commands) (Commands), [`src/main.tsx`](https://github.com/andytonglove/claude-code-leak/blob/main/src/main.tsx) (main)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_startup["Startup"]
  node_main["main<br/>entrypoint<br/>[main.tsx]"]
  node_entrypoints["Entrypoints<br/>startup routes"]
  node_bootstrap["Bootstrap<br/>startup setup"]
end

subgraph group_ui["Terminal UI"]
  node_repl["REPL Screen<br/>terminal session<br/>[REPL.tsx]"]
  node_app["App Shell<br/>ink/react UI<br/>[App.tsx]"]
  node_state[("App State<br/>shared state")]
  node_prompt["Prompt Flow<br/>input pipeline"]
  node_dialogs["Dialogs<br/>ui surfaces"]
end

subgraph group_engine["Agent Engine"]
  node_query["Query Engine<br/>agent loop<br/>[QueryEngine.ts]"]
  node_task[("Task Model<br/>work units<br/>[Task.ts]")]
  node_tool["Tool API<br/>tool schema<br/>[Tool.ts]"]
  node_tools["Tool Catalog<br/>tool registry<br/>[tools.ts]"]
  node_toolsvc["Tool Runtime<br/>tool execution"]
  node_permissions["Permissions<br/>safety policy"]
  node_memory[("Context & Memory<br/>session memory<br/>[context.ts]")]
  node_commands["Commands"]
end

subgraph group_integrations["Integrations"]
  node_services["Services<br/>integrations"]
  node_bridge["Bridge<br/>remote control"]
  node_remote["Remote Sessions<br/>session transport"]
  node_server["Direct Connect<br/>server mode"]
end

subgraph group_extensibility["Extensibility"]
  node_plugins["Plugins<br/>extension loader"]
  node_skills["Skills<br/>workflow bundles"]
  node_coordinator["Coordinator<br/>multi-agent orchestration"]
  node_swarm["Swarm Utils<br/>multi-agent runtime"]
end

node_main -->|"initializes"| node_bootstrap
node_main -->|"routes"| node_entrypoints
node_main -->|"opens"| node_repl
node_entrypoints -->|"launches"| node_repl
node_repl -->|"renders"| node_app
node_app -->|"uses"| node_state
node_app -->|"accepts input"| node_prompt
node_prompt -->|"parses slash cmds"| node_commands
node_prompt -->|"submits prompt"| node_query
node_query -->|"invokes"| node_tool
node_tool -->|"implemented by"| node_tools
node_tools -->|"executes via"| node_toolsvc
node_toolsvc -->|"checks"| node_permissions
node_query -->|"builds context"| node_memory
node_commands -->|"orchestrates"| node_services
node_services -->|"feeds"| node_bridge
node_services -->|"manages"| node_remote
node_remote -->|"connects"| node_server
node_services -->|"loads"| node_plugins
node_services -->|"enables"| node_skills
node_coordinator -->|"uses"| node_swarm
node_coordinator -->|"spawns"| node_task
node_query -->|"tracks"| node_task
node_commands -->|"controls"| node_bridge
node_commands -->|"manages"| node_coordinator
node_permissions -->|"surfaces"| node_dialogs

click node_main "https://github.com/andytonglove/claude-code-leak/blob/main/src/main.tsx"
click node_entrypoints "https://github.com/andytonglove/claude-code-leak/tree/main/src/entrypoints"
click node_bootstrap "https://github.com/andytonglove/claude-code-leak/tree/main/src/bootstrap"
click node_repl "https://github.com/andytonglove/claude-code-leak/blob/main/src/screens/REPL.tsx"
click node_app "https://github.com/andytonglove/claude-code-leak/blob/main/src/components/App.tsx"
click node_state "https://github.com/andytonglove/claude-code-leak/tree/main/src/state"
click node_prompt "https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/processUserInput"
click node_dialogs "https://github.com/andytonglove/claude-code-leak/tree/main/src/components"
click node_query "https://github.com/andytonglove/claude-code-leak/blob/main/src/QueryEngine.ts"
click node_task "https://github.com/andytonglove/claude-code-leak/blob/main/src/Task.ts"
click node_tool "https://github.com/andytonglove/claude-code-leak/blob/main/src/Tool.ts"
click node_tools "https://github.com/andytonglove/claude-code-leak/blob/main/src/tools.ts"
click node_toolsvc "https://github.com/andytonglove/claude-code-leak/tree/main/src/services/tools"
click node_permissions "https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/permissions"
click node_memory "https://github.com/andytonglove/claude-code-leak/blob/main/src/context.ts"
click node_commands "https://github.com/andytonglove/claude-code-leak/tree/main/src/commands"
click node_services "https://github.com/andytonglove/claude-code-leak/tree/main/src/services"
click node_bridge "https://github.com/andytonglove/claude-code-leak/tree/main/src/bridge"
click node_remote "https://github.com/andytonglove/claude-code-leak/tree/main/src/remote"
click node_server "https://github.com/andytonglove/claude-code-leak/tree/main/src/server"
click node_plugins "https://github.com/andytonglove/claude-code-leak/tree/main/src/plugins"
click node_skills "https://github.com/andytonglove/claude-code-leak/tree/main/src/skills"
click node_coordinator "https://github.com/andytonglove/claude-code-leak/tree/main/src/coordinator"
click node_swarm "https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/swarm"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_entrypoints,node_bootstrap toneBlue
class node_repl,node_app,node_state,node_prompt,node_dialogs toneAmber
class node_query,node_task,node_tool,node_tools,node_toolsvc,node_permissions,node_memory,node_commands toneMint
class node_services,node_bridge,node_remote,node_server toneRose
class node_plugins,node_skills,node_coordinator,node_swarm toneIndigo
```

## Components

### Startup

Bootstrapping, entrypoints, and session launch paths.

- [main](https://github.com/andytonglove/claude-code-leak/blob/main/src/main.tsx): entrypoint · Top-level process startup and mode selection. · `src/main.tsx`
- [Entrypoints](https://github.com/andytonglove/claude-code-leak/tree/main/src/entrypoints): startup routes · CLI, MCP, init, and SDK entry surfaces. · `src/entrypoints`
- [Bootstrap](https://github.com/andytonglove/claude-code-leak/tree/main/src/bootstrap): startup setup · Early environment, settings, and keychain/session preflight. · `src/bootstrap`

### Terminal UI

Ink/React rendering, screens, components, state, and context.

- [REPL Screen](https://github.com/andytonglove/claude-code-leak/blob/main/src/screens/REPL.tsx): terminal session · Primary interactive session screen and resume flow. · `src/screens/REPL.tsx`
- [App Shell](https://github.com/andytonglove/claude-code-leak/blob/main/src/components/App.tsx): ink/react UI · Root terminal app composition and top-level layout. · `src/components/App.tsx`
- [App State](https://github.com/andytonglove/claude-code-leak/tree/main/src/state): shared state · Centralized application state and selectors/hooks. · `src/state`
- [Prompt Flow](https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/processUserInput): input pipeline · User input, slash commands, and prompt handling. · `src/utils/processUserInput`
- [Dialogs](https://github.com/andytonglove/claude-code-leak/tree/main/src/components): ui surfaces · Permission prompts, settings, diffs, onboarding, and status dialogs. · `src/components`

### Agent Engine

Query loop, task model, tools, permissions, memory, and command parsing.

- [Query Engine](https://github.com/andytonglove/claude-code-leak/blob/main/src/QueryEngine.ts): agent loop · Conversation loop, streaming, tool calls, retries, and turn completion. · `src/QueryEngine.ts`
- [Task Model](https://github.com/andytonglove/claude-code-leak/blob/main/src/Task.ts): work units · Running work across local, remote, shell, and teammate contexts. · `src/Task.ts`
- [Tool API](https://github.com/andytonglove/claude-code-leak/blob/main/src/Tool.ts): tool schema · Typed tool definitions, permissions, and result rendering boundary. · `src/Tool.ts`
- [Tool Catalog](https://github.com/andytonglove/claude-code-leak/blob/main/src/tools.ts): tool registry · Registry of operational tools available to the agent. · `src/tools.ts`
- [Tool Runtime](https://github.com/andytonglove/claude-code-leak/tree/main/src/services/tools): tool execution · Streaming execution, orchestration, and tool hooks. · `src/services/tools`
- [Permissions](https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/permissions): safety policy · Approval, validation, and permission-mode enforcement. · `src/utils/permissions`
- [Context & Memory](https://github.com/andytonglove/claude-code-leak/blob/main/src/context.ts): session memory · Conversation context, history, memories, and compaction. · `src/context.ts`
- [Commands](https://github.com/andytonglove/claude-code-leak/tree/main/src/commands): slash commands · User-facing workflow, config, resume, review, and utility commands. · `src/commands`

### Integrations

External services, remote control, plugins, MCP, LSP, analytics, and auth.

- [Services](https://github.com/andytonglove/claude-code-leak/tree/main/src/services): integrations · API, auth, analytics, LSP, MCP, plugins, limits, and remote settings. · `src/services`
- [Bridge](https://github.com/andytonglove/claude-code-leak/tree/main/src/bridge): remote control · Bidirectional messaging for IDE and remote session control. · `src/bridge`
- [Remote Sessions](https://github.com/andytonglove/claude-code-leak/tree/main/src/remote): session transport · Remote session manager and websocket/session coordination. · `src/remote`
- [Direct Connect](https://github.com/andytonglove/claude-code-leak/tree/main/src/server): server mode · Direct-connect session creation and server-side session management. · `src/server`

### Extensibility

Plugins, skills, multi-agent workflows, and swarm coordination.

- [Plugins](https://github.com/andytonglove/claude-code-leak/tree/main/src/plugins): extension loader · Builtin and loadable plugins and their activation surface. · `src/plugins`
- [Skills](https://github.com/andytonglove/claude-code-leak/tree/main/src/skills): workflow bundles · Reusable skill workflows and bundled capabilities. · `src/skills`
- [Coordinator](https://github.com/andytonglove/claude-code-leak/tree/main/src/coordinator): multi-agent orchestration · Leader/session coordination for parallel work and swarms. · `src/coordinator`
- [Swarm Utils](https://github.com/andytonglove/claude-code-leak/tree/main/src/utils/swarm): multi-agent runtime · Spawn, permission sync, teammate layout, and in-process/back-end support. · `src/utils/swarm`

## Connections

- main → Bootstrap: initializes · Bootstraps environment and runtime state before app launch.
- main → Entrypoints: routes · Dispatches to CLI, MCP, init, or other entry modes.
- main → REPL Screen: opens · Starts the interactive terminal session UI.
- Entrypoints → REPL Screen: launches · Entry modes can create or resume the session UI.
- REPL Screen → App Shell: renders · REPL screen is composed through the app shell.
- App Shell → App State: uses · UI reads and writes centralized shared state.
- App Shell → Prompt Flow: accepts input · Prompt handling feeds user commands and text into the system.
- Prompt Flow → Commands: parses slash cmds · Slash commands are resolved through the command layer.
- Prompt Flow → Query Engine: submits prompt · Regular user input becomes a query-engine turn.
- Query Engine → Tool API: invokes · The engine dispatches typed tool calls.
- Tool API → Tool Catalog: implemented by · Concrete tools are registered in the catalog.
- Tool Catalog → Tool Runtime: executes via · Tool definitions run through the tool execution services.
- Tool Runtime → Permissions: checks · Dangerous actions pass through permission and validation gates.
- Query Engine → Context & Memory: builds context · Conversation state, history, and memory are assembled into each turn.
- Commands → Services: orchestrates · Commands wrap service-layer operations and background flows.
- Services → Bridge: feeds · Remote control and IDE integration use bridge messaging.
- Services → Remote Sessions: manages · Remote session lifecycle is handled by remote services.
- Remote Sessions → Direct Connect: connects · Remote sessions can be created through direct-connect server mode.
- Services → Plugins: loads · Plugin loading, policy, and startup checks come from services.
- Services → Skills: enables · Skill loading and skill-based workflows are activated through services.
- Coordinator → Swarm Utils: uses · Coordinator flows depend on swarm/spawn utilities.
- Coordinator → Task Model: spawns · Parallel work creates additional task units.
- Query Engine → Task Model: tracks · Agent turns and background work are tracked as tasks.
- Commands → Bridge: controls · Bridge-related commands expose session control and diagnostics.
- Commands → Coordinator: manages · Agent/team commands surface multi-agent coordination.
- Permissions → Dialogs: surfaces · Permission decisions are often resolved in UI dialogs.
