Delegate coding tasks to agy-task from Claude Code
AI coding orchestrators such as Claude Code, Antigravity, and Gemini CLI can delegate implementation and exploration tasks to agy as a subagent. Using the agy skill and agyr, the orchestrator plans and reviews while agy executes in headless mode. This guide covers the reviewer/coder role split, agy-run vs agy-task, the worktree workflow, configuration options, scope checks, exit codes, and skill setup.
Role Split and Execution: Orchestrator vs Sub-Agent
The orchestrator configuration in skills/agy/ enforces a strict separation of concerns: the orchestrator agent acts as planner and reviewer, while agy operates as the sub-agent coder. The main agent does not edit project code directly, except when it has already traced the exact lines to change during investigation (where delegating would cost more than the fix). Otherwise, implementation tasks are dispatched through agy-task run, and read-only exploration through agy-run.
The orchestrator plans without over-specifying: it determines the goal, suspected area, relevant files, pattern to mirror, and acceptance criteria. Tasks run in dedicated git worktrees, launched individually in the background, and are verified with diffs and tests before integration.
agy-run: Runs headlessagy(--dangerously-skip-permissions --output-format stream-json). On HTTP 429 (Individual quota reached), it terminates immediately, sets an account cooldown, switches accounts viaagyr next(soonest weekly reset), and resumes with--conversation <id>. Used for read-only exploration with--add-dir.agy-task: A deterministic wrapper for running a single implement task end to end in an isolated git worktree without an internal LLM. It runs setup commands, invokesagy-run, enforces scope and forbidden paths, and writes a summary report. It runs no tests itself; the orchestrator verifies afterwards.
The agy-task Workflow Step by Step
A typical implementation task follows six sequential stages:
- Task specification: Write the prompt body to a session file (e.g.
.agy-sessions/auth-fix.task.txt). - Launch task: Run
agy-task runin the background:agy-task run --name auth-fix --task .agy-sessions/auth-fix.task.txt --scope 'src/auth/**' --model gemini-4-hydrogen-high - Inspect diff: Read
.agy-sessions/auth-fix.summary.txtand inspectgit diffin.worktrees/agy-auth-fix. - Correction rounds: Write follow-up prompt
fix.txtand resume the session:
Theagy-task run --name auth-fix --resume --task fix.txt --scope 'src/auth/**' --model gemini-4-hydrogen-high--resumeflag continues from the lastinitevent in.agy-sessions/auth-fix.jsonl(implies--reuse-worktree --no-setup). - Integrate: Review code changes, run project tests, and commit verified changes.
- Clean up: Remove the worktree and branch:
Deletes the worktree, branch, and prompt file, keeping audit logs (agy-task rm auth-fix -f.jsonl,.summary.txt,.setup.log,usage.tsv). Without-f, it refuses (exit 2) if untracked changes exist or commits are unmerged.
Configuration File and Run Options
agy-task sources <repo>/.agy-sessions/agy-task.conf (or $AGY_TASK_CONF) defining:
SETUP_CMDS: Array of bash commands executed in order inside the worktree beforeagystarts.COPY_FILES: Array of repo-relative paths copied from the main checkout afterSETUP_CMDS.
See templates/agy-task.conf.example. Useful agy-task run options include:
--name NAME: Task name ([a-z0-9-]+, required; creates worktree, branch, logs).--task FILE: Prompt body file (required).--repo DIR: Main checkout directory (default: current directory).--base REF: Branch base commit-ish (default:HEAD).--scope PATHSPEC: Repeatable pathspec of allowed files.--allow-path PATH: Override permitting modifications to normally forbidden paths.--no-setup: SkipsSETUP_CMDSandCOPY_FILES.--reuse-worktree: Reuses existing worktree directory.--resume: Resumes previous conversation (implies--reuse-worktree --no-setup).--model M: Model ID passed toagy-run(e.g.gemini-4-hydrogen-high).
Scope Checks, Forbidden Paths, and Summary Files
To prevent unintended changes, agy-task validates boundaries after execution:
- Forbidden paths: Edits to
.env*, lockfiles (pnpm-lock.yaml,package-lock.json,yarn.lock), and AI instructions (CLAUDE*.md,AGENTS.md,GEMINI*.md) trigger violations unless allowed via--allow-path. - Scope validation: When
--scopeis set, modifications outside pathspecs trigger violations. - HEAD movement: Sub-agents cannot commit. If
START_HEAD != NOW_HEAD,agy-taskreports a violation. - Limitations: Worktrees start from
--basewithout uncommitted changes from the main checkout. Scope checks inspect files visible togit status/git diff(gitignored files are invisible).
The summary file .agy-sessions/NAME.summary.txt records status (RESULT=OK, RESULT=SCOPE_VIOLATION, RESULT=SETUP_FAILED, or RESULT=AGY_FAILED), metadata, turns, tokens, elapsed seconds, git diff --stat, scope details, up to 25 response lines, and log paths. Metrics are appended to usage.tsv.
agy-task Exit Codes
The table below lists exit codes returned by agy-task:
| Code | Origin | Description |
|---|---|---|
0 |
agy-task |
Success (run: no scope violation; rm: removed). |
1 |
Propagated from agy-run |
General agy execution failure during task run. |
2 |
agy-task |
Invalid arguments, configuration error, resume failure, or rm refused. |
4 |
Propagated from agy-run |
Login error or no active Google account found. |
5 |
Propagated from agy-run |
All accounts in the pool are exhausted (whole pool out of quota). |
6 |
Propagated from agy-run |
Exceeded maximum account switches permitted per run (AGY_RUN_MAX_SWITCH, default 10). |
7 |
agy-task |
Setup commands defined in SETUP_CMDS failed inside worktree. |
8 |
agy-task |
Scope or forbidden-file violation detected (RESULT=SCOPE_VIOLATION). |
Installing the agy Skill for AI Orchestrators
Install agyr using the unified installer:
curl -fsSL https://agyr.pages.dev/install.sh | bash
Copy skills/agy into your agent skills directory:
# Claude Code
mkdir -p ~/.claude/skills
cp -r ~/tools/agy-acct/skills/agy ~/.claude/skills/
# Antigravity / Gemini CLI
mkdir -p ~/.gemini/skills
cp -r ~/tools/agy-acct/skills/agy ~/.gemini/skills/
# Shared ~/.agents/skills convention
mkdir -p ~/.agents/skills
cp -r ~/tools/agy-acct/skills/agy ~/.agents/skills/
You can also add role-split rules from docs/agent-setup.md to CLAUDE.md, GEMINI.md, or AGENTS.md. Tasks automatically inherit templates/hard-rules.txt appended by agy-task. Run agyr help and bash test/run.sh to verify.
Related Guides
Additional resources for configuring Antigravity CLI rotation and agent workflows: