# he-yufeng/corecoder architecture

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

- Interactive diagram: https://gitdiagram.com/he-yufeng/corecoder
- Repository: https://github.com/he-yufeng/corecoder

## Overview

CoreCoder is a small, runnable coding-agent engine intended as a readable foundation for building agents. Its main workflow is terminal input through the CLI into the agent loop, which requests model responses and dispatches tool calls until it can return a reply. The graph also preserves documented capabilities such as sub-agents, context compression, consent, undo, sessions, hooks, and MCP. Edges use the excerpts, source-index references, or README; some subsystem wiring is not shown in detail.

Main entry points: [`corecoder/agent.py`](https://github.com/he-yufeng/corecoder/blob/main/corecoder/agent.py) (Agent loop), [`corecoder/cli.py`](https://github.com/he-yufeng/corecoder/blob/main/corecoder/cli.py) (CLI and REPL), [`corecoder/tools/agent.py`](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/agent.py) (Sub-agents), [`corecoder/mcp.py`](https://github.com/he-yufeng/corecoder/blob/main/corecoder/mcp.py) (MCP tools and resources)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Terminal interface"]
  node_cli["CLI and REPL<br/>[cli.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_engine["Agent engine"]
  node_agent["Agent loop<br/>[agent.py]"]
  node_prompt["System prompt<br/>[prompt.py]"]
  node_context["Context compression<br/>[context.py]"]
end

subgraph group_tools["Agent tools"]
  node_tool_registry["Tool registry<br/>[__init__.py]"]
  node_tool_base["Tool interface<br/>[base.py]"]
  node_file_read["Read files<br/>[read.py]"]
  node_file_write["Write files<br/>[write.py]"]
  node_file_edit["Edit files<br/>[edit.py]"]
  node_file_search["Find files and text<br/>[glob_tool.py]"]
  node_text_search["Search text<br/>[grep.py]"]
  node_bash["Shell commands<br/>[bash.py]"]
  node_shell["Shell runner<br/>[shell.py]"]
  node_todo["Task checklist<br/>[todo.py]"]
  node_subagents["Sub-agents<br/>[agent.py]"]
end

subgraph group_state["Safety and state"]
  node_permissions["Tool consent<br/>[permissions.py]"]
  node_hooks["Tool hooks<br/>[hooks.py]"]
  node_checkpoints[("Undo checkpoints<br/>[checkpoints.py]")]
  node_sessions[("Saved sessions<br/>[session.py]")]
end

subgraph group_integrations["Model and MCP"]
  node_llm["LLM client<br/>[llm.py]"]
  node_mcp["MCP tools and resources<br/>[mcp.py]"]
  node_mcp_http["MCP HTTP transport<br/>[mcp_http.py]"]
end

node_user(("User"))
node_model_service{{"OpenAI-compatible model API"}}
node_mcp_server{{"MCP servers"}}

node_user -->|"enters prompt"| node_cli
node_cli -->|"starts and prompts"| node_agent
node_cli -->|"loads settings"| node_config
node_cli -->|"loads and saves"| node_sessions
node_cli -->|"configures consent"| node_permissions
node_cli -->|"configures hooks"| node_hooks
node_cli -->|"handles undo"| node_checkpoints
node_cli -->|"loads MCP tools"| node_mcp
node_agent -->|"requests responses"| node_llm
node_llm -->|"sends model requests"| node_model_service
node_agent -->|"compresses history"| node_context
node_agent -->|"builds system prompt"| node_prompt
node_agent -->|"uses registered tools"| node_tool_registry
node_tool_registry -->|"implements interface"| node_tool_base
node_agent -->|"checks tool consent"| node_permissions
node_agent -->|"runs tool hooks"| node_hooks
node_agent -->|"dispatches calls"| node_file_read
node_agent -->|"dispatches calls"| node_file_write
node_agent -->|"dispatches calls"| node_file_edit
node_agent -->|"dispatches calls"| node_file_search
node_agent -->|"dispatches calls"| node_text_search
node_agent -->|"dispatches calls"| node_bash
node_agent -->|"dispatches calls"| node_todo
node_agent -->|"dispatches calls"| node_subagents
node_bash -->|"runs commands"| node_shell
node_file_edit -->|"records edits"| node_checkpoints
node_file_write -->|"records writes"| node_checkpoints
node_subagents -->|"creates workers"| node_agent
node_subagents -->|"tracks working directory"| node_bash
node_subagents -->|"isolates checklists"| node_todo
node_mcp -->|"uses HTTP transport"| node_mcp_http
node_mcp -->|"connects to servers"| node_mcp_server

click node_cli "https://github.com/he-yufeng/corecoder/blob/main/corecoder/cli.py"
click node_agent "https://github.com/he-yufeng/corecoder/blob/main/corecoder/agent.py"
click node_prompt "https://github.com/he-yufeng/corecoder/blob/main/corecoder/prompt.py"
click node_context "https://github.com/he-yufeng/corecoder/blob/main/corecoder/context.py"
click node_llm "https://github.com/he-yufeng/corecoder/blob/main/corecoder/llm.py"
click node_tool_registry "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/__init__.py"
click node_tool_base "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/base.py"
click node_file_read "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/read.py"
click node_file_write "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/write.py"
click node_file_edit "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/edit.py"
click node_file_search "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/glob_tool.py"
click node_text_search "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/grep.py"
click node_bash "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/bash.py"
click node_shell "https://github.com/he-yufeng/corecoder/blob/main/corecoder/shell.py"
click node_todo "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/todo.py"
click node_subagents "https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/agent.py"
click node_permissions "https://github.com/he-yufeng/corecoder/blob/main/corecoder/permissions.py"
click node_hooks "https://github.com/he-yufeng/corecoder/blob/main/corecoder/hooks.py"
click node_checkpoints "https://github.com/he-yufeng/corecoder/blob/main/corecoder/checkpoints.py"
click node_sessions "https://github.com/he-yufeng/corecoder/blob/main/corecoder/session.py"
click node_config "https://github.com/he-yufeng/corecoder/blob/main/corecoder/config.py"
click node_mcp "https://github.com/he-yufeng/corecoder/blob/main/corecoder/mcp.py"
click node_mcp_http "https://github.com/he-yufeng/corecoder/blob/main/corecoder/mcp_http.py"

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_cli,node_config,node_user toneBlue
class node_agent,node_prompt,node_context toneAmber
class node_tool_registry,node_tool_base,node_file_read,node_file_write,node_file_edit,node_file_search,node_text_search,node_bash,node_shell,node_todo,node_subagents,node_model_service,node_mcp_server toneMint
class node_permissions,node_hooks,node_checkpoints,node_sessions toneRose
class node_llm,node_mcp,node_mcp_http toneIndigo
```

## Components

### Terminal interface

- [CLI and REPL](https://github.com/he-yufeng/corecoder/blob/main/corecoder/cli.py): `corecoder/cli.py`
- [Runtime configuration](https://github.com/he-yufeng/corecoder/blob/main/corecoder/config.py): `corecoder/config.py`

### Agent engine

- [Agent loop](https://github.com/he-yufeng/corecoder/blob/main/corecoder/agent.py): `corecoder/agent.py`
- [System prompt](https://github.com/he-yufeng/corecoder/blob/main/corecoder/prompt.py): `corecoder/prompt.py`
- [Context compression](https://github.com/he-yufeng/corecoder/blob/main/corecoder/context.py): `corecoder/context.py`

### Agent tools

- [Tool registry](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/__init__.py): `corecoder/tools/__init__.py`
- [Tool interface](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/base.py): `corecoder/tools/base.py`
- [Read files](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/read.py): `corecoder/tools/read.py`
- [Write files](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/write.py): `corecoder/tools/write.py`
- [Edit files](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/edit.py): `corecoder/tools/edit.py`
- [Find files and text](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/glob_tool.py): `corecoder/tools/glob_tool.py`
- [Search text](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/grep.py): `corecoder/tools/grep.py`
- [Shell commands](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/bash.py): `corecoder/tools/bash.py`
- [Shell runner](https://github.com/he-yufeng/corecoder/blob/main/corecoder/shell.py): `corecoder/shell.py`
- [Task checklist](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/todo.py): `corecoder/tools/todo.py`
- [Sub-agents](https://github.com/he-yufeng/corecoder/blob/main/corecoder/tools/agent.py): `corecoder/tools/agent.py`

### Safety and state

- [Tool consent](https://github.com/he-yufeng/corecoder/blob/main/corecoder/permissions.py): `corecoder/permissions.py`
- [Tool hooks](https://github.com/he-yufeng/corecoder/blob/main/corecoder/hooks.py): `corecoder/hooks.py`
- [Undo checkpoints](https://github.com/he-yufeng/corecoder/blob/main/corecoder/checkpoints.py): `corecoder/checkpoints.py`
- [Saved sessions](https://github.com/he-yufeng/corecoder/blob/main/corecoder/session.py): `corecoder/session.py`

### Model and MCP

- [LLM client](https://github.com/he-yufeng/corecoder/blob/main/corecoder/llm.py): `corecoder/llm.py`
- [MCP tools and resources](https://github.com/he-yufeng/corecoder/blob/main/corecoder/mcp.py): `corecoder/mcp.py`
- [MCP HTTP transport](https://github.com/he-yufeng/corecoder/blob/main/corecoder/mcp_http.py): `corecoder/mcp_http.py`

### Other components

- **User**
- **OpenAI-compatible model API**
- **MCP servers**

## Connections

- User → CLI and REPL: enters prompt (evidence: `README.md`)
- CLI and REPL → Agent loop: starts and prompts (evidence: `corecoder/cli.py`)
- CLI and REPL → Runtime configuration: loads settings (evidence: `corecoder/cli.py`)
- CLI and REPL → Saved sessions: loads and saves (evidence: `corecoder/cli.py`)
- CLI and REPL → Tool consent: configures consent (evidence: `corecoder/cli.py`)
- CLI and REPL → Tool hooks: configures hooks (evidence: `corecoder/cli.py`)
- CLI and REPL → Undo checkpoints: handles undo (evidence: `corecoder/cli.py`)
- CLI and REPL → MCP tools and resources: loads MCP tools (evidence: `corecoder/cli.py`)
- Agent loop → LLM client: requests responses (evidence: `corecoder/agent.py`)
- LLM client → OpenAI-compatible model API: sends model requests (evidence: `README.md`)
- Agent loop → Context compression: compresses history (evidence: `corecoder/agent.py`)
- Agent loop → System prompt: builds system prompt (evidence: `corecoder/agent.py`)
- Agent loop → Tool registry: uses registered tools (evidence: `corecoder/agent.py`)
- Tool registry → Tool interface: implements interface (evidence: `corecoder/tools/__init__.py`)
- Agent loop → Tool consent: checks tool consent (evidence: `corecoder/agent.py`)
- Agent loop → Tool hooks: runs tool hooks (evidence: `corecoder/agent.py`)
- Agent loop → Read files: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Write files: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Edit files: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Find files and text: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Search text: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Shell commands: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Task checklist: dispatches calls (evidence: `corecoder/agent.py`)
- Agent loop → Sub-agents: dispatches calls (evidence: `corecoder/agent.py`)
- Shell commands → Shell runner: runs commands (evidence: `corecoder/tools/bash.py`)
- Edit files → Undo checkpoints: records edits (evidence: `corecoder/tools/edit.py`)
- Write files → Undo checkpoints: records writes (evidence: `corecoder/tools/write.py`)
- Sub-agents → Agent loop: creates workers (evidence: `corecoder/tools/agent.py`)
- Sub-agents → Shell commands: tracks working directory (evidence: `corecoder/tools/agent.py`)
- Sub-agents → Task checklist: isolates checklists (evidence: `corecoder/tools/agent.py`)
- MCP tools and resources → MCP HTTP transport: uses HTTP transport (evidence: `corecoder/mcp.py`)
- MCP tools and resources → MCP servers: connects to servers (evidence: `corecoder/mcp.py`)
