# chinasiro/claude-code-sourcemap architecture

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

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

## Overview

1. **What this repo is**
   - This is the reconstructed source for `@anthropic-ai/claude-code` v2.1.88, a terminal-first AI assistant/runtime rather than a conventional web app.
   - The main executable lives in `package/cli.js` with the TypeScript app in `restored-src/src`, and the app is built around a React-style terminal UI.

2. **Top-level runtime shape**
   - `src/main.tsx`, `src/entrypoints/cli.tsx`, and `src/entrypoints/init.ts` are the main startup path.
   - The app runs as a CLI process, manages its own event loop, and uses Node/Bun-oriented tooling plus native terminal handling.

3. **Terminal UI layer**
   - `src/ink/` is a custom terminal rendering/runtime layer, and `src/components/` contains the visible UI.
   - The UI is organized as dialogs, message feeds, input controls, status lines, permission prompts, and settings panes.
   - This layer is responsible for rendering session state, prompts, tool results, approvals, and notifications to the terminal.

4. **Session and application state**
   - `src/state/`, `src/context/`, `src/history.ts`, `src/assistant/`, and `src/bootstrap/` hold the app’s mutable session model.
   - These modules track conversation history, queued messages, session metadata, selected model/mode, and UI overlay state.
   - `src/hooks/` stitches state into the UI via many reactive hooks for input, session lifecycle, notifications, and integrations.

5. **Core interaction flow**
   - User input enters through `components/PromptInput` and related hooks.
   - Input is classified into text prompts, slash commands, or shell/tool actions via `src/utils/processUserInput`.
   - The resulting action is routed into the main session loop, where it becomes either a model request, a command handler call, or a tool invocation.

6. **Model and API boundary**
   - `src/services/api/`, `src/query/`, `src/services/claudeAiLimits.ts`, `src/utils/model/`, and `src/services/tokenEstimation.ts` define the AI/backend boundary.
   - This layer handles Claude API calls, retries, usage/rate limits, model selection, prompt construction, token budgeting, and error normalization.
   - It is the main outbound dependency to Anthropic services and related account/usage endpoints.

7. **Tool execution pipeline**
   - `src/tools/` contains the concrete capabilities the assistant can invoke: shell, file read/write/edit, grep/glob, web fetch/search, tasks, agent spawning, MCP, notebook edits, and more.
   - `src/services/tools/` and `src/utils/toolPool.ts` / `toolOrchestration.ts` manage execution, streaming results, and lifecycle tracking.
   - Tool results are converted into typed messages and fed back into the conversation UI and model context.

8. **Permissions, sandboxing, and safety**
   - Safety is a major architectural boundary: `src/utils/permissions/`, `src/components/permissions/`, and `src/tools/BashTool` / `PowerShellTool` implement approval flows and command validation.
   - Sandbox-related behavior is handled by `src/utils/sandbox/`, `src/components/sandbox/`, and shell policy helpers.
   - File edits, shell commands, and external access all pass through permission decisions, policy rules, and destructive-action checks before execution.

9. **Integrations with developer tools and local environment**
   - The repo integrates with IDEs, LSP, Git, browser/chrome handoff, voice, and local shell environments through modules under `src/services/lsp`, `src/utils/ide`, `src/utils/git`, `src/voice`, and `src/utils/claudeInChrome`.
   - These integrations feed status, diagnostics, file context, and external actions back into the assistant workflow.
   - MCP support (`src/services/mcp`, `src/components/mcp`, `src/tools/MCPTool`) is a first-class extension boundary for connecting external tool servers.

10. **Remote control and multi-device/session transport**
   - `src/bridge/`, `src/remote/`, `src/server/`, and `src/upstreamproxy/` implement remote sessions, bridge control, websocket/SSE transport, and direct-connect flows.
   - This is the boundary for controlling or resuming sessions outside the local terminal, including trusted device handling and session ingress.
   - It separates local interactive execution from networked session management and remote orchestration.

11. **Agents, tasks, and swarm/coordinator modes**
   - `src/tools/AgentTool`, `src/tasks/`, `src/coordinator/`, and `src/utils/swarm/` support subordinate agents, background tasks, teammate modes, and multi-agent coordination.
   - The architecture treats agents/tasks as durable execution units with their own status, progress, permissions, and resumability.
   - This subsystem is distinct from the main chat loop: it fans work out to background or remote actors and then merges their outputs back into the parent session.

12. **Plugins, skills, and extensibility**
   - `src/plugins/`, `src/services/plugins/`, `src/skills/`, and `src/utils/hooks/` provide the extension model.
   - Plugins can add commands, tools, hooks, output styles, and marketplace-distributed content; skills inject task-specific behavior and prompts.
   - This is the main customization boundary, and it affects startup, command routing, tool availability, and UI affordances.

13. **Persistence, memory, and session recovery**
   - `src/memdir/`, `src/services/SessionMemory/`, `src/utils/sessionStorage*`, `src/utils/filePersistence/`, and `src/utils/conversationRecovery.ts` handle local state and recall.
   - The app persists session history, summaries, memories, settings, and cached outputs so sessions can be resumed or compacted later.
   - Memory files and session artifacts form a second data plane beside the live conversation stream.

14. **Telemetry, analytics, and operational services**
   - `src/services/analytics/`, `src/utils/telemetry/`, `src/services/notifier.ts`, and logging/tracing utilities provide observability.
   - External sinks include Datadog, GrowthBook, BigQuery, and first-party event logging, with opt-out and killswitch support.
   - This is not core to user interaction, but it materially affects startup checks, experiment gating, and post-run diagnostics.

15. **How to think about the architecture diagram**
   - The central hub is the terminal session loop: user input → command/tool dispatch → permission/safety gate → model/API or local tool execution → message/state update → UI render.
   - Around that core sit extensibility boundaries (plugins, skills, MCP), collaboration boundaries (agents/tasks/swarm/remote), and operational boundaries (storage, telemetry, auth, updates).

Main entry points: [`restored-src/src/hooks/useMainLoopModel.ts`](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/hooks/useMainLoopModel.ts) (Hooks layer), [`restored-src/src/services/tools/toolOrchestration.ts`](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/tools/toolOrchestration.ts) (Tool executor), [`restored-src/src/components/App.tsx`](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/App.tsx) (App shell), [`restored-src/src/QueryEngine.ts`](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/QueryEngine.ts) (Query engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime"]
  node_main_entry["Main entry<br/>CLI bootstrap<br/>[main.tsx]"]
  node_cli_entry["CLI entry<br/>Entrypoint<br/>[cli.tsx]"]
  node_init_entry["Init entry<br/>Entrypoint<br/>[init.ts]"]
  node_ink_runtime["Ink runtime<br/>Terminal renderer<br/>[ink.tsx]"]
end

subgraph group_ui["Terminal UI"]
  node_app_shell["App shell<br/>UI root<br/>[App.tsx]"]
  node_prompt_input["Prompt input<br/>Input UI<br/>[PromptInput.tsx]"]
  node_message_feed["Message feed<br/>Conversation UI<br/>[Messages.tsx]"]
  node_permission_ui["Permissions UI<br/>Approval UI"]
  node_status_panels["Status panels<br/>UI surfaces<br/>[StatusLine.tsx]"]
end

subgraph group_core["Core Loop"]
  node_app_state[("App state<br/>Session state<br/>[AppState.tsx]")]
  node_context_layer(("Contexts<br/>State wiring<br/>[context.ts]"))
  node_history_store["History<br/>Conversation memory<br/>[history.ts]"]
  node_command_router["Command router<br/>Input classifier"]
  node_hooks_layer["Hooks layer<br/>Reactive glue"]
end

subgraph group_model["Model Boundary"]
  node_query_engine["Query engine<br/>Model orchestration<br/>[QueryEngine.ts]"]
  node_api_boundary["API client<br/>Claude API<br/>[claude.ts]"]
  node_limits_budget["Limits & budget<br/>Policy<br/>[claudeAiLimits.ts]"]
end

subgraph group_tools["Tooling"]
  node_tool_executor["Tool executor<br/>Tool runtime"]
  node_tool_catalog["Tool catalog<br/>Capabilities<br/>[tools.ts]"]
  node_permission_engine["Permission engine<br/>Safety policy<br/>[permissions.ts]"]
  node_task_system["Task system<br/>Background execution<br/>[tasks.ts]"]
end

subgraph group_integrations["Integrations"]
  node_agent_system["Agent system<br/>Subagents<br/>[AgentTool.tsx]"]
  node_mcp_boundary["MCP boundary<br/>Extension bridge"]
  node_plugin_system["Plugin system<br/>Extensibility<br/>[builtinPlugins.ts]"]
  node_ide_lsp["IDE & LSP<br/>Dev integration"]
  node_remote_bridge["Remote bridge<br/>Remote control<br/>[bridgeMain.ts]"]
end

subgraph group_storage["Persistence"]
  node_session_memory["Session memory<br/>Persistence<br/>[sessionMemory.ts]"]
  node_memdir["Memdir<br/>Local memory<br/>[memdir.ts]"]
  node_session_storage["Session storage<br/>Local state<br/>[sessionStorage.ts]"]
end

subgraph group_ops["Operations"]
  node_telemetry["Telemetry<br/>Observability<br/>[index.ts]"]
end

node_main_entry -->|"starts"| node_cli_entry
node_main_entry -->|"initializes"| node_init_entry
node_cli_entry -->|"mounts"| node_ink_runtime
node_ink_runtime -->|"renders"| node_app_shell
node_app_shell -->|"includes"| node_prompt_input
node_app_shell -->|"includes"| node_message_feed
node_app_shell -->|"includes"| node_permission_ui
node_app_shell -->|"includes"| node_status_panels
node_prompt_input -->|"submits"| node_command_router
node_command_router -->|"dispatches"| node_hooks_layer
node_hooks_layer -->|"updates"| node_app_state
node_hooks_layer -->|"records"| node_history_store
node_hooks_layer -->|"requests"| node_query_engine
node_query_engine -->|"calls"| node_api_boundary
node_query_engine -->|"checks"| node_limits_budget
node_query_engine -->|"invokes"| node_tool_executor
node_tool_executor -->|"executes"| node_tool_catalog
node_tool_executor -->|"gates"| node_permission_engine
node_permission_engine -->|"prompts"| node_permission_ui
node_tool_executor -->|"spawns"| node_task_system
node_tool_executor -->|"fans out"| node_agent_system
node_tool_executor -->|"bridges"| node_mcp_boundary
node_tool_executor -->|"feeds"| node_message_feed
node_hooks_layer -->|"loads"| node_plugin_system
node_hooks_layer -->|"syncs"| node_ide_lsp
node_hooks_layer -->|"connects"| node_remote_bridge
node_hooks_layer -->|"persists"| node_session_memory
node_session_memory -->|"writes"| node_memdir
node_hooks_layer -->|"saves"| node_session_storage
node_app_state -->|"emits"| node_telemetry
node_query_engine -->|"logs"| node_telemetry

click node_main_entry "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/main.tsx"
click node_cli_entry "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/entrypoints/cli.tsx"
click node_init_entry "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/entrypoints/init.ts"
click node_ink_runtime "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/ink/ink.tsx"
click node_app_shell "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/App.tsx"
click node_prompt_input "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/PromptInput/PromptInput.tsx"
click node_message_feed "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/Messages.tsx"
click node_permission_ui "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/permissions/PermissionDialog.tsx"
click node_status_panels "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/StatusLine.tsx"
click node_app_state "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/state/AppState.tsx"
click node_context_layer "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/context.ts"
click node_history_store "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/history.ts"
click node_command_router "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/processUserInput/processUserInput.ts"
click node_hooks_layer "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/hooks/useMainLoopModel.ts"
click node_query_engine "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/QueryEngine.ts"
click node_api_boundary "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/api/claude.ts"
click node_limits_budget "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/claudeAiLimits.ts"
click node_tool_executor "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/tools/toolOrchestration.ts"
click node_tool_catalog "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tools.ts"
click node_permission_engine "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/permissions/permissions.ts"
click node_task_system "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tasks.ts"
click node_agent_system "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tools/AgentTool/AgentTool.tsx"
click node_mcp_boundary "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/mcp/MCPConnectionManager.tsx"
click node_plugin_system "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/plugins/builtinPlugins.ts"
click node_ide_lsp "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/lsp/LSPServerManager.ts"
click node_remote_bridge "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/bridge/bridgeMain.ts"
click node_session_memory "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/SessionMemory/sessionMemory.ts"
click node_memdir "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/memdir/memdir.ts"
click node_session_storage "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/sessionStorage.ts"
click node_telemetry "https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/analytics/index.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_main_entry,node_cli_entry,node_init_entry,node_ink_runtime,node_session_memory,node_memdir,node_session_storage toneBlue
class node_app_shell,node_prompt_input,node_message_feed,node_permission_ui,node_status_panels,node_telemetry toneAmber
class node_app_state,node_context_layer,node_history_store,node_command_router,node_hooks_layer toneMint
class node_query_engine,node_api_boundary,node_limits_budget toneRose
class node_tool_executor,node_tool_catalog,node_permission_engine,node_task_system toneIndigo
class node_agent_system,node_mcp_boundary,node_plugin_system,node_ide_lsp,node_remote_bridge toneTeal
```

## Components

### Runtime

CLI startup, entrypoints, and terminal engine

- [Main entry](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/main.tsx): CLI bootstrap · Process startup and app wiring · `restored-src/src/main.tsx`
- [CLI entry](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/entrypoints/cli.tsx): Entrypoint · CLI process initialization and dispatch · `restored-src/src/entrypoints/cli.tsx`
- [Init entry](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/entrypoints/init.ts): Entrypoint · One-time initialization path · `restored-src/src/entrypoints/init.ts`
- [Ink runtime](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/ink/ink.tsx): Terminal renderer · Custom terminal rendering, events, layout, and screen output · `restored-src/src/ink/ink.tsx`

### Terminal UI

React-style screen composition and interactive panels

- [App shell](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/App.tsx): UI root · Top-level app composition and screen orchestration · `restored-src/src/components/App.tsx`
- [Prompt input](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/PromptInput/PromptInput.tsx): Input UI · User command entry, shortcuts, and queued actions · `restored-src/src/components/PromptInput/PromptInput.tsx`
- [Message feed](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/Messages.tsx): Conversation UI · Session transcript, tool results, and assistant/user messages · `restored-src/src/components/Messages.tsx`
- [Permissions UI](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/permissions/PermissionDialog.tsx): Approval UI · Approval dialogs and safety prompts · `restored-src/src/components/permissions/PermissionDialog.tsx`
- [Status panels](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/components/StatusLine.tsx): UI surfaces · Status line, overlays, settings, and notifications · `restored-src/src/components/StatusLine.tsx`

### Core Loop

Session state, message routing, commands, and hooks

- [App state](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/state/AppState.tsx): Session state · Mutable session model and selectors · `restored-src/src/state/AppState.tsx`
- [Contexts](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/context.ts): State wiring · React contexts for overlays, mailbox, notifications, voice, and prompts · `restored-src/src/context.ts`
- [History](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/history.ts): Conversation memory · Conversation history and session replay state · `restored-src/src/history.ts`
- [Command router](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/processUserInput/processUserInput.ts): Input classifier · Routes text, slash commands, and shell/tool actions · `restored-src/src/utils/processUserInput/processUserInput.ts`
- [Hooks layer](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/hooks/useMainLoopModel.ts): Reactive glue · Session lifecycle, input, notifications, and integration hooks · `restored-src/src/hooks/useMainLoopModel.ts`

### Model Boundary

API access, token budgeting, limits, and query orchestration

- [Query engine](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/QueryEngine.ts): Model orchestration · Prompt construction, budgeting, and execution coordination · `restored-src/src/QueryEngine.ts`
- [API client](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/api/claude.ts): Claude API · Outbound Anthropic/backend requests, retry, and error normalization · `restored-src/src/services/api/claude.ts`
- [Limits & budget](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/claudeAiLimits.ts): Policy · Rate limits, usage, token budgets, and model constraints · `restored-src/src/services/claudeAiLimits.ts`

### Tooling

Tool execution, permissions, and task orchestration

- [Tool executor](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/tools/toolOrchestration.ts): Tool runtime · Streaming execution, orchestration, and lifecycle tracking · `restored-src/src/services/tools/toolOrchestration.ts`
- [Tool catalog](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tools.ts): Capabilities · Concrete tool implementations for shell, files, web, tasks, agents, and MCP · `restored-src/src/tools.ts`
- [Permission engine](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/permissions/permissions.ts): Safety policy · Permission modes, rule evaluation, sandboxing, and command validation · `restored-src/src/utils/permissions/permissions.ts`
- [Task system](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tasks.ts): Background execution · Local, remote, and teammate tasks plus progress reporting · `restored-src/src/tasks.ts`

### Integrations

Remote control, IDE/LSP, MCP, plugins, and voice

- [Agent system](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/tools/AgentTool/AgentTool.tsx): Subagents · Agent spawning, built-in agents, memory, and resume flow · `restored-src/src/tools/AgentTool/AgentTool.tsx`
- [MCP boundary](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/mcp/MCPConnectionManager.tsx): Extension bridge · Model Context Protocol servers, approvals, and tool exposure · `restored-src/src/services/mcp/MCPConnectionManager.tsx`
- [Plugin system](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/plugins/builtinPlugins.ts): Extensibility · Plugin loading, commands, hooks, output styles, and marketplace integration · `restored-src/src/plugins/builtinPlugins.ts`
- [IDE & LSP](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/lsp/LSPServerManager.ts): Dev integration · Editor, IDE, and language-server integration · `restored-src/src/services/lsp/LSPServerManager.ts`
- [Remote bridge](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/bridge/bridgeMain.ts): Remote control · Remote sessions, websocket/SSE transport, and direct-connect ingress · `restored-src/src/bridge/bridgeMain.ts`

### Persistence

Session memory, local storage, and recovery

- [Session memory](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/SessionMemory/sessionMemory.ts): Persistence · Memory files, summaries, and recovery artifacts · `restored-src/src/services/SessionMemory/sessionMemory.ts`
- [Memdir](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/memdir/memdir.ts): Local memory · Filesystem-backed memory discovery and team memory paths · `restored-src/src/memdir/memdir.ts`
- [Session storage](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/utils/sessionStorage.ts): Local state · Session persistence, portable storage, and recovery helpers · `restored-src/src/utils/sessionStorage.ts`

### Operations

Telemetry, analytics, updates, and diagnostics

- [Telemetry](https://github.com/chinasiro/claude-code-sourcemap/blob/main/restored-src/src/services/analytics/index.ts): Observability · Analytics, tracing, logging, and experiment sinks · `restored-src/src/services/analytics/index.ts`

## Connections

- Main entry → CLI entry: starts · CLI startup hands off to the main command entrypoint
- Main entry → Init entry: initializes · Runs startup initialization before interactive work
- CLI entry → Ink runtime: mounts · Creates the terminal UI runtime
- Ink runtime → App shell: renders · Hosts the application root component
- App shell → Prompt input: includes · Provides the user input surface
- App shell → Message feed: includes · Displays conversation and tool messages
- App shell → Permissions UI: includes · Surfaces approvals and safety prompts
- App shell → Status panels: includes · Shows status, notifications, and settings
- Prompt input → Command router: submits · User input is classified into action types
- Command router → Hooks layer: dispatches · Actions enter the reactive session loop
- Hooks layer → App state: updates · Hooks mutate session/application state
- Hooks layer → History: records · Conversation turns are appended to history
- Hooks layer → Query engine: requests · Model turns are scheduled through the query layer
- Query engine → API client: calls · Executes Claude/backend requests
- Query engine → Limits & budget: checks · Applies model, usage, and token constraints
- Query engine → Tool executor: invokes · Model tool calls are routed into execution
- Tool executor → Tool catalog: executes · Dispatches concrete tool implementations
- Tool executor → Permission engine: gates · Tool activity is filtered through safety policy
- Permission engine → Permissions UI: prompts · Approval decisions are surfaced to the user
- Tool executor → Task system: spawns · Background and delegated work is tracked as tasks
- Tool executor → Agent system: fans out · Agent tool use creates subordinate execution units
- Tool executor → MCP boundary: bridges · MCP tools and servers are mediated through the extension boundary
- Tool executor → Message feed: feeds · Tool results are converted back into conversation messages
- Hooks layer → Plugin system: loads · Plugins contribute commands, tools, hooks, and styles
- Hooks layer → IDE & LSP: syncs · IDE and LSP state is observed through hooks
- Hooks layer → Remote bridge: connects · Remote session and bridge state is wired into the loop
- Hooks layer → Session memory: persists · Session summaries and memory artifacts are stored
- Session memory → Memdir: writes · Memory files live in the local memory directory
- Hooks layer → Session storage: saves · Session recovery and local state are persisted
- App state → Telemetry: emits · Operational events and traces are produced from state changes
- Query engine → Telemetry: logs · Model and request activity is observed
