Skip to content

Delegate tasks between coding agents

Hand a task to Claude Code, Codex, or opencode headlessly from the terminal — or let a running agent delegate a subtask to another agent — all through one AnyRouter key.

One AnyRouter key drives every coding agent — so agents can hand work to each other. The documented path is the CLI:

anyr delegate --to <agent> "<task>"

Delegation is limited to one hop: a delegated agent can never delegate again, so two agents cannot ping-pong tasks (and spend) between each other.

From the terminal

anyr delegate --to codex "add unit tests for src/utils/slug.ts"
anyr delegate --to claude "explain this stack trace" --model deepseek/deepseek-v3
anyr delegate --to opencode "fix the lint errors in packages/ui" --yes

The CLI launches the target agent's non-interactive mode (claude -p, codex exec, opencode run) with the same gateway configuration as a normal anyr <agent> launch — your stored key, base URL, and model — streams the agent's output, and exits with the agent's exit code.

Before running, a terminal prompt confirms the target and model (an agent run can make many model calls). In scripts and CI pass --yes.

FlagMeaning
--to <agent>Target: claude, codex, or opencode (required)
--model <id>Model for the run (default: your profile's default model)
--yesSkip the confirm prompt (required without a terminal)
--dry-runShow the exact command and environment (secrets redacted)
--profile <name>Use a named account

The target agent must be installed; if it is not, the CLI prints the install command.

Bridging from an already-running agent session

If you already have a session running on the (deprecated) @anyr/agent runtime, it exposes the same capability as a tool the model can call:

delegate_task(tool, task, model?)

It is a thin bridge — under the hood it runs anyr delegate with your stored credentials, with the same one-hop guard and a 10-minute cap. This is a compatibility bridge for existing sessions, not a reason to adopt @anyr/agent; for new setups use anyr delegate (or launch agents with anyr claude / anyr codex) directly.

Task pipelines without an agent

For a lighter two-step (a strong model plans, a fast model executes — no coding agent spawned), see anyr task.

Guardrails

  • One hop. Delegated agents run with a depth marker; a second delegation is refused.
  • Confirmation. Terminal runs confirm first; non-interactive runs require --yes.
  • Timeout. In-agent delegations are capped at 10 minutes so a hung child cannot stall your session.
  • Same key, same logs. Delegated runs authenticate with your stored key and appear in your request logs like any other usage.