session-bridge
# session-bridge
A zero-dependency Python (3.9+ stdlib) MCP server, SQLite WAL task ledger, cross-agent mailbox, and read-only session inspector connecting **Claude Code**, **Antigravity**, **Codex CLI**, and **Gemini CLI**.
## Why `session-bridge`?
Switching between coding agents shouldn't mean copy-pasting transcripts or guessing which worktree is active:
- **Read-only cross-CLI session adapters**: list, read (`handoff`, `recent`, `full`, `files`/`artifacts`), and search sessions across Claude Code (`~/.claude`), Antigravity (`~/.gemini/antigravity*`), Codex CLI (`~/.codex`), and Gemini CLI (`~/.gemini/tmp`).
- **Shared SQLite WAL task ledger** (`~/.local/share/session-bridge/bridge.db` + auto-rendered `LEDGER.md`): track task `status`, `ball_with`, git `worktree`, `branch`, `commit_sha`, `pr_url`, and warn on active worktree collisions.
- **Cross-agent mailbox with honest wakeup UX**: `bridge_send_message` tracks active `wait-inbox` watcher PIDs and reports either `delivery: "live_wakeup"` (a watcher is running and will return within ~1 s) or `delivery: "queued_for_next_turn"` (stored in `bridge.db` until the recipient's next turn).
- **Sub-5 ms prompt-turn hooks**: surfaces unacknowledged message previews once per message via `SessionStart` / `UserPromptSubmit` / `PreInvocation` / `BeforeAgent` hooks without blocking turns.
- **Strict security defaults**: `0700` data directory, `0600` on `bridge.db` + `-wal`/`-shm` + `LEDGER.md`, and canonical root confinement rejecting symlink escapes and `..` traversal.
## Supported CLIs
| Client | Read/List/Search Adapter | MCP Auto-Config | Prompt Hooks | Packaged Skill |
| :--- | :---: | :---: | :---: | :---: |
| **Claude Code** | Yes | `~/.claude.json` | `SessionStart`, `UserPromptSubmit` | `~/.claude/skills/session-handoff/SKILL.md` |
| **Antigravity** | Yes | `~/.gemini/config/mcp_config.json` | `SessionStart`, `PreInvocation` | `~/.gemini/config/skills/session-handoff/SKILL.md` |
| **Codex CLI** | Yes | `~/.codex/config.toml` | n/a | `~/.codex/skills/session-handoff/SKILL.md` |
| **Gemini CLI** | Yes | `~/.gemini/settings.json` | `SessionStart`, `BeforeAgent` | `~/.gemini/skills/session-handoff/SKILL.md` |
## Installation
Install persistently with `uv` or `pipx` (recommended so hooks invoke a local binary without cache cold-starts):
```bash
uv tool install session-bridge
# or
pipx install session-bridge
```
Or try directly from a local checkout:
```bash
pip install -e .
```
Then register the MCP server, hooks, and skills for whichever coding CLIs exist on your machine:
```bash
session-bridge install
session-bridge doctor
```
Useful flags:
```bash
session-bridge install --dry-run
session-bridge install --clients claude codex
session-bridge uninstall # preserves ~/.local/share/session-bridge/bridge.db
session-bridge uninstall --purge-data
```
## Honest Delivery Model (`live_wakeup` vs `queued_for_next_turn`)
Sending a message **never wakes an idle peer by itself**. `bridge_send_message` (and `session-bridge send`) inspects active `wait-inbox` watcher PIDs and returns:
- `"live_wakeup"`: at least one matching `session-bridge wait-inbox` process is alive right now (`watcher_pids` populated) and will receive the message within ~1 s.
- `"queued_for_next_turn"`: no watcher is active; the message is queued in `bridge.db` and surfaced on the recipient's next turn by its hook (or when the user asks it to check inbox).
To wait for a reply in the background from any agent or terminal:
```bash
session-bridge wait-inbox --target claude --session <session-id> --timeout 1800
```
## MCP Tools (17 total)
| Category | Tools |
| :--- | :--- |
| **Claude Code** | `list_claude_sessions`, `read_claude_session`, `search_claude_sessions` |
| **Antigravity** | `list_antigravity_sessions`, `read_antigravity_session`, `search_antigravity_sessions` |
| **Codex CLI** | `list_codex_sessions`, `read_codex_session`, `search_codex_sessions` |
| **Gemini CLI** | `list_gemini_sessions`, `read_gemini_session`, `search_gemini_sessions` |
| **Task Ledger** | `ledger_upsert_task`, `ledger_list_tasks` |
| **Mailbox** | `bridge_send_message`, `bridge_check_inbox`, `bridge_ack_messages` |
## CLI Quick Reference
```bash
# Inspect peer sessions
session-bridge list-claude --all
session-bridge read-claude <id-or-name> --mode handoff
session-bridge list-agy
session-bridge list-codex
session-bridge list-gemini
# Shared ledger & mailbox
session-bridge ledger-upsert my-task --title "Refactor auth" --status needs_review --ball-with claude
session-bridge ledger-list
session-bridge send --to claude --from antigravity:abc12345 --kind review_request --task my-task --subject "Ready for review" --body "See branch feat/auth"
session-bridge inbox --target claude
session-bridge watchers
```
## Security & Privacy
- **Zero runtime dependencies**: pure Python 3.9+ standard library (`sqlite3`, `json`, `pathlib`, `argparse`, `os`, `signal`).
- **Path confinement**: every transcript, artifact, side-note, and project-root read resolves symlinks and rejects any path outside canonical CLI directories.
- **Strict file permissions**: `~/.local/share/session-bridge` is enforced as `0700`; `bridge.db`, `bridge.db-wal`, `bridge.db-shm`, and `LEDGER.md` are enforced as `0600`.
- **Opt-out env var**: set `SESSION_BRIDGE_DISABLE_HOOK=1` in automated/headless runs to keep hooks completely silent.
- **Custom data directory**: set `SESSION_BRIDGE_DIR=/path/to/dir` to isolate state per environment.
## Development
```bash
pip install -e ".[dev]"
pytest -v
python scripts/privacy_scan.py --git-history
```
## License
MIT — see [LICENSE](LICENSE).
TDQS
Scored across 17 tools
Each tool targets a distinct resource+action: the four provider families are cleanly separated (list/read/search per Gemini, Antigravity, Codex, Claude), and the ledger and mailbox tools occupy clearly different domains. The only near-overlap is bridge_check_inbox (ack=true by default) versus bridge_ack_messages, and the descriptions explicitly explain the ack=false workflow that separates them.
Twelve tools follow a strict verb_provider_noun pattern (list_gemini_sessions, read_codex_session, search_claude_sessions), and the collaboration tools follow a namespace_verb_noun pattern (ledger_upsert_task, bridge_send_message). Two coexisting conventions is a minor deviation, but each family is internally consistent and readable.
17 tools is slightly above the comfortable range, but the count is fully accounted for by a systematic 4 providers × 3 operations matrix plus 5 collaboration tools. Nothing appears redundant, though the per-provider symmetry means any new provider adds three more tools.
Session lifecycle (list, read, search) is covered for all four agent CLIs, and the ledger/mailbox surface supports create, update, list, send, receive, and acknowledge. Gaps are minor: no task delete/archive or single-task get on the ledger, no message history/thread view beyond the inbox, and no unified cross-provider search despite the 'bridge' framing.