cmux-delegate
Skill3 starsChanged 9 days agoMITView on GitHub
Delegate a task to another AI agent in a separate cmux pane or workspace. Supports Claude Code, Codex, Gemini CLI, and custom agents. Handles agent launch, task submission, completion detection, and result collection.
In this repository24 other files it gives its agents.
- AGENTS.mdAGENTS.md
- agent-delegateSkill
- cmux-forkSkill
- cmux-second-opinionSkill
- handoverSkill
- harness-initSkill
- harness-loopSkill
- harness-planSkill
- ja-humanizerSkill
- magiSkill
- mcp-convertSkill
- skill-suggestSkill
- spec-codeSkill
- spec-evaluateSkill
- spec-generatorSkill
- spec-implementSkill
- spec-inspectSkill
- spec-orchestrateSkill
- spec-reviewSkill
- spec-rules-initSkill
- spec-testSkill
- spec-to-issueSkill
- spec-workflow-initSkill
- spec-writingSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 7 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 40
If empty or unset → stop with error:
- Very specific: line 76
Default is pane split right.
- Distinctive: line 91
If the user specified a different directory:
- Distinctive: line 131
Check output for the agent's prompt pattern.
- Distinctive: line 133
If prompt not detected after retries → report error and stop.
- Distinctive: line 153
After sending, verify the agent accepted the task by reading the screen and confirming the prompt disappeared.
- Distinctive: line 169
Timeout: No hard timeout by default.
- Distinctive: line 190
Ask the user or auto-cleanup based on context:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
cmux-delegate — Delegate Task to Another Agent
Launch an AI agent in a separate cmux pane or workspace, send it a task, monitor completion, and collect results.
Language Rules
- Auto-detect input language → output in the same language
- Japanese input → Japanese output, use
references/delegate-guide.ja.md - English input → English output, use
references/delegate-guide.md - Explicit override takes priority
Prerequisites
BEFORE delegating, verify cmux environment:
echo $CMUX_SOCKET_PATH- If empty or unset → stop with error:
- EN: "Error: Not running inside a cmux session. Please start Claude Code from within cmux."
- JA: "エラー: cmux セッション内で実行されていません。cmux 内で Claude Code を起動してください。"
- If set → proceed
Verify target agent is available (if not default):
which codex # or whichever agent was specifiedAgent Profiles
Select the agent based on user instruction. Default is Claude Code with auto-approve.
| Agent | Interactive Command | Auto-Approve Command (default) | Prompt Pattern | Exit Command |
| Claude Code | claude | claude --dangerously-skip-permissions | > or idle prompt | /exit or Ctrl+C |
| Codex | codex | codex --dangerously-bypass-approvals-and-sandbox | prompt display | exit or Ctrl+C |
| Gemini CLI | gemini | (no auto-approve option available — interactive only) | prompt display | /exit or Ctrl+C |
For agent details and custom agent definitions, see references/agent-profiles.md.
Execution Steps
Step 1: Parse User Request
Extract from the user's instruction:
- Task: What to do (the prompt to send to the agent)
- Agent: Which agent to use (default: Claude Code)
- Mode: Auto-approve (default) or interactive. Use interactive only if user explicitly requests it (e.g., "interactive", "対話モード", "承認あり")
- Direction: Where to place (default: new workspace)
- Directory: Target directory if cross-directory (optional)
Step 2: Create Surface
Default is pane split right. cmux new-workspace may create a non-terminal surface that cannot receive commands — use cmux new-split instead.
# Default: split right (recommended)
cmux new-split right
# Output: OK surface:{N} workspace:{N}
# Alternative: split down
cmux new-split downExtract the surface handle from the output.
Step 3: Change Directory (if cross-directory)
If the user specified a different directory:
cmux send --surface surface:{N} "cd /path/to/target/repo\n"
sleep 1Step 4: Launch Agent
Select the launch command from the Agent Profiles table based on the agent and mode determined in Step 1. Default is auto-approve mode.
Auto-approve (default):
# Claude Code
cmux send --surface surface:{N} "claude --dangerously-skip-permissions\n"
# Codex
cmux send --surface surface:{N} "codex --dangerously-bypass-approvals-and-sandbox\n"
# Gemini CLI (no auto-approve available — always interactive)
cmux send --surface surface:{N} "gemini\n"Interactive mode (if user explicitly requested):
cmux send --surface surface:{N} "claude\n"
cmux send --surface surface:{N} "codex\n"Step 5: Detect Agent Prompt (Polling)
Poll until the agent shows its prompt (ready for input):
sleep 3
cmux read-screen --surface surface:{N}Check output for the agent's prompt pattern. If not detected, retry up to 5 times with 3-second intervals (15 seconds total timeout).
If prompt not detected after retries → report error and stop.
Step 6: Send Task
Send the task prompt to the agent:
cmux send --surface surface:{N} "{task_prompt}"
cmux send-key --surface surface:{N} returnFor multi-line prompts, send line by line:
cmux send --surface surface:{N} "line 1"
cmux send-key --surface surface:{N} return
cmux send --surface surface:{N} "line 2"
cmux send-key --surface surface:{N} returnAfter sending, verify the agent accepted the task by reading the screen and confirming the prompt disappeared.
Step 7: Monitor Completion (Polling)
Poll the surface to detect task completion. Use graduated intervals:
| Elapsed | Poll Interval |
| 0–60s | every 5 seconds |
| 60–300s | every 10 seconds |
| 300s+ | every 30 seconds |
Completion signals:
- Agent prompt reappears → task completed
- Error message pattern detected → task failed
Timeout: No hard timeout by default. Report progress to user periodically (every 60 seconds).
cmux read-screen --surface surface:{N}Step 8: Collect Results
Once completion is detected, collect the full output:
cmux read-screen --surface surface:{N} --scrollback 500Analyze the output:
- Extract the conclusion/summary
- Determine success or failure
- Report results to the user
Step 9: Cleanup (Optional)
Ask the user or auto-cleanup based on context:
# Close the workspace
cmux close-workspace --workspace workspace:{N}
# Or close just the surface
cmux close-surface --surface surface:{N}Error Handling
| Situation | Response |
CMUX_SOCKET_PATH not set | Error: not in cmux session |
| Agent command not found | Error: "{agent} is not installed" |
| Agent prompt not detected | Error: agent failed to start; suggest checking the pane |
| Task sending fails | Retry once; report error if still failing |
| Agent crashes during task | Detect via error patterns in read-screen; report to user |
| Surface creation fails | Report error; cmux may not be running |
Notes
- This skill launches new agent sessions, not forked conversations. For conversation forking, use
cmux-fork. - The parent agent (running this skill) monitors and collects results. The user can also observe the child agent in real-time via the cmux UI.
- For detailed agent profiles, custom agent definitions, and advanced patterns, see the reference guides.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

