cd /news/ai-agents/how-to-call-google-antigravity-agy-p… · home › topics › ai-agents › article
[ARTICLE · art-179227] src=flaviocopes.com ↗ pub= topic=ai-agents verified=true sentiment=· neutral

How to call Google Antigravity (agy -p) as a subagent from Claude Code or Codex

Google's December 1, 2026 rewrite of clause 6 of the Antigravity Terms of Service explicitly permits calling the unmodified `agy` CLI, including `agy -p` headless mode, as a tool or subagent from other coding harnesses such as Claude Code and Codex, according to a guide by Flavio tested with `agy` 1.5.17, Claude Code 2.1.332 and Codex 0.172.0. The guide shows delegating read-only code reviews to Gemini 4 Neon models (`gemini-4-neon-high`, `-medium`, `-low`, plus `gemini-4-hydrogen-low`) via `--model`, `--mode plan`, `--output-format json` and `--print-timeout 120s`, with the JSON envelope returning `conversation_id`, `status`, `response` and `usage`. The rule the guide draws is that Antigravity must run its own agent loop — extracting OAuth tokens or using `agy` as a raw completions proxy to drive another harness's loop still risks suspension, and external harnesses wanting their own loop should use a Gemini API key backed by Google Cloud API credits.

recommendation

Delegate to `agy -p` with `--mode plan` and `--output-format json`, and tell the model not to run shell commands, so the calling agent gets a parseable read-only result.

more in playbook: Designing agent systems
read11 min views13 publishedDec 1, 2026
How to call Google Antigravity (agy -p) as a subagent from Claude Code or Codex
Image: Flaviocopes (auto-discovered)

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_id so you can ask a follow-up question in the same thread later
  • status (SUCCESS orERROR )
  • response with the plain Markdown answer
  • duration_seconds andusage (includingthinking_tokens andcache_read_tokens )
  • denied_actions if 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.
---


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:

1. **Sandboxed Bash breaks `agy`.** Look at Claude Code’s note above: inside a sandboxed shell,`agy` fails because it needs to bind a local port and write state/logs under`~/.gemini/` . In Claude Code, allow`agy` outside the Bash sandbox (or run the command unsandboxed). In Codex, approve escalated execution when it calls`agy` .
2. **`--disable-slash-commands` disables `--mode plan`.** When I passed both flags together,` agy` printed`warning: --mode plan has no effect while slash command expansion is disabled.` Leave`--disable-slash-commands` off when you want plan mode.
3. **Auto-denied shell commands return `"status": "SUCCESS"`.** During my first` gemini-4-neon-medium` run with`--json-schema` , Neon read`remark-pele.mjs` and then tried to run`Bash` to execute the test suite. Headless mode cannot prompt for permission, so it auto-denied the command and exited`0` with`"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 check`denied_actions` before trusting`status` .
4. **120 seconds is too tight for `gemini-4-neon-high`.** My first two` gemini-4-neon-high` runs with`--print-timeout 120s` hit the deadline and exited with code`3` (`DEADLINE_EXCEEDED` ). When it succeeded, it took 113.08 seconds and used 9,787 thinking tokens. Use`gemini-4-neon-low` (33s) or`gemini-4-neon-medium` (51s) by default, and give`neon-high` at least`--print-timeout 300s` .

## How I would use this in my own workflow

When I am working inside [T3 Code](https://flaviocopes.com/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](https://flaviocopes.com/sponsor/).
── more in #ai-agents 4 stories · sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/how-to-call-google-a…] indexed:0 read:11min 2026-12-01 · —