# jyotbuch/ctxrelay architecture

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

- Interactive diagram: https://gitdiagram.com/jyotbuch/ctxrelay
- Repository: https://github.com/jyotbuch/ctxrelay

## Overview

ctxrelay preserves coding-agent context across subscription switches through two complementary workflows: durable task-state capture and repository-graph indexing/query. A switch assembles recorded notes, verified work, live Git state, and graph context into a handoff, then checks and launches the destination CLI. The graph also supports MCP and optional natural-language code search. Edges reflect shown calls or README-documented behavior; several CLI and graph details are unsampled, so those relationships are omitted rather than inferred.

Main entry points: [`ctxrelay/cli.py`](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/cli.py) (Command router), [`ctxrelay/handoff.py`](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/handoff.py) (Handoff renderer), [`ctxrelay/mcp_server.py`](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/mcp_server.py) (MCP tools), [`ctxrelay/state.py`](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/state.py) (Task notes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["CLI and setup"]
  node_cli["Command router<br/>[cli.py]"]
  node_terminal["Terminal interface<br/>[ui.py]"]
  node_mcp["MCP tools<br/>[mcp_server.py]"]
end

subgraph group_capture["Task capture"]
  node_state[("Task notes<br/>[state.py]")]
  node_events[("Work events<br/>[events.py]")]
end

subgraph group_graph["Code graph"]
  node_graphindex[("Repository index<br/>[graph.py]")]
  node_colgrep["Code search<br/>[graph.py]"]
end

subgraph group_handoff["Handoff and switching"]
  node_handoff["Handoff renderer<br/>[handoff.py]"]
  node_switch["Switch checks<br/>[switch.py]"]
end

node_user(("Developer"))
node_agent(("Coding agent"))
node_git["Git repository"]
node_destination["Destination CLI"]

node_user -->|"runs commands"| node_cli
node_cli -->|"shows status"| node_terminal
node_cli -->|"records notes"| node_state
node_cli -->|"ingests events"| node_events
node_cli -->|"refreshes index"| node_graphindex
node_cli -->|"writes handoff"| node_handoff
node_cli -->|"checks destination"| node_switch
node_agent -->|"calls tools"| node_mcp
node_mcp -->|"serves graph queries"| node_graphindex
node_mcp -->|"records notes"| node_state
node_mcp -->|"renders handoff"| node_handoff
node_handoff -->|"loads notes"| node_state
node_handoff -->|"summarizes work"| node_events
node_handoff -->|"reads code map"| node_graphindex
node_handoff -->|"reads repository state"| node_git
node_switch -->|"checks and launches"| node_destination
node_cli -->|"launches switch"| node_destination
node_colgrep -.->|"finds code by description"| node_agent

click node_cli "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/cli.py"
click node_terminal "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/ui.py"
click node_mcp "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/mcp_server.py"
click node_state "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/state.py"
click node_events "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/events.py"
click node_graphindex "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/graph.py"
click node_colgrep "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/graph.py"
click node_handoff "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/handoff.py"
click node_switch "https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/switch.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_terminal,node_mcp toneBlue
class node_state,node_events toneAmber
class node_graphindex,node_colgrep toneMint
class node_handoff,node_switch toneRose
class node_user,node_agent,node_git,node_destination toneIndigo
```

## Components

### CLI and setup

- [Command router](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/cli.py): `ctxrelay/cli.py`
- [Terminal interface](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/ui.py): `ctxrelay/ui.py`
- [MCP tools](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/mcp_server.py): `ctxrelay/mcp_server.py`

### Task capture

- [Task notes](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/state.py): `ctxrelay/state.py`
- [Work events](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/events.py): `ctxrelay/events.py`

### Code graph

- [Repository index](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/graph.py): `ctxrelay/graph.py`
- [Code search](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/graph.py): `ctxrelay/graph.py`

### Handoff and switching

- [Handoff renderer](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/handoff.py): `ctxrelay/handoff.py`
- [Switch checks](https://github.com/jyotbuch/ctxrelay/blob/main/ctxrelay/switch.py): `ctxrelay/switch.py`

### Other components

- **Developer**
- **Coding agent**
- **Git repository**
- **Destination CLI**

## Connections

- Developer → Command router: runs commands (evidence: `README.md`)
- Command router → Terminal interface: shows status (evidence: `ctxrelay/cli.py`)
- Command router → Task notes: records notes (evidence: `ctxrelay/cli.py`)
- Command router → Work events: ingests events (evidence: `ctxrelay/cli.py`)
- Command router → Repository index: refreshes index (evidence: `ctxrelay/cli.py`)
- Command router → Handoff renderer: writes handoff (evidence: `ctxrelay/cli.py`)
- Command router → Switch checks: checks destination (evidence: `ctxrelay/cli.py`)
- Coding agent → MCP tools: calls tools (evidence: `README.md`)
- MCP tools → Repository index: serves graph queries (evidence: `ctxrelay/mcp_server.py`)
- MCP tools → Task notes: records notes (evidence: `ctxrelay/mcp_server.py`)
- MCP tools → Handoff renderer: renders handoff (evidence: `ctxrelay/mcp_server.py`)
- Handoff renderer → Task notes: loads notes (evidence: `ctxrelay/handoff.py`)
- Handoff renderer → Work events: summarizes work (evidence: `ctxrelay/handoff.py`)
- Handoff renderer → Repository index: reads code map (evidence: `ctxrelay/handoff.py`)
- Handoff renderer → Git repository: reads repository state (evidence: `ctxrelay/handoff.py`)
- Switch checks → Destination CLI: checks and launches (evidence: `ctxrelay/switch.py`)
- Command router → Destination CLI: launches switch (evidence: `README.md`)
- Code search → Coding agent: finds code by description (evidence: `README.md`)
