# fendouai/codexsaver architecture

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

- Interactive diagram: https://gitdiagram.com/fendouai/codexsaver
- Repository: https://github.com/fendouai/codexsaver

## Overview

CodexSaver is an MCP tool, also exposed through a CLI, that routes Codex work to lower-cost workers when the task is safe and bounded. Its main workflow is risk-based routing, then either specialist orchestration or a bounded work packet whose changes are sandboxed and verified before Codex reviews them. The README also documents worker discovery, provider configuration, and output compression. Some internal connections are supported only by the README or source index; unsampled implementation details are not inferred.

Main entry points: [`codexsaver/orchestrator.py`](https://github.com/fendouai/codexsaver/blob/main/codexsaver/orchestrator.py) (Specialist orchestration), [`codexsaver/engine.py`](https://github.com/fendouai/codexsaver/blob/main/codexsaver/engine.py) (Delegation engine), [`codexsaver/work_packet.py`](https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_packet.py) (Work packet runtime), [`codexsaver/work_graph.py`](https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_graph.py) (Work graph)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Product entry"]
  node_mcp["MCP tools<br/>[codexsaver_mcp.py]"]
  node_cli["CLI<br/>[cli.py]"]
  node_engine["Delegation engine<br/>[engine.py]"]
end

subgraph group_routing["Routing and policy"]
  node_router["Risk router<br/>[router.py]"]
  node_policy["Action policy<br/>[policy.py]"]
  node_workgraph["Work graph<br/>[work_graph.py]"]
end

subgraph group_execution["Worker execution"]
  node_orchestrator["Specialist orchestration<br/>[orchestrator.py]"]
  node_specialists["Specialist profiles<br/>[specialists.py]"]
  node_aggregator["Patch aggregation<br/>[aggregator.py]"]
  node_packet["Work packet runtime<br/>[work_packet.py]"]
  node_context["Context packing<br/>[context.py]"]
end

subgraph group_safety["Verification and handoff"]
  node_verifier["Patch verifier<br/>[verifier.py]"]
  node_ledger[("Task ledger<br/>[ledger.py]")]
end

subgraph group_support["Configuration and workers"]
  node_registry["Agent discovery<br/>[agent_registry.py]"]
  node_agentrouter["Worker selection<br/>[agent_router.py]"]
  node_piagent["Pi Agent client<br/>[pi_agent.py]"]
  node_provider["LLM provider client<br/>[provider.py]"]
  node_config["Provider config<br/>[config.py]"]
  node_schema["Runtime schemas<br/>[schema.py]"]
end

node_codex(("Codex"))
node_worker(("Worker agents"))
node_llm(("LLM provider service"))

node_codex -->|"invokes tools"| node_mcp
node_codex -->|"runs commands"| node_cli
node_mcp -->|"dispatches requests"| node_engine
node_cli -->|"dispatches requests"| node_engine
node_engine -->|"checks risk"| node_router
node_engine -->|"runs bounded work"| node_packet
node_engine -->|"starts orchestration"| node_orchestrator
node_orchestrator -->|"plans work graph"| node_workgraph
node_workgraph -->|"applies risk policy"| node_policy
node_orchestrator -->|"uses profiles"| node_specialists
node_orchestrator -->|"aggregates patches"| node_aggregator
node_orchestrator -->|"runs patch nodes"| node_packet
node_packet -->|"loads file context"| node_context
node_packet -->|"requests worker output"| node_provider
node_packet -->|"verifies changes"| node_verifier
node_orchestrator -->|"checks patch results"| node_verifier
node_verifier -->|"hands off for review"| node_codex
node_orchestrator -->|"discovers workers"| node_registry
node_orchestrator -->|"selects workers"| node_agentrouter
node_orchestrator -->|"dispatches to Pi"| node_piagent
node_piagent -->|"runs agent command"| node_worker
node_provider -->|"sends completions"| node_llm
node_provider -->|"resolves settings"| node_config
node_engine -->|"loads provider settings"| node_config
node_engine -->|"packs task context"| node_context
node_engine -->|"uses request models"| node_schema
node_orchestrator -->|"uses work models"| node_schema
node_workgraph -->|"uses graph models"| node_schema
node_engine -.-> node_ledger

click node_mcp "https://github.com/fendouai/codexsaver/blob/main/codexsaver_mcp.py"
click node_cli "https://github.com/fendouai/codexsaver/blob/main/cli.py"
click node_engine "https://github.com/fendouai/codexsaver/blob/main/codexsaver/engine.py"
click node_router "https://github.com/fendouai/codexsaver/blob/main/codexsaver/router.py"
click node_policy "https://github.com/fendouai/codexsaver/blob/main/codexsaver/policy.py"
click node_workgraph "https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_graph.py"
click node_orchestrator "https://github.com/fendouai/codexsaver/blob/main/codexsaver/orchestrator.py"
click node_specialists "https://github.com/fendouai/codexsaver/blob/main/codexsaver/specialists.py"
click node_aggregator "https://github.com/fendouai/codexsaver/blob/main/codexsaver/aggregator.py"
click node_packet "https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_packet.py"
click node_context "https://github.com/fendouai/codexsaver/blob/main/codexsaver/context.py"
click node_verifier "https://github.com/fendouai/codexsaver/blob/main/codexsaver/verifier.py"
click node_ledger "https://github.com/fendouai/codexsaver/blob/main/codexsaver/ledger.py"
click node_registry "https://github.com/fendouai/codexsaver/blob/main/codexsaver/agent_registry.py"
click node_agentrouter "https://github.com/fendouai/codexsaver/blob/main/codexsaver/agent_router.py"
click node_piagent "https://github.com/fendouai/codexsaver/blob/main/codexsaver/pi_agent.py"
click node_provider "https://github.com/fendouai/codexsaver/blob/main/codexsaver/provider.py"
click node_config "https://github.com/fendouai/codexsaver/blob/main/codexsaver/config.py"
click node_schema "https://github.com/fendouai/codexsaver/blob/main/codexsaver/schema.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_mcp,node_cli,node_engine toneBlue
class node_router,node_policy,node_workgraph toneAmber
class node_orchestrator,node_specialists,node_aggregator,node_packet,node_context toneMint
class node_verifier,node_ledger,node_worker toneRose
class node_registry,node_agentrouter,node_piagent,node_provider,node_config,node_schema,node_codex,node_llm toneIndigo
```

## Components

### Product entry

- [MCP tools](https://github.com/fendouai/codexsaver/blob/main/codexsaver_mcp.py): `codexsaver_mcp.py`
- [CLI](https://github.com/fendouai/codexsaver/blob/main/cli.py): `cli.py`
- [Delegation engine](https://github.com/fendouai/codexsaver/blob/main/codexsaver/engine.py): `codexsaver/engine.py`

### Routing and policy

- [Risk router](https://github.com/fendouai/codexsaver/blob/main/codexsaver/router.py): `codexsaver/router.py`
- [Action policy](https://github.com/fendouai/codexsaver/blob/main/codexsaver/policy.py): `codexsaver/policy.py`
- [Work graph](https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_graph.py): `codexsaver/work_graph.py`

### Worker execution

- [Specialist orchestration](https://github.com/fendouai/codexsaver/blob/main/codexsaver/orchestrator.py): `codexsaver/orchestrator.py`
- [Specialist profiles](https://github.com/fendouai/codexsaver/blob/main/codexsaver/specialists.py): `codexsaver/specialists.py`
- [Patch aggregation](https://github.com/fendouai/codexsaver/blob/main/codexsaver/aggregator.py): `codexsaver/aggregator.py`
- [Work packet runtime](https://github.com/fendouai/codexsaver/blob/main/codexsaver/work_packet.py): `codexsaver/work_packet.py`
- [Context packing](https://github.com/fendouai/codexsaver/blob/main/codexsaver/context.py): `codexsaver/context.py`

### Verification and handoff

- [Patch verifier](https://github.com/fendouai/codexsaver/blob/main/codexsaver/verifier.py): `codexsaver/verifier.py`
- [Task ledger](https://github.com/fendouai/codexsaver/blob/main/codexsaver/ledger.py): `codexsaver/ledger.py`

### Configuration and workers

- [Agent discovery](https://github.com/fendouai/codexsaver/blob/main/codexsaver/agent_registry.py): `codexsaver/agent_registry.py`
- [Worker selection](https://github.com/fendouai/codexsaver/blob/main/codexsaver/agent_router.py): `codexsaver/agent_router.py`
- [Pi Agent client](https://github.com/fendouai/codexsaver/blob/main/codexsaver/pi_agent.py): `codexsaver/pi_agent.py`
- [LLM provider client](https://github.com/fendouai/codexsaver/blob/main/codexsaver/provider.py): `codexsaver/provider.py`
- [Provider config](https://github.com/fendouai/codexsaver/blob/main/codexsaver/config.py): `codexsaver/config.py`
- [Runtime schemas](https://github.com/fendouai/codexsaver/blob/main/codexsaver/schema.py): `codexsaver/schema.py`

### Other components

- **Codex**
- **Worker agents**
- **LLM provider service**

## Connections

- Codex → MCP tools: invokes tools (evidence: `README.md`)
- Codex → CLI: runs commands (evidence: `README.md`)
- MCP tools → Delegation engine: dispatches requests (evidence: `codexsaver_mcp.py`)
- CLI → Delegation engine: dispatches requests (evidence: `cli.py`)
- Delegation engine → Risk router: checks risk (evidence: `README.md`)
- Delegation engine → Work packet runtime: runs bounded work (evidence: `README.md`)
- Delegation engine → Specialist orchestration: starts orchestration (evidence: `README.md`)
- Specialist orchestration → Work graph: plans work graph (evidence: `README.md`)
- Work graph → Action policy: applies risk policy (evidence: `codexsaver/work_graph.py`)
- Specialist orchestration → Specialist profiles: uses profiles (evidence: `codexsaver/orchestrator.py`)
- Specialist orchestration → Patch aggregation: aggregates patches (evidence: `README.md`)
- Specialist orchestration → Work packet runtime: runs patch nodes (evidence: `README.md`)
- Work packet runtime → Context packing: loads file context (evidence: `codexsaver/work_packet.py`)
- Work packet runtime → LLM provider client: requests worker output (evidence: `codexsaver/work_packet.py`)
- Work packet runtime → Patch verifier: verifies changes (evidence: `README.md`)
- Specialist orchestration → Patch verifier: checks patch results (evidence: `README.md`)
- Patch verifier → Codex: hands off for review (evidence: `README.md`)
- Specialist orchestration → Agent discovery: discovers workers (evidence: `README.md`)
- Specialist orchestration → Worker selection: selects workers (evidence: `README.md`)
- Specialist orchestration → Pi Agent client: dispatches to Pi (evidence: `README.md`)
- Pi Agent client → Worker agents: runs agent command (evidence: `codexsaver/pi_agent.py`)
- LLM provider client → LLM provider service: sends completions (evidence: `codexsaver/provider.py`)
- LLM provider client → Provider config: resolves settings (evidence: `codexsaver/provider.py`)
- Delegation engine → Provider config: loads provider settings (evidence: `codexsaver/engine.py`)
- Delegation engine → Context packing: packs task context (evidence: `codexsaver/engine.py`)
- Delegation engine → Runtime schemas: uses request models (evidence: `codexsaver/engine.py`)
- Specialist orchestration → Runtime schemas: uses work models (evidence: `codexsaver/orchestrator.py`)
- Work graph → Runtime schemas: uses graph models (evidence: `codexsaver/work_graph.py`)
- Delegation engine → Task ledger
