How githpriyanshu23/claude-code-leaks works
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: QueryEngine.ts Query engine · tools Agent tools · REPL.tsx REPL screen · components Ink UI
Components 21
Core loop
Startup, REPL UI, session orchestration, and state flow.
- Entry · CLI bootstrap and process handoff.
src/main.tsx - Entrypoints · CLI, init, MCP, and SDK entry wiring.
src/entrypoints - App state · Central application state and selectors.
src/state - Query engine · Builds prompts, streams model turns, and drives tool-call cycles.
src/QueryEngine.ts - Context build · Assembles conversation, summaries, and token budget context.
src/context.ts
Tools & permissions
Model-invoked execution boundary and approval logic.
- Tool registry · Common tool types and registry for model-invoked actions.
src/tools.ts - Agent tools · Shell, file, search, MCP, LSP, task, and remote-trigger tools.
src/tools - Permissions · 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 · Interactive terminal session shell and conversation loop.
src/screens/REPL.tsx - Slash commands · User-facing commands that mutate state or launch flows.
src/commands.ts - Ink UI · Main component tree, dialogs, prompt input, and messages.
src/components - Hooks · Session, input, notification, and integration hooks.
src/hooks
Services
External integrations, persistence, sync, and telemetry.
- Compaction · Conversation compression and post-compact cleanup.
src/services/compact - API services · Model API, usage, ingest, and backend request clients.
src/services/api - Auth storage · OAuth flows and secure credential storage.
src/services/oauth - Memory & history · Conversation history, memory files, and restore state.
src/history.ts - Telemetry · Event logging, tracing, and product analytics.
src/services/analytics
Extensions
Plugins, skills, MCP, bridge, and multi-agent support.
- Plugins & skills · Plugin loading, marketplace, bundled skills, and validations.
src/plugins - MCP services · Model Context Protocol servers, clients, and exposure.
src/services/mcp - Bridge & remote · IDE bridge, remote session ingress, and transport sync.
src/bridge - Tasks & swarm · Background tasks, subagents, coordination, and teammate flows.
src/tasks
Connections 30
- 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.