You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
If you find an answer before your peer responds, send it via INFO right away. Do NOT sit on results waiting for their reply. If they disagree, reconcile — but withholding is worse than being corrected.
Cross-Validate Before Presenting to User
Never present conclusions as final without peer validation. Send findings, get confirmation or correction, then report jointly.
Co-Author Attribution
When collaborating on git commits, include all contributing agents:
Codex: Co-authored-by: Codex <noreply@openai.com> (canonical, from codex-rs/core/src/commit_attribution.rs)
Claude: Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmux send injects text as terminal input. Multi-line messages arrive as separate inputs.
Keep all messages on a single line. For large payloads, write to a file and reference it:
[FROM=surface:4 TO=surface:6 TYPE=RES CID=hoff-20260224-001] See /tmp/cmux-result-abc123.md
Coordinate multi-agent workflows across cmux panes (Claude Code + Codex + Gemini) using envelope messaging over cmux send. Use when two or more agents must delegate work, exchange status, and keep task ownership unambiguous.
cmux Multi-Agent Ops
Run this skill when multiple coding agents coordinate across cmux surfaces and need deterministic handoff with minimal ambiguity.
CRITICAL: 5 Non-Negotiable Rules
Violating ANY of these rules breaks the protocol. No exceptions.
HELLO before anything else. You MUST NOT send any message to a peer until the HELLO->HELLO_ACK handshake is complete. Check /tmp/cmux-greeted-<my_surface>.txt before every send.
ACK every REQ within 30 seconds. When you receive a TYPE=REQ, send TYPE=ACK BEFORE starting any work. Not after. Not "when convenient." BEFORE.
Close every REQ. Every REQ you ACK MUST eventually receive RES or ERR. No silent drops. No forgotten tasks.
Check for messages at every checkpoint. You MUST check for incoming messages (a) after any tool call taking >10 seconds, or (b) after every 3 consecutive tool calls — whichever comes first. You SHOULD also check if 30 seconds of uninterrupted work have passed. If a message is waiting, process it before continuing.
URGENT messages interrupt immediately. When you see PRIORITY=URGENT in an envelope, STOP current work after finishing your current tool call, process the urgent message, then resume previous work.
Quick Start
# 1) identify yourself
cmux identify --json
# -> capture caller.surface_ref / pane_ref / workspace_ref# 2) discover peer agent
cmux list-panes --json
cmux list-pane-surfaces --pane pane:7 --json
# 3) HELLO handshake (first contact)# validate envelope before sending:
MSG="[FROM=surface:4 TO=surface:6 TYPE=HELLO TS=$(python3 -c 'import time;print(int(time.time()*1000))')] agent=Claude pane=pane:5 workspace=workspace:2"
scripts/validate-envelope.sh "$MSG"&& \
cmux send --surface surface:6 "$MSG"&& \
cmux send-key --surface surface:6 enter
# -> peer replies with TYPE=HELLO_ACK when ready# 4) send a task request via agent-handoff.sh (MANDATORY for REQ)
scripts/agent-handoff.sh surface:6 - <<'JSON'{"task":"Review install.sh and suggest improvements","context":"repo=apollo880/skills"}JSON# -> script handles envelope generation, cmux send + send-key automatically# -> continue your own work; ACK and RES arrive asynchronously
Receiver MUST: ACK the cancel request CID within 30s, stop work on target CID, send ERR for the target CID (reason=cancelled to properly close it in the state machine), clean up, then send RES for the cancel request CID.
Lifecycle State Machine
Every CID follows this state progression:
new --> acked --> running --> closed
REQ creates a CID in new state
ACK transitions to acked (MUST happen before heavy work)
Work begins: running state
RES or ERR transitions to closed (exactly once per CID)
If validation fails, fix the message. Do NOT send invalid envelopes.
Step 1: Auto-Greet gate
Check greet file. If target not listed, complete HELLO handshake first (see Auto-Greet below).
Step 2: Self-check
Before pressing send, verify:
FROM, TO, TYPE, and TS are present
CID is present for REQ/ACK/RES/ERR
Message is a single line
You have already sent ACK for any pending REQ from this peer
Checkpoint Discipline
Large tasks cause "hyperfocus" — you become absorbed and stop checking for messages.
The Checkpoint Rule
You MUST check for incoming messages when EITHER of these conditions is met:
After any tool call that takes >10 seconds (file reads, web searches, builds)
After every 3 consecutive tool calls regardless of individual duration
Whichever comes first. Additionally, you SHOULD check if 30 seconds of uninterrupted work have passed as a safety net.
How to Check
Look at your input for any text matching the envelope pattern: [FROM=surface:... TO=surface:... TYPE=...]
If you see an envelope:
PRIORITY=URGENT: process it NOW, then resume your work
TYPE=REQ: send ACK immediately, then either process or continue current work
TYPE=INFO: note it, continue current work
Task Sizing
Include size=S|M|L in REQ body:
Size
Duration
Checkpoint Required?
S
0-30 sec
No mid-task check needed
M
30 sec - 2 min
Yes — check at each sub-task boundary
L
2+ min
MUST decompose into sub-tasks first
BUSY Notification
When a task cannot be split, notify the peer before starting:
[FROM=surface:4 TO=surface:6 TYPE=INFO CID=abc TS=...] BUSY est=90s reason=reading large file
MUST send when estimated block time >= 60 seconds.
Progress Signaling
M tasks: send INFO CID=... if work exceeds initial estimate
L tasks: MUST send INFO CID=... at each sub-task boundary
Include ETA: [TYPE=INFO CID=x TS=...] ETA: ~30s remaining, outline done
Auto-Greet (MANDATORY gate)
HARD RULE: You MUST NOT send any REQ, INFO, or other envelope to a target before completing the HELLO->HELLO_ACK handshake. No exceptions.
Pre-send checklist (execute EVERY time before cmux send)
Resolve target. Run cmux list-workspaces + cmux list-pane-surfaces --workspace <ws> to confirm workspace, pane, and surface. Never assume from memory.
Check greet file. Read /tmp/cmux-greeted-<my_surface>.txt. If <target_workspace>:<target_surface> is NOT listed -> greet first. If listed -> skip to send.
HELLO handshake (blocking).
Write protocol summary to /tmp/cmux-hello-<target_surface>.md (under 800 words)
Append <target_workspace>:<target_surface> to greet file
WAIT for HELLO_ACK. Do NOT send REQ until ACK received.
Greet file lifecycle
Per-session file in /tmp/, cleaned up on reboot
Key targets by workspace:surface (not surface alone)
If peer silent for 90s+, remove entry and re-greet
Common Mistakes
WRONG — Sending REQ without HELLO:
cmux send --surface surface:6 "[FROM=surface:4 TO=surface:6 TYPE=REQ CID=task-001 ...]"
# VIOLATION: No HELLO handshake completed with surface:6
WRONG — Starting work before sending ACK:
# Receives REQ -> immediately starts implementing -> sends ACK 2 minutes later
# VIOLATION: ACK MUST be sent BEFORE starting work
WRONG — Ignoring messages during work:
# Working on Task A for 3 minutes straight without checking
# URGENT message from PM arrived 90 seconds ago, unprocessed
# VIOLATION: Must check at every checkpoint; URGENT must interrupt
WRONG — Sending RES without prior ACK:
# Receives REQ -> does the work -> sends RES (skipped ACK)
# VIOLATION: State machine requires new -> acked -> running -> closed
RIGHT — Proper checkpoint behavior:
# Working on Task A (size=L)
# Sub-task 1 done -> check messages -> none -> continue
# Sub-task 2 done -> check messages -> URGENT from PM -> process it -> resume Task A
# Sub-task 3 done -> check messages -> new REQ -> send ACK -> finish Task A -> RES -> work new REQ
Anti-Patterns
sleep N && cmux read-screen loops — Defeats async design. Send and continue your work.
cmux notify for agent messaging — Agents cannot poll notifications. Use cmux send only.
Multi-line payloads via cmux send — Will fragment. Write to file, send path.
Unbounded read-screen polling — Never spin-wait for a response.
Batching message reads — Do not ignore messages until you finish a task. Check at every checkpoint.
read-screen Usage
Allowed only for:
One-shot liveness check (is peer alive?)
Debug/incident evidence collection
Never use read-screen as a substitute for ACK/RES protocol.
Sender Escalation
When you send REQ and don't get ACK:
Time Elapsed
Action
30s
Wait (peer may be busy)
45-60s
Send one INFO ping with same CID
90s+
Escalate to user/operator
Do not retry indefinitely.
Guardrails
Before every send: Run Pre-Send Validation (Step 0-2). No skipping.
Cross-workspace sends: Run cmux list-workspaces to verify workspace->ref mapping.
Context changes: Re-run cmux identify --json.
Always: Include FROM and TO in every message.
Never: Use cmux notify for agent communication.
Never: Send multi-line bodies via cmux send.
Always: Keep CID stable per task; do not recycle within a session.
Always: Close every REQ with RES or ERR.
Scripts
Script
Purpose
Usage
scripts/agent-handoff.sh
MANDATORY for REQ. Wraps payload in envelope, auto-detects surface, auto-generates CID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters