Delegate complex tasks to specialized AI coding agents
Picks the right AI agent for a task and sends it a TUI prompt safely, without breaking delivery or losing context.
Why it matters
Route and orchestrate work across multiple AI agents (Codex, Pi, Claude Code, Hermes) by selecting the right agent for each task type, formatting prompts correctly for terminal interfaces, and polling progress to ensure successful completion of complex multi-step workflows.
Outcomes
What it gets done
Send properly formatted single-line prompts to TUI agents via cmux without triggering submission errors
Select the optimal agent for each task: Codex for complex coding, Pi for frontend/design, Hermes for autonomous multi-session work
Poll agent progress with short 3-5 second intervals and relay status updates on task completion
Launch and drive agents on remote VPS environments via SSH for on-box execution
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-delegating-to-agents | bash Overview
Delegating to Agents
Picks the right AI agent for a task (Codex CLI for coding, Pi for most else and frontend, Claude Code, Hermes) and shows how to send it a single-line TUI prompt without breaking delivery. Use it when handing work to another AI agent with a complete prompt and progress checks. Keep polling sleeps short and never send multi-line or escaped-quote prompts to a TUI.
What it does
Delegates work to another AI agent - handing it a complete prompt, sending it correctly to a terminal or TUI agent without losing context, and checking on its progress. Covers agent selection, how to send prompts to a TUI agent without breaking the terminal, polling cadence, and driving agents on a remote VPS.
When to use - and when NOT to
Use it when work should be handed to another AI agent with a complete prompt and progress checks, or when instructions need to be relayed to terminal or TUI agents without losing context. For coding, default to Codex CLI - the strongest coding agent, especially for complex, long-running SWE tasks, on an unlimited-usage plan that doesn't need rationing. For most other tasks, use Pi Agent (pi in a cmux terminal; all Pi agents run opus-4.8-fast via OpenRouter at xhigh reasoning effort), and specifically prefer Pi for frontend or design work, where Opus 4.8 Fast beats Codex on UI, styling, and design. For heavy multi-step work, a solid default is acting as orchestrator yourself while Codex CLI executes in a right-hand cmux pane.
Inputs and outputs
Sending a prompt to a TUI agent has three hard rules: send it as ONE single line, never newlines in the message body - in a TUI a newline is Enter, so a multi-line prompt submits at the first line and the rest arrives as fragmented mid-turn steering messages; use ". " or "; " instead of line breaks, or for long instructions write them to a file and send a pointer like "read /tmp/task.md and follow it". Wrap the prompt in plain double quotes, never escaped - cmux send --surface surface:N "your prompt" - since an escaped \" breaks bash with unexpected EOF; avoid apostrophes and literal double quotes inside the prompt (write "dont", "wont", "lets") rather than escaping them. Use the exact commands cmux send --surface surface:N followed by cmux send-key --surface surface:N enter - there is no send-surface or send-key-surface. When polling for a response, keep sleeps short (start at 3-5s and re-check, never sleep 30, since Pi and Hermes launch and respond within seconds and only genuinely heavy tasks need longer), and send the user a one-line status after every check. On a remote VPS, SSH in first and launch the agent on the VPS itself (e.g. codex --yolo), then drive that on-box agent, rather than running an agent locally and having it SSH for every step.
Integrations
Covers four interoperable CLI agents, all using the portable SKILL.md standard where project skills win over global ones: Pi (pi.dev, open-source TypeScript) with a minimal read/write/edit/bash core that self-extends via TS extensions, true BYOK, and best-in-class session branch/fork/resume, skills in ~/.pi/agent/skills/; Codex CLI (OpenAI, Rust) with the fastest startup, kernel-level sandboxing, codex exec for CI, and AGENTS.md support, skills in ~/.codex/skills/; Claude Code (Anthropic, TypeScript) with the deepest Claude integration, .claude/ conventions, and live skill hot-reload, skills in ~/.claude/skills/; and Hermes (Nous Research, Python), a persistent autonomous agent with cross-session memory, a built-in scheduler, 40+ tools, and the ability to orchestrate the other CLIs as workers, skills in ~/.hermes/skills/. Codex, Pi, and OpenCode need pty=true to drive interactively; Claude Code is instead best driven with claude --print --permission-mode bypassPermissions (no PTY). Claude Code may also prefill a predicted next user message after finishing - that draft is Claude's own prediction, not the user's.
Who it's for
Orchestrating agents or developers who need to reliably hand off coding, frontend, or heavy multi-step work to the right specialized CLI agent - locally or on a remote VPS - without breaking prompt delivery or losing track of progress.
Source README
Delegating to Agents
When to Use
- Use when work should be handed to another AI agent with a complete prompt and progress checks.
- Use when you need to relay instructions to terminal or TUI agents without losing context.
Which agent to pick
- Coding (default) → Codex CLI. Strongest coding agent, especially for complex, long-running SWE tasks. It's on an unlimited-usage plan - effectively unlimited, don't ration it.
- Most other tasks → Pi Agent (
piin a cmux terminal). All Pi agents run opus-4.8-fast via OpenRouter at xhigh reasoning effort. - Frontend / design → Pi. Opus 4.8 Fast beats Codex on UI, styling, design.
- Heavy multi-step work: you as orchestrator + Codex CLI executing in a right-hand cmux pane is a solid default setup.
Sending prompts to a TUI agent
- ONE single line - never newlines in the message body. In a TUI, newline = Enter: a multi-line prompt submits at the first line and the rest arrives as fragmented mid-turn steering messages. Use ". " or "; " instead of line breaks, then one explicit enter. For long instructions, write them to a file and send:
read /tmp/task.md and follow it. - Wrap the prompt in plain double quotes - NEVER escaped.
cmux send --surface surface:N "your prompt". The recurring bug is emitting\"- in bash that's literal-broken and dies withunexpected EOF. Inside the prompt, avoid apostrophes and literal double quotes (write "dont", "wont", "lets"); rephrase instead of escaping. If a send failed, the cause was the escaped\", not the quote type. - Exact command names:
cmux send --surface surface:Nthencmux send-key --surface surface:N enter. There is NOsend-surfaceorsend-key-surface.
Polling
Keep sleeps SHORT: start at 3-5s, re-check, repeat. Don't sleep 30. Pi and Hermes (opus-4.8-fast) launch and respond within seconds; scale up only for genuinely heavy tasks. After every check, send the user a one-line status: what the agent is doing and whether it's on track.
Claude Code note: after it finishes, it may prefill a predicted next user message - that draft is Claude, not the user.
Remote VPS
SSH in first and launch the agent ON the VPS (e.g. codex --yolo), then drive that on-box agent. Don't run an agent locally and have it SSH for every step.
The 4 agents (background reference)
All four use the portable SKILL.md standard; project skills win over global.
- Pi (pi.dev, open-source TS): minimal read/write/edit/bash core, self-extends via TS extensions; true BYOK; best-in-class session branch/fork/resume. Skills:
~/.pi/agent/skills/. - Codex CLI (OpenAI, Rust): fastest startup; kernel-level sandboxing;
codex execfor CI; reads AGENTS.md. Skills:~/.codex/skills/. - Claude Code (Anthropic, TS): deepest Claude integration,
.claude/conventions, live skill hot-reload. Skills:~/.claude/skills/. - Hermes (Nous Research, Python): persistent autonomous agent - cross-session memory, built-in scheduler, 40+ tools; can orchestrate the other CLIs as workers. Skills:
~/.hermes/skills/.
Driving interactive CLIs
- Codex, Pi, OpenCode: need
pty=true. - Claude Code: prefer
claude --print --permission-mode bypassPermissions(no PTY).
Limitations
- Adapted from
davidondrej/skills; verify local paths, tools, credentials, and agent features before acting. - For commands, remote access, scheduling, browser automation, or file-changing workflows, get explicit user approval and confirm the target environment first.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.