How to call Google Antigravity (agy -p) as a subagent from Claude Code or Codex
By Flavio
Tagged: AI
Run Gemini 4 Neon through Google's unmodified agy CLI as a subagent from Claude Code or Codex, with real benchmarks, structured JSON output, and the gotchas I hit.
On December 1, 2026, Google rewrote clause 6 of the Antigravity Terms of Service and updated the Antigravity FAQ.
One change unlocked a workflow a lot of us wanted for months: calling the unmodified agy CLI (including agy -p headless mode) as a tool or subagent from another coding harness is now explicitly permitted.
That means you can stay inside Claude Code or Codex as your main driver and delegate a second opinion, a code review, or an architecture check to Gemini 4 Neon using your existing Google AI Pro or Google AI Ultra subscription.
In this guide I will show you how to set it up, what real timings and token counts look like on a real codebase, and the four gotchas I ran into when testing it with agy 1.5.17, Claude Code 2.1.332, and Codex 0.172.0.
Why this is allowed (and where the line is)
Before writing a single wrapper script, it helps to be crystal clear on what stays inside Google’s Terms of Service and what still gets Antigravity access suspended. I covered the full policy rewrite in Google Antigravity and Gemini Neon: what gets accounts banned.
The short rule is simple: let Antigravity run its own agent loop.
When Claude Code or Codex invokes agy -p over the shell, Google’s unmodified CLI handles authentication, reads the files it needs, runs its own reasoning, and prints a finished answer back to stdout. You are not extracting OAuth tokens and you are not using agy as a raw completions proxy to drive Claude Code’s own loop.
If you want an external harness to run its own loop straight against Gemini models without calling agy, use a Gemini API key backed by your monthly Google Cloud API credits instead.
Prerequisites and picking a model
First make sure agy is installed and signed in with one interactive session (headless mode reuses those cached credentials and exits with an auth error if you have not logged in yet). If you are setting up Antigravity for the first time, start with the complete guide to Google Antigravity, or grab the free Antigravity Handbook to read offline.
List the exact model IDs your account can pass to --model:
agy --version
agy models
On my machine (agy 1.5.17), the Gemini 4 models I use for subagent work are:
gemini-4-neon-high Gemini 4 Neon (High)
gemini-4-neon-medium Gemini 4 Neon (Medium)
gemini-4-neon-low Gemini 4 Neon (Low)
gemini-4-hydrogen-low Gemini 4 Hydrogen (Low)
Your first agy -p subagent call
Let’s run a real read-only code review against a file in this site’s repository, src/plugins/remark-pele.mjs, and ask agy -p to return a JSON envelope so another agent can parse it cleanly.
agy -p "Read src/plugins/remark-pele.mjs only (do not run shell commands) and list the top 2 edge cases. Be concise, cite line numbers." \
--model gemini-4-neon-low \
--mode plan \
--output-format json \
--print-timeout 120s \
| jq '{conversation_id, status, duration_seconds, usage}'
Notice the two safety rails in that command: --mode plan keeps the session out of edit mode, and the prompt tells the model not to run shell commands (I will explain why that sentence matters in the gotchas section below).
Here is the real output from running that command on my Mac:

The JSON envelope gives the calling agent everything it needs:
conversation_idso you can ask a follow-up question in the same thread laterstatus(SUCCESSorERROR)responsewith the plain Markdown answerduration_secondsandusage(includingthinking_tokensandcache_read_tokens)denied_actionsif Antigravity tried to use a tool that headless mode blocked
On that review of src/plugins/remark-pele.mjs, Gemini 4 Neon caught two real edge cases: passing HTML wrapper divs (<div data-pele-step>) to fromHtml(svg, { fragment: true, space: 'svg' }) on line 123, and file.path || file.value.toString() throwing a TypeError on line 99 when a virtual VFile has neither path nor value.
Real timings across Gemini 4 models
When Claude Code or Codex waits on a shell tool call, latency matters a lot. I ran the same read-only review of src/plugins/remark-pele.mjs across four models on my Mac to see how thinking effort changes wall time and token usage:
| Model | Wall time (duration_seconds) | Input tokens | Output tokens | Thinking tokens | Cache read | Good for |
|---|---|---|---|---|---|---|
gemini-4-hydrogen-low | 6.96s | 24,915 | 870 | 462 | 22,388 | Fast file lookups, quick checks |
gemini-4-neon-low | 33.34s | 24,271 | 1,355 | 924 | 21,754 | Everyday second opinions and reviews |
gemini-4-neon-medium (--json-schema) | 50.56s | 24,599 | 4,800 | 4,414 | 21,917 | Structured JSON reviews and bug hunts |
gemini-4-neon-high | 113.08s | 24,172 | 10,347 | 9,787 | 21,709 | Hard architectural reviews (raise timeout) |
Every single one of those four models spotted both real edge cases in remark-pele.mjs. gemini-4-neon-high spent 9,787 thinking tokens and also noticed that unnamed files collide on the same idPrefix hash, while gemini-4-neon-low returned a sharp answer in a third of the time.
For daily subagent delegation from Claude Code or Codex, I default to gemini-4-neon-low or gemini-4-neon-medium, and only bump to gemini-4-neon-high (with --print-timeout 300s) when I am stuck on a gnarly bug.
Enforcing structured JSON output with --json-schema
Free-text Markdown works when a human reads the answer, but when another agent is deciding whether to fix something or move on, typed JSON is much cleaner.
agy -p supports --json-schema directly. You pass an inline JSON schema (or a path to a .json file) alongside --output-format json, and the parsed object comes back under .structured_output:
agy -p "Read src/plugins/remark-pele.mjs only (do not run shell commands) and return a code review verdict with up to 2 findings." \
--model gemini-4-neon-low \
--mode plan \
--output-format json \
--json-schema '{
"type": "object",
"properties": {
"verdict": { "type": "string", "enum": ["approve", "comment", "request_changes"] },
"findings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"line": { "type": "integer" },
"severity": { "type": "string" },
"issue": { "type": "string" }
},
"required": ["line", "severity", "issue"]
}
}
},
"required": ["verdict", "findings"]
}' \
--print-timeout 120s \
| jq '.structured_output'
Here is the real structured output printed in my terminal:

Your calling agent gets a guaranteed verdict and an array of { line, severity, issue } objects with zero regex parsing.
Resuming the subagent thread with -r
Headless runs start fresh by default, which is usually what you want for an unbiased second opinion. When you want to follow up on a finding without making Gemini re-read everything, pass -r (short for --conversation) with the conversation_id from the first JSON response:
agy -p "For finding #2, show a 1-line fix." \
-r 43569107-8fee-4437-8338-313b2e86159b \
--model gemini-4-hydrogen-low \
--mode plan \
--output-format json \
--print-timeout 60s \
| jq -r '.response'
That follow-up took about 4.5 seconds on my Mac and returned the exact diff from the prior context:
- .update(file.path || file.value.toString())
+ .update(file.path || String(file.value ?? ''))
One detail to watch if you log metrics: duration_seconds and usage in the JSON output are cumulative across the whole conversation (num_turns: 2), while response contains only the latest turn.
Wiring it into Claude Code and Codex as a skill
You do not want to type those flags by hand every time. The cleanest way to give both Claude Code and Codex access to Gemini 4 Neon is a tiny shared skill (if you have not written skills yet, grab the free Agent Skills Handbook alongside the Claude Code Handbook and Codex Handbook).
Create a small wrapper script or put the instructions straight into a skill file. You can keep a single skill at ~/.agents/skills/ask-neon/SKILL.md (which Codex reads natively) and symlink it into ~/.claude/skills/ask-neon for Claude Code:
---
name: ask-neon
description: Delegate a read-only code review, second opinion, or debugging check to Google Antigravity (Gemini 4 Neon) using the unmodified agy CLI.
---
# Ask Gemini 4 Neon via agy -p
When you want a second opinion or independent code review from Gemini 4 Neon, run Google's unmodified `agy` CLI over the shell.
## Command
```bash
agy -p "<specific question, file paths, and 'do not run shell commands or edit files'>" \
--model gemini-4-neon-low \
--mode plan \
--output-format json \
--print-timeout 180s
```
Use `gemini-4-neon-medium` (with `--print-timeout 240s`) for deeper reviews, or `gemini-4-neon-high` (`--print-timeout 300s`) for hard architecture questions.
## Rules
- Run `agy` outside the Bash sandbox (it opens a local port and writes logs under `~/.gemini/`).
- Do not pass `--disable-slash-commands` together with `--mode plan`.
- Always check `.denied_actions` in the JSON response. If it is non-null or `.response` is empty, refine the prompt so `agy` sticks to read-only file tools.
- Never extract OAuth tokens or turn `agy` into a raw model proxy for another agent loop.
Then link it so both tools discover the same skill:
mkdir -p ~/.claude/skills
ln -s ~/.agents/skills/ask-neon ~/.claude/skills/ask-neon
Testing it for real from Claude Code
I tested calling agy -p directly from claude 2.1.332 on this repository, asking Claude Code to delegate a lookup in scripts/check-post-visuals.mjs:
claude -p "Run a single Bash command to call agy -p with --model gemini-4-hydrogen-low --mode plan --output-format json asking it to read scripts/check-post-visuals.mjs (do not run shell commands) and name the single date cutoff used for checking posts. Then print the exact answer and agy duration_seconds in 2 short lines." \
--allowedTools "Bash(agy:*)" \
--model haiku \
--output-format json \
| jq '{subtype, duration_ms, num_turns, result}'
Here is the real output Claude Code returned:
{
"subtype": "success",
"duration_ms": 15652,
"num_turns": 3,
"result": "2026-09-20\nduration_seconds: 4.978662\n\nThe first run failed inside the sandbox because agy couldn't open a local port or write its log, so I reran the same command with the sandbox off."
}
Testing it for real from Codex
I ran the same delegation test from codex 0.172.0:
codex exec --dangerously-bypass-approvals-and-sandbox \
"Run one shell command calling agy -p with --model gemini-4-hydrogen-low --output-format json asking it to read scripts/check-post-visuals.mjs (do not run shell commands or edit files) and report the single date cutoff used for checking posts. Reply with just the cutoff date and agy's duration_seconds."
Codex spawned /bin/zsh -lc "agy -p ..." in 8.48 seconds (agy itself took 6.38 seconds, 25,654 total tokens with 20,363 cached) and printed:
2026-09-20, 6.376986 seconds
Four real gotchas I hit (so you don’t have to)
Running these commands for real surfaced four quirks that are easy to miss if you only read the --help output:
- Sandboxed Bash breaks
agy. Look at Claude Code’s note above: inside a sandboxed shell,agyfails because it needs to bind a local port and write state/logs under~/.gemini/. In Claude Code, allowagyoutside the Bash sandbox (or run the command unsandboxed). In Codex, approve escalated execution when it callsagy. --disable-slash-commandsdisables--mode plan. When I passed both flags together,agyprintedwarning: --mode plan has no effect while slash command expansion is disabled.Leave--disable-slash-commandsoff when you want plan mode.- Auto-denied shell commands return
"status": "SUCCESS". During my firstgemini-4-neon-mediumrun with--json-schema, Neon readremark-pele.mjsand then tried to runBashto execute the test suite. Headless mode cannot prompt for permission, so it auto-denied the command and exited0with"status": "SUCCESS","structured_output": null, and"denied_actions": [{"action": "command", "display_name": "Bash"}]. Always tell read-only subagent prompts not to run shell commands, and checkdenied_actionsbefore trustingstatus. - 120 seconds is too tight for
gemini-4-neon-high. My first twogemini-4-neon-highruns with--print-timeout 120shit the deadline and exited with code3(DEADLINE_EXCEEDED). When it succeeded, it took 113.08 seconds and used 9,787 thinking tokens. Usegemini-4-neon-low(33s) orgemini-4-neon-medium(51s) by default, and giveneon-highat least--print-timeout 300s.
How I would use this in my own workflow
When I am working inside T3 Code, I already run Antigravity alongside Claude Code and Codex over ACP.
Where calling agy -p as a subagent makes sense is inside a standalone terminal session of Claude Code or Codex when I want a fresh pair of eyes from a different model family. Before merging a tricky refactor or shipping a subtle bug fix, I would have Claude Code call the ask-neon skill to review my diff and return structured findings.
It is a poor fit for tiny questions (spawning agy -p adds a few seconds of startup overhead) or for letting another harness drive Gemini turn by turn as a raw completions backend. For multi-turn heavy lifting with Neon, open Antigravity or an ACP client directly. For targeted second opinions and automated review steps inside Claude Code or Codex, agy -p with --output-format json is now clean, fast, and officially inside the rules.
Want me to talk about your product? You can sponsor this site.
Related posts about ai: