Architecture
Agent Relay has three cooperating pieces:
- Interactive REPL: the no-args
relayshell that owns live agent processes, slash commands, handoffs, and session context. - Repo-local store:
.agent-relay/, where turns, checkpoints, metrics, and resume packets are written for the current project. - Always-on daemon:
~/.relay/, where adapter events, snapshots, daemon config, and the IPC socket live.
Primary flow
The REPL keeps a long-lived RelayContext. Bare text goes to the active
agent. Slash commands such as /status, /metrics, /race, and /use codex
dispatch through the same command logic as the scriptable CLI.
When there is live context and the user switches agents, Relay prepares a handoff packet from the active session and starts the target agent with that context. Automatic rate-limit handoff uses the same path.
Storage roots
| Root | Scope | What lives there |
|---|---|---|
<repo>/.agent-relay/ | Per repository | Sessions, turns, checkpoints, resume packets, metrics artifacts, race/conflict artifacts. |
~/.config/relay/ | Per user | REPL config, prompt history, logs, pidfiles for orphan recovery. |
~/.relay/ | Per user | Daemon config, adapter event logs, snapshots, IPC socket, proxy state. |
The REPL writes project work to .agent-relay/. The daemon writes machine-wide
events and snapshots to ~/.relay/. They meet through the daemon IPC stream
and handoff/resume translation.
REPL process model
relay with no subcommand enters the interactive shell:
- First-run onboarding detects agents and writes
~/.config/relay/config.toml. AgentRouterowns live agent sessions.- Bare prompts are written to the active agent.
- Output is streamed, ANSI-sanitized, displayed, and persisted as turn artifacts.
- Older saved context can be auto-compacted after turns.
/use <agent>routes through handoff when there is active context.- The REPL subscribes to daemon handoff notifications when the daemon socket is available.
Daemon and adapters
Current shipped capture paths:
- Claude Code
Notificationhook installed byrelay install. - Codex
Stophook installed byrelay install. - Gemini CLI
Notificationhook installed byrelay install. - OpenCode event plugin installed by
relay install. relay wrap <command>for generic CLI agents on POSIX.- Optional
relay proxyfor provider response-header signals. relay mcp servefor MCP-aware clients;relay install --warpwrites a Warp MCP snippet but does not silently edit Warp settings.
Some detected products are future adapter phases. Detection alone does not mean Relay has installed a capture integration for that product.
Proxy mode opt-in
Proxy mode is off by default. When explicitly enabled, it can observe provider
rate-limit response headers such as anthropic-ratelimit-* and x-ratelimit-*
and emit rate_limited or early-warning events. It requires the proxy extra
and local certificate trust setup.
Where to look in the code
| Concern | Module |
|---|---|
| Root CLI and REPL entry | src/agent_relay/cli.py |
| REPL shell and handoff listener | src/agent_relay/repl/shell.py |
| Agent process routing | src/agent_relay/repl/agent_router.py |
| User config | src/agent_relay/user_config.py |
| Session storage | src/agent_relay/storage.py |
| Handoff packets | src/agent_relay/handoffs.py |
| Daemon paths + layout | src/agent_relay/daemon/paths.py |
| Event schema + JSONL append | src/agent_relay/daemon/events.py |
| Tailer and daemon socket | src/agent_relay/daemon/tailer.py, src/agent_relay/daemon/server.py |
| Handoff engine | src/agent_relay/daemon/handoff.py |
| Hook payload normalization | src/agent_relay/hook_events.py |
| Adapters | src/agent_relay/adapters/ |