# githpriyanshu23/claude-code-leaks architecture

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

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

## Overview

1. This repository is the source for a terminal-based AI coding agent, built in TypeScript on Bun. The main runtime is a React + Ink CLI UI, not a browser app, and the architecture centers on an interactive session loop that coordinates user input, LLM calls, tool execution, and streamed UI updates.

2. The top-level flow starts in `src/main.tsx` and the entrypoints under `src/entrypoints/`. Startup wires together CLI parsing, configuration/bootstrap, state initialization, and feature-flagged loading of optional subsystems. From there, the app hands control to the REPL-style terminal UI in `src/screens/` and `src/components/`.

3. The core orchestration boundary is the query engine (`src/QueryEngine.ts`) plus supporting context assembly (`src/context.ts`, `src/query/`, `src/services/compact/`). This is where prompts are built, conversation state is summarized/compacted, model requests are made to Anthropic, streamed responses are consumed, and tool-call loops are managed until a turn completes.

4. User-facing commands are a separate subsystem under `src/commands/`. These are slash commands such as review, compact, mcp, config, login/logout, resume, diff, and task/session commands. They are not the same as agent tools: commands mutate app/session state, open dialogs, or launch flows, while tools are invoked by the model during a turn.

5. Agent tools live under `src/tools/` and form the execution boundary between the LLM and the local environment. This includes shell execution, file read/write/edit, search, web fetch/search, LSP, MCP, notebook editing, agent spawning, task APIs, and remote triggers. Each tool module owns its schema, UI rendering, and security/permission behavior, with `src/Tool.ts` and `src/tools.ts` acting as the common registry and type layer.

6. Tool execution is guarded by a permission subsystem in `src/hooks/toolPermission/` and `src/utils/permissions/`. That layer decides whether a tool call is auto-approved, denied, or surfaced to the user, and it supports mode-dependent behavior like default, plan, bypass, auto, and classifier-based decisions. This is a major architectural boundary because all high-risk actions pass through it.

7. The terminal UI is built from a large React/Ink component tree under `src/components/`, with reusable primitives in `src/ink/`. The UI is state-driven: `src/state/` holds app state, while hooks under `src/hooks/` connect state, notifications, keybindings, prompt input, history, task progress, and modal dialogs to the rendered terminal experience.

8. External integrations are isolated into service layers under `src/services/`. The most important are:
   - `services/api/` for Anthropic API and related backend calls
   - `services/oauth/` and `src/utils/secureStorage/` for authentication and credential storage
   - `services/mcp/` for Model Context Protocol servers and tool exposure
   - `services/lsp/` for language-server-based code intelligence
   - `services/plugins/` for plugin loading/installation/validation
   These services encapsulate network and platform dependencies so the core session loop stays cleaner.

9. IDE and editor connectivity is handled by the bridge subsystem in `src/bridge/` plus the remote control code in `src/remote/` and `src/server/`. The bridge provides bidirectional messaging, permissions callbacks, session creation, and REPL transport for integrations like VS Code or JetBrains. Remote session management adds a separate boundary for session ingress, websocket/session syncing, and handoff between local and remote control surfaces.

10. The repository has strong support for multi-agent and background work. `src/coordinator/`, `src/tasks/`, `src/utils/swarm/`, and `src/tools/AgentTool/` implement task assignment, sub-agent spawning, teammate/in-process/remote task variants, and coordination policies. These flows are distinct from the main chat loop: they let the system delegate work to other sessions or agents while keeping task status and outputs visible in the UI.

11. Persistent knowledge and session continuity are handled by `src/memdir/`, `src/history.ts`, `src/services/SessionMemory/`, and storage utilities in `src/utils/sessionStorage*` and `src/utils/filePersistence/`. These layers manage conversation history, memory files, extracted memories, session restore, and file-backed caches so the agent can resume or summarize prior work.

12. Around the core loop are cross-cutting subsystems for safety, observability, and product behavior: telemetry/analytics in `src/services/analytics/` and `src/utils/telemetry/`, rate-limit and cost tracking in `src/cost-tracker.ts` and related utilities, settings/migrations in `src/utils/settings/` and `src/migrations/`, and feature flags/plugin/skill loading in `src/plugins/`, `src/skills/`, and `src/utils/plugins/`. For an architecture diagram, the cleanest split is: terminal UI and commands at the edge, query/tool orchestration in the middle, and external services/integrations plus persistence beneath that.

Main entry points: [`src/QueryEngine.ts`](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/QueryEngine.ts) (Query engine), [`src/tools`](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/tools) (Agent tools), [`src/screens/REPL.tsx`](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/screens/REPL.tsx) (REPL screen), [`src/components`](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/components) (Ink UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_core["Core loop"]
  node_node_main["Entry<br/>startup<br/>[main.tsx]"]
  node_node_entrypoints["Entrypoints<br/>bootstraps"]
  node_node_appstate[("App state<br/>state store")]
  node_node_query{{"Query engine<br/>orchestrator<br/>[QueryEngine.ts]"}}
  node_node_context["Context build<br/>prompt context<br/>[context.ts]"]
end

subgraph group_group_tools["Tools & permissions"]
  node_node_toolreg{{"Tool registry<br/>tool layer<br/>[tools.ts]"}}
  node_node_tools["Agent tools<br/>exec boundary"]
  node_node_perms(("Permissions<br/>approval gate"))
end

subgraph group_group_ui["Terminal UI"]
  node_node_repl["REPL screen<br/>terminal loop<br/>[REPL.tsx]"]
  node_node_commands["Slash commands<br/>command layer<br/>[commands.ts]"]
  node_node_ui["Ink UI<br/>react terminal"]
  node_node_hooks["Hooks<br/>ui logic"]
end

subgraph group_group_services["Services"]
  node_node_compact["Compaction<br/>summarizer"]
  node_node_services_api["API services<br/>anthropic/backend"]
  node_node_auth["Auth storage<br/>oauth + secrets"]
  node_node_persistence["Memory & history<br/>session persistence<br/>[history.ts]"]
  node_node_telemetry["Telemetry<br/>analytics"]
end

subgraph group_group_extensions["Extensions"]
  node_node_plugins["Plugins & skills<br/>extensibility"]
  node_node_mcp["MCP services<br/>protocol integration"]
  node_node_bridge["Bridge & remote<br/>ide/remote bridge"]
  node_node_tasks["Tasks & swarm<br/>multi-agent"]
end

node_node_main -->|"starts"| node_node_entrypoints
node_node_entrypoints -->|"bootstraps"| node_node_appstate
node_node_entrypoints -->|"launches"| node_node_repl
node_node_repl -->|"renders"| node_node_ui
node_node_ui -->|"driven by"| node_node_hooks
node_node_hooks -->|"reads/writes"| node_node_appstate
node_node_commands -->|"mutates"| node_node_appstate
node_node_commands -->|"invoked in"| node_node_repl
node_node_repl -->|"submits turns"| node_node_query
node_node_query -->|"assembles"| node_node_context
node_node_query -->|"compacts"| node_node_compact
node_node_query -->|"calls"| node_node_services_api
node_node_query -->|"dispatches to"| node_node_toolreg
node_node_toolreg -->|"exposes"| node_node_tools
node_node_tools -->|"checks"| node_node_perms
node_node_perms -->|"prompts"| node_node_ui
node_node_tools -->|"uses"| node_node_services_api
node_node_tools -->|"integrates"| node_node_mcp
node_node_tools -->|"spawns"| node_node_tasks
node_node_bridge -->|"syncs"| node_node_repl
node_node_bridge -->|"callbacks"| node_node_perms
node_node_tasks -->|"reports"| node_node_ui
node_node_persistence -->|"hydrates"| node_node_query
node_node_persistence -->|"stores"| node_node_appstate
node_node_plugins -->|"extends"| node_node_commands
node_node_plugins -->|"extends"| node_node_tools
node_node_plugins -->|"configures"| node_node_ui
node_node_telemetry -->|"observes"| node_node_query
node_node_auth -->|"authenticates"| node_node_services_api
node_node_mcp -->|"connects"| node_node_services_api

click node_node_main "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/main.tsx"
click node_node_entrypoints "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/entrypoints"
click node_node_repl "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/screens/REPL.tsx"
click node_node_appstate "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/state"
click node_node_query "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/QueryEngine.ts"
click node_node_context "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/context.ts"
click node_node_compact "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/compact"
click node_node_commands "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/commands.ts"
click node_node_ui "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/components"
click node_node_hooks "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/hooks"
click node_node_toolreg "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/tools.ts"
click node_node_tools "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/tools"
click node_node_perms "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/hooks/toolPermission"
click node_node_services_api "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/api"
click node_node_auth "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/oauth"
click node_node_persistence "https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/history.ts"
click node_node_telemetry "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/analytics"
click node_node_plugins "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/plugins"
click node_node_mcp "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/mcp"
click node_node_bridge "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/bridge"
click node_node_tasks "https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/tasks"

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_node_main,node_node_entrypoints,node_node_appstate,node_node_query,node_node_context toneBlue
class node_node_toolreg,node_node_tools,node_node_perms toneAmber
class node_node_repl,node_node_commands,node_node_ui,node_node_hooks toneMint
class node_node_compact,node_node_services_api,node_node_auth,node_node_persistence,node_node_telemetry toneRose
class node_node_plugins,node_node_mcp,node_node_bridge,node_node_tasks toneIndigo
```

## Components

### Core loop

Startup, REPL UI, session orchestration, and state flow.

- [Entry](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/main.tsx): startup · CLI bootstrap and process handoff. · `src/main.tsx`
- [Entrypoints](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/entrypoints): bootstraps · CLI, init, MCP, and SDK entry wiring. · `src/entrypoints`
- [App state](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/state): state store · Central application state and selectors. · `src/state`
- [Query engine](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/QueryEngine.ts): orchestrator · Builds prompts, streams model turns, and drives tool-call cycles. · `src/QueryEngine.ts`
- [Context build](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/context.ts): prompt context · Assembles conversation, summaries, and token budget context. · `src/context.ts`

### Tools & permissions

Model-invoked execution boundary and approval logic.

- [Tool registry](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/tools.ts): tool layer · Common tool types and registry for model-invoked actions. · `src/tools.ts`
- [Agent tools](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/tools): exec boundary · Shell, file, search, MCP, LSP, task, and remote-trigger tools. · `src/tools`
- [Permissions](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/hooks/toolPermission): approval gate · Auto-approve, deny, or prompt decisions for risky tool use. · `src/hooks/toolPermission`

### Terminal UI

Ink component tree, hooks, dialogs, and command screens.

- [REPL screen](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/screens/REPL.tsx): terminal loop · Interactive terminal session shell and conversation loop. · `src/screens/REPL.tsx`
- [Slash commands](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/commands.ts): command layer · User-facing commands that mutate state or launch flows. · `src/commands.ts`
- [Ink UI](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/components): react terminal · Main component tree, dialogs, prompt input, and messages. · `src/components`
- [Hooks](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/hooks): ui logic · Session, input, notification, and integration hooks. · `src/hooks`

### Services

External integrations, persistence, sync, and telemetry.

- [Compaction](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/compact): summarizer · Conversation compression and post-compact cleanup. · `src/services/compact`
- [API services](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/api): anthropic/backend · Model API, usage, ingest, and backend request clients. · `src/services/api`
- [Auth storage](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/oauth): oauth + secrets · OAuth flows and secure credential storage. · `src/services/oauth`
- [Memory & history](https://github.com/githpriyanshu23/claude-code-leaks/blob/main/src/history.ts): session persistence · Conversation history, memory files, and restore state. · `src/history.ts`
- [Telemetry](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/analytics): analytics · Event logging, tracing, and product analytics. · `src/services/analytics`

### Extensions

Plugins, skills, MCP, bridge, and multi-agent support.

- [Plugins & skills](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/plugins): extensibility · Plugin loading, marketplace, bundled skills, and validations. · `src/plugins`
- [MCP services](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/services/mcp): protocol integration · Model Context Protocol servers, clients, and exposure. · `src/services/mcp`
- [Bridge & remote](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/bridge): ide/remote bridge · IDE bridge, remote session ingress, and transport sync. · `src/bridge`
- [Tasks & swarm](https://github.com/githpriyanshu23/claude-code-leaks/tree/main/src/tasks): multi-agent · Background tasks, subagents, coordination, and teammate flows. · `src/tasks`

## Connections

- Entry → Entrypoints: starts · Process startup delegates into CLI and init entrypoints.
- Entrypoints → App state: bootstraps · Creates initial app/session state.
- Entrypoints → REPL screen: launches · Hands control to the terminal session UI.
- REPL screen → Ink UI: renders · REPL uses the Ink component tree for output and dialogs.
- Ink UI → Hooks: driven by · UI behavior is wired through hooks and local state bindings.
- Hooks → App state: reads/writes · Hooks connect UI interactions to app state.
- Slash commands → App state: mutates · Slash commands update session/configuration state.
- Slash commands → REPL screen: invoked in · Commands are entered from the terminal session.
- REPL screen → Query engine: submits turns · User prompts flow into the orchestration engine.
- Query engine → Context build: assembles · Query engine builds turn context before model calls.
- Query engine → Compaction: compacts · Long sessions are summarized and compressed as needed.
- Query engine → API services: calls · Model requests and backend interactions go through API services.
- Query engine → Tool registry: dispatches to · Model tool calls are resolved through the registry.
- Tool registry → Agent tools: exposes · Registry provides the concrete tool implementations.
- Agent tools → Permissions: checks · High-risk tools are gated by permission decisions.
- Permissions → Ink UI: prompts · Denied or uncertain actions surface approval dialogs in the UI.
- Agent tools → API services: uses · Some tools depend on API-backed services and remote capabilities.
- Agent tools → MCP services: integrates · MCP tools and resource exposure connect through MCP services.
- Agent tools → Tasks & swarm: spawns · Agent and task tools delegate into background or sub-agent work.
- Bridge & remote → REPL screen: syncs · Bridge and remote control share session/UI state with the terminal loop.
- Bridge & remote → Permissions: callbacks · IDE and remote integrations participate in permission decisions.
- Tasks & swarm → Ink UI: reports · Task progress and agent status are rendered in the terminal UI.
- Memory & history → Query engine: hydrates · History and memory feed future turns and restores.
- Memory & history → App state: stores · Session continuity is persisted alongside state.
- Plugins & skills → Slash commands: extends · Plugins add commands and UI surfaces.
- Plugins & skills → Agent tools: extends · Plugins can add or modify tool behavior.
- Plugins & skills → Ink UI: configures · Plugin settings and trust flows surface in the UI.
- Telemetry → Query engine: observes · Orchestration emits telemetry and traces.
- Auth storage → API services: authenticates · OAuth and secret storage support authenticated backend calls.
- MCP services → API services: connects · MCP transport and server management depend on network services.
