ctrlb-agent
CtrlB's agent package for Claude Code and Codex. It does three things:
- It uploads every session, including subagents, to the session store in CtrlB. One row per message, thinking block, tool call and tool result, and one per session title (every rename kept), with secrets redacted first.
- It tells each agent its CtrlB Relay run id and agent id at session start. The relay tools (
peers, post, claim, release) and the recall tools (search_sessions, find_command, next_actions, fetch_records) come from CtrlB's hosted MCP server, at the CtrlB URL plus /mcp.
- It checks each edit against the run's claims before the edit runs. Claims are advisory unless the workspace turns on
enforce.
Everything goes to the CtrlB URL with your MCP key. Nothing talks to the lake directly. Standard library Python 3.9 or newer; nothing else is installed.
Use an HTTPS CtrlB URL. The hooks and bin/configure.py allow plain HTTP for loopback (localhost, 127.0.0.0/8, ::1). For a self-hosted server on another host, set CTRLB_ALLOW_HTTP=1 in the environment when configuring and running your agent to opt into plain HTTP; the key and session text then travel unencrypted. API requests reject redirects, so configure the final server URL.
For Recall and Relay on one machine with a standalone binary and SQLite, see Local mode. It includes installation, agent setup, coordinating several agents, limits and moving your records to hosted CtrlB.
Local mode has five recall tools: search_sessions, find_command, next_actions, fetch_records and session_index. session_index lists the caller's recent sessions. All five read only stored records and make no model call, and are listed with or without CTRLB_RUN. Local mode writes no running notes or memories; those need a model.
Install in Claude Code
Mint a key on the Connect page in CtrlB. Put these three lines in your shell profile:
export CTRLB_URL="<your CtrlB URL>"
export CTRLB_MCP_URL="<your CtrlB URL>/mcp"
export CTRLB_KEY="<your key>"
Install the plugin:
claude plugin marketplace add ctrlb-hq/ctrlb-agent
claude plugin install ctrlb-agent@ctrlb-agent
Start Claude Code and run /ctrlb-agent:setup. It checks the connection and offers to upload past sessions.
Claude Code can also do this setup for you: save the key in a file yourself, then give it the prompt in docs/connect-claude-code.md. The agent never reads the key.
To keep the key out of your shell profile, clone this repo and run python3 -I bin/configure.py in a terminal. It asks for the key with hidden input and writes ~/.ctrlb/config.json with mode 0600. The hooks read that file. The MCP server still needs CTRLB_MCP_URL and CTRLB_KEY in the environment, because Claude Code expands them in plugin/.mcp.json.
Install in Codex
Put the same three lines in your shell profile, clone this repo, and run the installer from the clone:
export CTRLB_URL="<your CtrlB URL>"
export CTRLB_MCP_URL="<your CtrlB URL>/mcp"
export CTRLB_KEY="<your key>"
python3 -I install.py --codex --dry-run
python3 -I install.py --codex
python3 -I install.py --codex runs codex/install.py with the options that follow; either command works.
--dry-run prints the change to ~/.codex/config.toml and writes nothing. The installer then writes one block between two marker comments:
[mcp_servers.ctrlb] with the CtrlB URL plus /mcp and bearer_token_env_var = "CTRLB_KEY". Codex reads the key from the environment; the key is never written into the file. env_http_headers sends CTRLB_RUN and CTRLB_AGENT as X-CtrlB-Run and X-CtrlB-Agent when they are set.
[[hooks.<Event>]] tables for SessionStart, SubagentStart, PreCompact, SessionEnd, Stop, SubagentStop and PreToolUse (matcher apply_patch). Each calls codex/hook.py in the clone, so keep the clone where it is.
It copies the old file to config.toml.ctrlb-backup-<time> before it writes. Running it again changes nothing. It refuses to run when config.toml already has an MCP server named ctrlb. Codex skips new or changed hooks until you trust them: start Codex and run /hooks once.
--codex-home <dir> or CODEX_HOME picks another Codex home; --config <file> names the file. --uninstall removes the block.
To upload past Codex sessions: python3 -I bin/backfill.py --codex.
OTEL export instead
Both harnesses can also send their own OpenTelemetry logs straight to the lake's OTLP endpoint with your ingest credentials. For Codex, --otel adds an [otel] table to the block:
python3 -I codex/install.py --otel \
--otel-endpoint "<your CtrlB URL>/api/<org>/<dataset>/_otel/v1/logs" \
--otel-header "Authorization=<your ingest credentials>"
The header value is stored in config.toml as given. The installer refuses to write your CtrlB key there.
Runs and agents