# codewhale-hq/codewhale architecture

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

- Interactive diagram: https://gitdiagram.com/codewhale-hq/codewhale
- Repository: https://github.com/codewhale-hq/codewhale

## Overview

Codewhale is a local-first coding agent: a user submits a task through the terminal or a headless client, the shared Engine coordinates a model-backed turn and available tools, and the agent can inspect or change the project and check its work. Major supporting capabilities include provider/configuration routing, permissions, durable background work, sub-agents and fleets, extensibility, and a local Runtime API. README statements establish the client-to-Engine workflow; source-index references and excerpts identify internal modules, but unsampled call paths are not inferred.

Main entry points: [`crates/tui/src/core/engine.rs`](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/engine.rs) (Turn engine), [`crates/tui/src/tui/app.rs`](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tui/app.rs) (Terminal client), [`crates/cli/src/main.rs`](https://github.com/codewhale-hq/codewhale/blob/main/crates/cli/src/main.rs) (Headless CLI), [`crates/tui/src/runtime_api.rs`](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/runtime_api.rs) (Runtime API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User interfaces"]
  node_terminal["Terminal client<br/>[app.rs]"]
  node_cli["Headless CLI<br/>[main.rs]"]
  node_api["Runtime API<br/>[runtime_api.rs]"]
end

subgraph group_engine["Agent runtime"]
  node_engine_core["Turn engine<br/>[engine.rs]"]
  node_authority["Tool authority<br/>[authority.rs]"]
  node_catalog["Tool catalog<br/>[tool_catalog.rs]"]
  node_tool_specs["Tool contracts<br/>[spec.rs]"]
  node_shell["Shell execution<br/>[shell.rs]"]
  node_config["Configuration<br/>[config.rs]"]
  node_provider["Model clients<br/>[client.rs]"]
  node_sessions[("Session state<br/>[session_manager.rs]")]
end

subgraph group_work["Work coordination"]
  node_tasks[("Background tasks<br/>[task_manager.rs]")]
  node_subagents["Sub-agents<br/>[engine.rs]"]
  node_fleet["Agent fleets<br/>[manager.rs]"]
  node_workflow["Workflows"]
end

subgraph group_extend["Integrations"]
  node_plugins["Plugins and skills<br/>[activation.rs]"]
  node_mcp["MCP servers<br/>[mcp.rs]"]
  node_hooks["Lifecycle hooks<br/>[lib.rs]"]
end

node_user(("Developer"))

node_user -->|"submits task"| node_terminal
node_user -->|"runs task"| node_cli
node_user -->|"uses API"| node_api
node_terminal -->|"drives"| node_engine_core
node_cli -->|"drives"| node_engine_core
node_api -->|"uses shared engine"| node_engine_core

click node_terminal "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tui/app.rs"
click node_cli "https://github.com/codewhale-hq/codewhale/blob/main/crates/cli/src/main.rs"
click node_api "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/runtime_api.rs"
click node_engine_core "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/engine.rs"
click node_authority "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/authority.rs"
click node_catalog "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/engine/tool_catalog.rs"
click node_tool_specs "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/spec.rs"
click node_shell "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/shell.rs"
click node_config "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/config.rs"
click node_provider "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/client.rs"
click node_sessions "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/session_manager.rs"
click node_tasks "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/task_manager.rs"
click node_subagents "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/subagent/engine.rs"
click node_fleet "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/fleet/manager.rs"
click node_workflow "https://github.com/codewhale-hq/codewhale/blob/main/crates/workflow/src/reasoning_router.rs"
click node_plugins "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/plugins/activation.rs"
click node_mcp "https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/mcp.rs"
click node_hooks "https://github.com/codewhale-hq/codewhale/blob/main/crates/hooks/src/lib.rs"

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_terminal,node_cli,node_api toneBlue
class node_engine_core,node_authority,node_catalog,node_tool_specs,node_shell,node_config,node_provider,node_sessions toneAmber
class node_tasks,node_subagents,node_fleet,node_workflow toneMint
class node_plugins,node_mcp,node_hooks toneRose
class node_user toneIndigo
```

## Components

### User interfaces

- [Terminal client](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tui/app.rs): `crates/tui/src/tui/app.rs`
- [Headless CLI](https://github.com/codewhale-hq/codewhale/blob/main/crates/cli/src/main.rs): `crates/cli/src/main.rs`
- [Runtime API](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/runtime_api.rs): `crates/tui/src/runtime_api.rs`

### Agent runtime

- [Turn engine](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/engine.rs): `crates/tui/src/core/engine.rs`
- [Tool authority](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/authority.rs): `crates/tui/src/core/authority.rs`
- [Tool catalog](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/core/engine/tool_catalog.rs): `crates/tui/src/core/engine/tool_catalog.rs`
- [Tool contracts](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/spec.rs): `crates/tui/src/tools/spec.rs`
- [Shell execution](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/shell.rs): `crates/tui/src/tools/shell.rs`
- [Configuration](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/config.rs): `crates/tui/src/config.rs`
- [Model clients](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/client.rs): `crates/tui/src/client.rs`
- [Session state](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/session_manager.rs): `crates/tui/src/session_manager.rs`

### Work coordination

- [Background tasks](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/task_manager.rs): `crates/tui/src/task_manager.rs`
- [Sub-agents](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/tools/subagent/engine.rs): `crates/tui/src/tools/subagent/engine.rs`
- [Agent fleets](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/fleet/manager.rs): `crates/tui/src/fleet/manager.rs`
- [Workflows](https://github.com/codewhale-hq/codewhale/blob/main/crates/workflow/src/reasoning_router.rs): `crates/workflow/src/reasoning_router.rs`

### Integrations

- [Plugins and skills](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/plugins/activation.rs): `crates/tui/src/plugins/activation.rs`
- [MCP servers](https://github.com/codewhale-hq/codewhale/blob/main/crates/tui/src/mcp.rs): `crates/tui/src/mcp.rs`
- [Lifecycle hooks](https://github.com/codewhale-hq/codewhale/blob/main/crates/hooks/src/lib.rs): `crates/hooks/src/lib.rs`

### Other components

- **Developer**

## Connections

- Developer → Terminal client: submits task (evidence: `README.md`)
- Developer → Headless CLI: runs task (evidence: `README.md`)
- Developer → Runtime API: uses API (evidence: `README.md`)
- Terminal client → Turn engine: drives (evidence: `README.md`)
- Headless CLI → Turn engine: drives (evidence: `README.md`)
- Runtime API → Turn engine: uses shared engine (evidence: `README.md`)
