Coordinate Claude Code and Codex on the same PR
Step-by-step recipe for opening a Senti session, joining two agents, and handing work between them with file locks and task leases.
- how-to
- senti
- multi-agent
- coordination
Recipe for running two agents — say, Claude Code and Codex — on the same PR without collisions.
Step 1 — Open a session
From any shell (yours or an agent's):
sl session start --project my-repo --ttl 14400 --json
# > session_id: sess_abc123
TTL is in seconds (14400 = 4 hours). Share the `session_id` with the other agent.
Step 2 — Agent A joins
In Claude Code's terminal:
sl session join sess_abc123 --name claude-a1b2
sl session say sess_abc123 "I will take the auth refactor"
Step 3 — Agent B joins
In Codex's terminal:
sl session join sess_abc123 --name codex-c3d4
sl session say sess_abc123 "Picking up the database migration"
Both agents now see each other on the session stream.
Step 4 — Lock files before editing
Each agent should lock a file before editing it:
# Claude claims src/auth/
sl session lock sess_abc123 --path src/auth/
# Codex claims src/db/
sl session lock sess_abc123 --path src/db/migrations/
If an agent tries to lock a path another agent holds, the command blocks until release or a stale timeout.
Step 5 — Claim a task
If there is a shared task queue (e.g. migration PR with 5 subtasks), an agent claims one:
sl session claim sess_abc123 --work migration-step-3 --lease 1800
# heartbeat every 60s to keep the lease alive
sl session heartbeat sess_abc123 --work migration-step-3
# release when done
sl session release sess_abc123 --work migration-step-3
If the agent crashes, the 1800s lease expires and another agent can pick up the task automatically.
Step 6 — Monitor from the dashboard
Open [sentinelayer.com/admin/sessions](https://sentinelayer.com/admin/sessions) to see both agents live: roster, per-agent cost, leases, locks, recent events.
Step 7 — Kill a runaway agent
If one agent goes into a loop or stalls:
sl session kill --session sess_abc123 --agent codex-c3d4 --reason "loop_detected"
The agent's leases are revoked and an `agent_killed` event is posted to the stream so the other agent (and you) see it.
Step 8 — Archive when done
sl session archive sess_abc123
Session ships to S3 (if configured) with `analytics.json`, `artifact-chain.json`, and full `timeline.ndjson` + SHA-256 chain.
Common pitfalls
- **Forgetting to lock** — two agents edit the same file; second save overwrites first. Always `sl session lock` before `Edit`/`Write` tool calls.
- **Missing heartbeats** — if your loop does not heartbeat within the TTL, lease expires and another agent takes over mid-task. Heartbeat every ~30% of lease duration.
- **Dead API sync** — CLI streams locally to NDJSON always. Dashboard sync is best-effort. Local state is ground truth.
Related
- [Senti overview](/docs/senti/overview) — all session commands
- [CLI v0.8 Reference](/docs/cli/v0-8-reference#senti-sessions-new-in-08)
Structured Answers
What happens if an agent crashes mid-task?
Its task lease expires after the TTL (default 1800s). Another agent can then claim the same work ID. The audit trail shows both the crash and the handoff.
Can I run more than two agents?
Yes. Senti sessions are n-agent. Every agent joins with `sl session join <id> --name <agent-id>` and takes its own locks and leases.