# Delegate tasks between coding agents

> Hand a task to Claude Code, Codex or opencode headlessly from the terminal, all through one AnyRouter key.


# Delegating between coding agents

`anyr delegate` hands a task to another coding agent with the same AnyRouter key.

```bash
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 starts the target's non-interactive mode (`claude -p`, `codex exec`, `opencode run`) with your stored key, base URL and model, streams its output, and exits with the agent's exit code. The target must be installed; if not, the CLI prints the install command.

| Flag | Meaning |
| --- | --- |
| `--to <agent>` | Target: `claude`, `codex`, or `opencode` (required) |
| `--model <id>` | Model for the run (default: your profile's default model) |
| `--yes` | Skip the confirm prompt (required without a terminal) |
| `--dry-run` | Show the exact command and environment (secrets redacted) |
| `--profile <name>` | Use a named [account](/cli/accounts-and-keys) |

## Guardrails

- **One hop.** A delegated agent cannot delegate again, so agents cannot ping-pong tasks and spend.
- **Confirmation.** Terminal runs confirm first; non-interactive runs need `--yes`.
- **Same key, same logs.** Delegated runs appear in your [request logs](https://anyrouter.dev/dashboard/).

A session on the deprecated `@anyr/agent` runtime exposes the same thing as a model-callable tool, `delegate_task(tool, task, model?)`, capped at 10 minutes. For new setups use `anyr delegate`.

For a lighter plan-then-execute pipeline without spawning an agent, see [`anyr task`](/cli/task).


## Related

- [Plan and implement with anyr task](/docs/cli/task.md)
- [Accounts and keys in the CLI](/docs/cli/accounts-and-keys.md)
