# tomrailio/claude-code architecture

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

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

## Overview

Claude Code is a terminal-based AI software-engineering CLI. The user invokes slash commands or submits a prompt; the query engine coordinates model interaction and tool use, while tools perform coding and workflow tasks and session data can be persisted for later resumption. The README also documents MCP, LSP, plugins, skills, remote sessions, and IDE bridging as product capabilities. Several connections below are grounded only in README descriptions or the source index; unsampled subsystem internals and runtime wiring are not inferred.

Main entry points: [`src/QueryEngine.ts`](https://github.com/tomrailio/claude-code/blob/main/src/QueryEngine.ts) (Query engine), [`src/tools`](https://github.com/tomrailio/claude-code/tree/main/src/tools) (Agent tools), [`src/commands`](https://github.com/tomrailio/claude-code/tree/main/src/commands) (Slash commands), [`src/bootstrap/state.ts`](https://github.com/tomrailio/claude-code/blob/main/src/bootstrap/state.ts) (Bootstrap state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["CLI Interaction"]
  node_commands["Slash commands"]
  node_registry["Command registry<br/>[commands.ts]"]
end

subgraph group_agent["Agent Runtime"]
  node_query_engine["Query engine<br/>[QueryEngine.ts]"]
  node_query["Model query<br/>[query.ts]"]
  node_tool_contract["Tool contract<br/>[Tool.ts]"]
  node_message_model["Message processing<br/>[messages.ts]"]
end

subgraph group_capabilities["Developer Capabilities"]
  node_tools["Agent tools"]
end

subgraph group_state["Session and State"]
  node_session_state["Bootstrap state<br/>[state.ts]"]
  node_session_storage[("Session storage<br/>[sessionStorage.ts]")]
  node_tool_results[("Tool result storage")]
  node_configuration["Configuration<br/>[config.ts]"]
  node_logging["Logging and diagnostics<br/>[log.ts]"]
  node_debug["Debug logging<br/>[debug.ts]"]
  node_environment["Environment utilities<br/>[envUtils.ts]"]
  node_slow_ops["Slow operation tracking<br/>[slowOperations.ts]"]
end

subgraph group_integrations["Integrations"]
  node_mcp["MCP services"]
  node_lsp["LSP services"]
  node_plugins["Plugin system"]
  node_bridge["IDE and remote bridge"]
end

node_user(("Terminal user"))

node_user -->|"invokes"| node_commands
node_commands -->|"registered by"| node_registry
node_registry -->|"imports commands"| node_commands
node_query_engine -->|"uses"| node_query
node_query_engine -->|"uses"| node_tool_contract
node_query -->|"uses"| node_tool_contract
node_query_engine -.->|"invokes tools"| node_tools
node_tools -.->|"can invoke"| node_mcp
node_tools -.->|"can invoke"| node_lsp
node_session_storage -->|"reads state"| node_session_state
node_configuration -->|"reads state"| node_session_state
node_slow_ops -->|"logs to"| node_debug
node_slow_ops -->|"records metrics"| node_session_state
node_debug -->|"checks flags"| node_environment
node_logging -->|"uses utilities"| node_environment
node_plugins -.->|"uses settings"| node_configuration
node_bridge -.->|"enables handoff"| node_user

click node_commands "https://github.com/tomrailio/claude-code/tree/main/src/commands"
click node_registry "https://github.com/tomrailio/claude-code/blob/main/src/commands.ts"
click node_query_engine "https://github.com/tomrailio/claude-code/blob/main/src/QueryEngine.ts"
click node_query "https://github.com/tomrailio/claude-code/blob/main/src/query.ts"
click node_tool_contract "https://github.com/tomrailio/claude-code/blob/main/src/Tool.ts"
click node_tools "https://github.com/tomrailio/claude-code/tree/main/src/tools"
click node_mcp "https://github.com/tomrailio/claude-code/tree/main/src/services/mcp"
click node_lsp "https://github.com/tomrailio/claude-code/tree/main/src/services/lsp"
click node_plugins "https://github.com/tomrailio/claude-code/tree/main/src/services/plugins"
click node_bridge "https://github.com/tomrailio/claude-code/tree/main/src/bridge"
click node_session_state "https://github.com/tomrailio/claude-code/blob/main/src/bootstrap/state.ts"
click node_session_storage "https://github.com/tomrailio/claude-code/blob/main/src/utils/sessionStorage.ts"
click node_tool_results "https://github.com/tomrailio/claude-code/blob/main/src/utils/toolResultStorage.ts"
click node_configuration "https://github.com/tomrailio/claude-code/blob/main/src/utils/config.ts"
click node_message_model "https://github.com/tomrailio/claude-code/blob/main/src/utils/messages.ts"
click node_logging "https://github.com/tomrailio/claude-code/blob/main/src/utils/log.ts"
click node_debug "https://github.com/tomrailio/claude-code/blob/main/src/utils/debug.ts"
click node_environment "https://github.com/tomrailio/claude-code/blob/main/src/utils/envUtils.ts"
click node_slow_ops "https://github.com/tomrailio/claude-code/blob/main/src/utils/slowOperations.ts"

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_commands,node_registry,node_user toneBlue
class node_query_engine,node_query,node_tool_contract,node_message_model toneAmber
class node_tools toneMint
class node_session_state,node_session_storage,node_tool_results,node_configuration,node_logging,node_debug,node_environment,node_slow_ops toneRose
class node_mcp,node_lsp,node_plugins,node_bridge toneIndigo
```

## Components

### CLI Interaction

- [Slash commands](https://github.com/tomrailio/claude-code/tree/main/src/commands): `src/commands`
- [Command registry](https://github.com/tomrailio/claude-code/blob/main/src/commands.ts): `src/commands.ts`

### Agent Runtime

- [Query engine](https://github.com/tomrailio/claude-code/blob/main/src/QueryEngine.ts): `src/QueryEngine.ts`
- [Model query](https://github.com/tomrailio/claude-code/blob/main/src/query.ts): `src/query.ts`
- [Tool contract](https://github.com/tomrailio/claude-code/blob/main/src/Tool.ts): `src/Tool.ts`
- [Message processing](https://github.com/tomrailio/claude-code/blob/main/src/utils/messages.ts): `src/utils/messages.ts`

### Developer Capabilities

- [Agent tools](https://github.com/tomrailio/claude-code/tree/main/src/tools): `src/tools`

### Session and State

- [Bootstrap state](https://github.com/tomrailio/claude-code/blob/main/src/bootstrap/state.ts): `src/bootstrap/state.ts`
- [Session storage](https://github.com/tomrailio/claude-code/blob/main/src/utils/sessionStorage.ts): `src/utils/sessionStorage.ts`
- [Tool result storage](https://github.com/tomrailio/claude-code/blob/main/src/utils/toolResultStorage.ts): `src/utils/toolResultStorage.ts`
- [Configuration](https://github.com/tomrailio/claude-code/blob/main/src/utils/config.ts): `src/utils/config.ts`
- [Logging and diagnostics](https://github.com/tomrailio/claude-code/blob/main/src/utils/log.ts): `src/utils/log.ts`
- [Debug logging](https://github.com/tomrailio/claude-code/blob/main/src/utils/debug.ts): `src/utils/debug.ts`
- [Environment utilities](https://github.com/tomrailio/claude-code/blob/main/src/utils/envUtils.ts): `src/utils/envUtils.ts`
- [Slow operation tracking](https://github.com/tomrailio/claude-code/blob/main/src/utils/slowOperations.ts): `src/utils/slowOperations.ts`

### Integrations

- [MCP services](https://github.com/tomrailio/claude-code/tree/main/src/services/mcp): `src/services/mcp`
- [LSP services](https://github.com/tomrailio/claude-code/tree/main/src/services/lsp): `src/services/lsp`
- [Plugin system](https://github.com/tomrailio/claude-code/tree/main/src/services/plugins): `src/services/plugins`
- [IDE and remote bridge](https://github.com/tomrailio/claude-code/tree/main/src/bridge): `src/bridge`

### Other components

- **Terminal user**

## Connections

- Terminal user → Slash commands: invokes (evidence: `README.md`)
- Slash commands → Command registry: registered by (evidence: `src/commands.ts`)
- Command registry → Slash commands: imports commands (evidence: `src/commands.ts`)
- Query engine → Model query: uses (evidence: `src/QueryEngine.ts`)
- Query engine → Tool contract: uses (evidence: `src/QueryEngine.ts`)
- Model query → Tool contract: uses (evidence: `src/query.ts`)
- Query engine → Agent tools: invokes tools (evidence: `src/QueryEngine.ts`)
- Agent tools → MCP services: can invoke
- Agent tools → LSP services: can invoke
- Session storage → Bootstrap state: reads state (evidence: `src/utils/sessionStorage.ts`)
- Configuration → Bootstrap state: reads state (evidence: `src/utils/config.ts`)
- Slow operation tracking → Debug logging: logs to (evidence: `src/utils/slowOperations.ts`)
- Slow operation tracking → Bootstrap state: records metrics (evidence: `src/utils/slowOperations.ts`)
- Debug logging → Environment utilities: checks flags (evidence: `src/utils/debug.ts`)
- Logging and diagnostics → Environment utilities: uses utilities (evidence: `src/utils/log.ts`)
- Plugin system → Configuration: uses settings
- IDE and remote bridge → Terminal user: enables handoff
