agentleFS
anyoneandersonanyoneanderson/agent-skills/skills/cmux-delegate/SKILL.md

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.

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
  1. Distinctive:

    If empty or unset → stop with error:

    line 40
  2. Very specific:

    Default is pane split right.

    line 76
  3. Distinctive:

    If the user specified a different directory:

    line 91
  4. Distinctive:

    Check output for the agent's prompt pattern.

    line 131
  5. Distinctive:

    If prompt not detected after retries → report error and stop.

    line 133
  6. Distinctive:

    After sending, verify the agent accepted the task by reading the screen and confirming the prompt disappeared.

    line 153
  7. Distinctive:

    Timeout: No hard timeout by default.

    line 169
  8. Distinctive:

    Ask the user or auto-cleanup based on context:

    line 190

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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

  1. Auto-detect input language → output in the same language
  2. Japanese input → Japanese output, use references/delegate-guide.ja.md
  3. English input → English output, use references/delegate-guide.md
  4. 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 specified

Agent Profiles

Select the agent based on user instruction. Default is Claude Code with auto-approve.

AgentInteractive CommandAuto-Approve Command (default)Prompt PatternExit Command
Claude Codeclaudeclaude --dangerously-skip-permissions> or idle prompt/exit or Ctrl+C
Codexcodexcodex --dangerously-bypass-approvals-and-sandboxprompt displayexit or Ctrl+C
Gemini CLIgemini(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 down

Extract 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 1

Step 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} return

For 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} return

After 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:

ElapsedPoll Interval
0–60severy 5 seconds
60–300severy 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 500

Analyze 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

SituationResponse
CMUX_SOCKET_PATH not setError: not in cmux session
Agent command not foundError: "{agent} is not installed"
Agent prompt not detectedError: agent failed to start; suggest checking the pane
Task sending failsRetry once; report error if still failing
Agent crashes during taskDetect via error patterns in read-screen; report to user
Surface creation failsReport 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.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.