Skip to main content
Glama
antigravity-mcp

antigravity-mcp

by khoa-na
README.md
# antigravity skill

A Claude Code **skill** that lets Claude delegate a bounded coding task to the **Google
Antigravity agent** (Gemini via the `agy` CLI) by running `agy -p` as a **background worker**.
There is no server, no MCP configuration, no Python package and no Claude sub-agent in between:
the project is one `SKILL.md` plus prompt templates. The fork-like features come from the `agy`
CLI itself:

| You want | How `agy` gives it |
|---|---|
| Runs while you keep talking to Claude | Bash `run_in_background`; Claude is notified when it exits |
| A clean main context | The brief makes `agy` end with a short (<= 15 lines) report; only that is read |
| Several workers at once | One run per directory or worktree (different directories work in parallel) |
| Isolated changes | `git worktree`: the worker edits a throwaway checkout until you accept it |
| Follow-up with the worker's memory | `--conversation <id>` (the ID is in the JSON result) |
| An independent check | A second, read-only `agy` run on the diff (deny rules enforced by `agy`) |

```text
you ── "ask Antigravity to ..." / /antigravity <task> ──► Claude Code (reads SKILL.md)
                                                            │ writes the brief, then (background):
                    cd <repo or worktree> && agy -p "..." --output-format json --print-timeout ...
                                                            │ short JSON result + completion notice
                                                            ▼
          Claude checks git diff + tests itself, optionally a read-only agy review, then reports
```

## Install

1. Install the Antigravity CLI `agy` and log in once (run `agy` interactively). `agy` must be on
   `PATH`; check with `agy models`.
2. Everything is picked up automatically when Claude Code starts in this repo: the skills in
   `.claude/skills/`, the session-wide guards in `.claude/settings.json` + `.claude/hooks/`, and the
   standing instructions in `CLAUDE.md` (see "Keeping the skills alive for a whole session").
3. Say "ask Antigravity to ..." or type `/antigravity <task>`.

To use it in another project, copy the three skill folders, `.claude/hooks/`, the `hooks` block of
`.claude/settings.json`, and the `CLAUDE.md` section (to `~/.claude/` for every project). Other
harnesses that read `SKILL.md` can reuse the instructions, but hooks are a Claude Code feature;
elsewhere the skill's "always verify yourself" steps are the only safeguard.

## What it does

[`SKILL.md`](.claude/skills/antigravity/SKILL.md) tells Claude how to:

- brief the agent (task, file scope, constraints, acceptance checks, and the short reply format;
  templates in [`references/prompts.md`](.claude/skills/antigravity/references/prompts.md));
- run `agy -p` **in the target repo or worktree**, so it is the agent's working directory, with
  `--output-format json` and an explicit `--print-timeout`, in the background;
- run risky or parallel work in an **isolated `git worktree`**, and bring it back only after review;
- read the JSON result and exit code, and continue with `--conversation <id>` (also after a print
  timeout);
- get a **second opinion**: a separate read-only `agy` run on the diff, enforced by deny rules that
  block every file write and shell command even under `--dangerously-skip-permissions`;
- check the remaining quota with `agy -p "/quota"` (answered by the CLI, no model call). The bucket
  for the configured model is found from the CLI's own output (the model's family name against each
  group's name or model list), so no model names are hard-coded; the lowest bucket in that group
  decides, with go / finish-this-step / stop thresholds and no retry loops on a quota error;
- verify the result itself (`git status`, `git diff`, run the tests) instead of trusting "SUCCESS".

Three hooks (Claude Code only) fire for `agy -p ...` Bash calls. They are bash scripts in
`.claude/hooks/` registered in `.claude/settings.json`, so they are active from the first command of
a session, whether or not a skill was invoked (the same scripts guard the advisor skill: calls that
carry `/advisor-` in the briefing path get the read-only check and the advisor wording). Each script
also re-checks that the command really starts with `agy -p`, because the `if:` filter was seen twice
to let through an unrelated multi-line command, which the guard then wrongly blocked:

- **PreToolUse** blocks a call without `--print-timeout` or `--output-format`. (In a headless test
  it caught the model forgetting `--print-timeout` on its first attempt.)
- **PostToolUse** reminds Claude to inspect the tree; for a call started with `run_in_background`
  it says the run has *not finished* yet. It stays silent for `/quota` and `/usage`.
- **PostToolUseFailure** fires after a non-zero exit (error, print timeout), because such a run may
  have left half-edited files.

Measured (headless, real `agy`, main model Sonnet 5.5): an isolated-worktree task plus a read-only
`agy` review took 19 turns and about $0.30 on the Claude side; the worker needed about 40 s, the main
checkout stayed untouched, and the result matched an independent `git diff` and test run. Here the
main model does the orchestration, so the Claude-side cost depends on which model you run.

A second end-to-end test used the **Gemini 4 Hydrogen** model (`gemini-4-hydrogen-medium`) through the
skill: it built a small module (`textstats.py` with a CLI and 8 unit tests, then a `--min-length`
option and 3 more tests, 30-40 s per run). Every result matched an independent `git diff`, test run
and CLI check, a read-only Hydrogen review approved it, two workers ran in parallel in separate
worktrees, a `--conversation` follow-up remembered its earlier work, and the patch-back and cleanup
recipes worked. The test also caught a real bug in an earlier version of the skill: with
`--add-dir` the worker wrote its files outside the worktree while reporting success; the
independent verification step caught it.

## Keeping the skills alive for a whole session

Claude Code can drop or cut a skill's text when it compacts the conversation, and a skill's own
frontmatter hooks only exist once the skill has been invoked. So the three skills are kept in force by
four layers, each covering what the others cannot:

| Layer | What it keeps | Survives |
|---|---|---|
| `CLAUDE.md` (project root) | Which skills exist, when to use them, the rules that always apply (load the skill with the Skill tool before any `agy -p`, verify, privacy, no `--add-dir`), and the `automatic-advisor` switch | every session start, `--resume`, and compaction (re-read from disk) |
| `.claude/settings.json` + `.claude/hooks/*.sh` | The guards: block `agy -p` without `--print-timeout` / `--output-format`, require the read-only rules on advisor calls, remind Claude to verify | the whole session from its first command, resume, compaction |
| The skill texts (`SKILL.md`) | The full procedures | until compaction; restored by the Skill tool |
| Skill size | Each skill stays well under the 5,000-token budget Claude Code re-attaches after auto-compaction (about 4,650 / 3,300 / 3,350 tokens, estimated from file size; the worker skill is now close to the limit), with the hooks moved out of the frontmatter | auto-compaction (documented, not forced here) |

Tested in real Claude Code sessions: a fresh session knew the three skills and the switch's state from
`CLAUDE.md` without calling any tool; the guard blocked a bare `agy -p` before any skill had been
invoked; after a real `/compact` (46,732 to 7,938 tokens) the guard still blocked, the skill text was
gone (the model said so), and the `CLAUDE.md` rule made it reload the skill with the Skill tool before
running anything, after which it quoted the skill correctly. Not tested: automatic compaction (the
docs say it re-attaches invoked skills, first 5,000 tokens each, 25,000 in total), and `/clear`.

**One agy conversation per directory.** Within a Claude Code session the skills keep `agy`'s memory
instead of starting from zero on every call, and **prime, worker, advisor and `dual-advisor` share one
conversation per absolute directory**, so Gemini keeps what it read. The intended flow: at session start
the `antigravity` skill *primes* the conversation (reads the folder read-only, facts only, while Claude
reads it too); later the same conversation does the coding, and answers as the advisor when a hard
problem comes up. Each call carries its own flags: `--model`/`--effort` and the read-only `--settings`
apply per call, also on resume (tested: the target model's own quota bucket dropped only after the call
that named it, and a write was blocked by deny rules on a conversation that had earlier been allowed
to write). So the worker runs on one model and the advisor on a stronger one in the same conversation.

Limits that follow from the tests: a conversation is bound to the directory it started in, so a
**worktree is a new conversation without the primed context** (prime it again, or work in the main
checkout); only one `agy` process may use a conversation at a time (do not consult the advisor while a
background worker runs on it, a rule, not tested); and the history can colour Gemini's "independent"
opinion (briefs that held Claude's plans), which the `dual-advisor` report states. The IDs and the
flags per role live in `agy-session.json` in the session's scratchpad directory (private to the session,
survives compaction). The rules are written into the `antigravity` and `antigravity-advisor` skills, so
`CLAUDE.md` is optional for this feature; it repeats them so they survive a compaction that drops the
skill text. If you already have your own `CLAUDE.md`, copy just the "One agy conversation per
directory" section into it, or skip it. This is instruction-only, not enforced by a hook, and has not
been tested end to end in a real Claude Code session or across a `/compact`; only the `agy` facts above
were measured.

**Automatic advisor** is a switch in `CLAUDE.md` (`automatic-advisor: off`). Turning it on makes Claude
consult the Antigravity advisor on its own before substantive work and before declaring done. It is
off by default because every consult sends a briefing to Google and spends quota.

Hook scripts must keep LF line endings (`.gitattributes` enforces it); a CRLF checkout breaks bash.

## Choosing the model and reasoning level

Each skill starts with a **Configuration** block, the only place a model name appears in the
instructions:

```text
model:  gemini-4-hydrogen      # the worker skill (the advisor skill ships with gemini-4-argon / high)
effort: medium
ask:    each-use
```

With `ask: each-use` (the shipped setting) the values above are only **suggested defaults**: whenever a
new `agy` conversation starts and your request does not name a model and level, Claude asks you which
to use, for the worker, the advisor and a dual-advisor run alike. Follow-ups in the same conversation
reuse the stored flags without asking again. Set `ask: never` to use the block silently. Headless runs
(nobody to ask) fall back to the defaults. This is instruction-only and has not been run in a real
session yet.

`model` is a family from `agy models` (the ID without its trailing level), a full ID, or `default` for
the model configured in `agy` itself; `effort` is `low` to `max` or `default`. The skill builds
`--model <model> --effort <effort>` from them, so changing models or levels means editing those two
lines and nothing else. You can also name another model in the request for a single run. Verified
with `agy`: a family plus `--effort` works (`gemini-4-argon` + `high`), a full ID plus a different
`--effort` is rejected as a conflict, and a level the model lacks fails with a message listing the
available ones (`gemini-4-argon has no "xhigh" effort (available: low, medium, high)`); the skill
reports that instead of guessing.

## Second skill: `antigravity-advisor`

[`.claude/skills/antigravity-advisor/SKILL.md`](.claude/skills/antigravity-advisor/SKILL.md) uses
Antigravity in the role of Claude Code's built-in *advisor*: a different model gives a second opinion
on a plan, an approach or finished work, at the same three moments (before substantive work, when
stuck, before declaring done). It never edits anything: `--settings` deny rules for `command(*)` and
`write_file(*)` make the run read-only, and a hook refuses an advisor call that lacks them.

Differences from the built-in advisor: it does **not** see the conversation, so Claude writes a short
curated briefing (goal, facts, the plan under review, what worries it, the question, a reply format).
That briefing is sent to Google, so the skill forbids secrets, personal data, raw transcripts and
untrimmed logs, and has Claude say so to the user. It is invoked on the user's request (add a line
to your CLAUDE.md if you want it automatic). Claude then verifies the advisor's claims before
relying on them and, on a conflict with its own evidence, makes one reconcile call with
`--conversation` instead of silently switching.

The advisor checks the matching quota bucket before its first call, keeps its calls few, and offers
a model from another group if its bucket is nearly empty. Its model is whatever the skill's
Configuration block declares (currently `gemini-4-argon`, effort `high`). On the same
question and briefing, Argon high (about 150 s) overlapped Hydrogen high on the main findings and added
two more real bugs that reproduced when run: a newline inside an item name splits the CLI `list` line,
and an item added with quantity 0 can never be removed.

Tested on the finished `inventory` project (33 passing tests, an independent acceptance script and an
earlier review all green): Gemini 4 Hydrogen (high) found four real bugs none of those had caught
(`OverflowError` in `total_value` for a huge quantity, exact duplicate JSON keys silently overwritten,
`-0.0` printed as `-0.00`, unknown JSON keys ignored); all four reproduced when run. A second turn in
the same conversation kept its memory and re-ranked the findings for a single-user CLI. In a fresh
Claude Code session the skill produced a briefing without personal data, ran the advisor read-only
from the repo, verified claims by running code, and reported what it adopted and rejected. The two
skills' hooks do not interfere: each ignores the other's calls (advisor calls carry `/advisor-` in the
briefing path).

## Third skill: `dual-advisor`

[`.claude/skills/dual-advisor/SKILL.md`](.claude/skills/dual-advisor/SKILL.md) is for a hard problem
where you want two different models and one answer: Claude Code's built-in advisor and the Antigravity
advisor each answer **independently** from the same facts (round 0), then **rebut each other for up to
two rounds** (rebuttal 1: each critiques the other's round-0 opinion; rebuttal 2: each answers the
critique of its own position: defend, concede or revise). **If they agree earlier, the skill accepts
it and stops**: after round 0 and after rebuttal 1 it checks for the same decision and the same details
with nothing left open, and skips the remaining rebuttals (the report says so). Claude verifies factual
disputes itself, and
Claude's advisor finally **merges** everything into one recommendation. In each round a side receives
only the other side's text from the previous round. The report ends with a merge ledger (point, source,
kept/changed/dropped, why), what the rebuttals changed, the disagreements that could not be settled,
what was verified, and the caveats. It needs the built-in `advisor` tool (`/advisor <model>`) and the
`antigravity-advisor` skill, and is meant to be used rarely: up to four Claude advisor calls and three
Antigravity calls on a growing conversation (a full run added about 125k input tokens, so the skill
wants the conversation under about 75k first, or a fresh one), and the briefings leave the machine.
Antigravity calls use a 540 s timeout (a round 2 took 242 s of a 300 s limit).

Independence of the first answers is the point of round 0, so the skill enforces an order: a facts-only
briefing, frozen before either answer is read; `advisor()` is called alone in every round and Claude's
answer comes first, then the Antigravity command. "At the same time" is therefore not literal (an
`advisor()` batched with a Bash call returned nothing in a real run), which is safe because each side
only sees the previous round. Claude's advisor reads the whole transcript while Antigravity reads the
briefings and its own conversation history, so the two sources are not symmetric, and the report must
say so. The same applies to a question the session already discussed, which the skill now warns about.
The debate protocol (rounds, shared conversation) was run end to end twice on a throwaway repo; the
early-agreement stop has not been run yet.

First real run, on "how to verify a delegated agent's reports cheaply": the two advisors agreed on the
core (mechanical per-step checks, a hidden boundary corpus, one cross-model review at the end,
nothing slow inside hooks) and each added something the other missed. The comparison also surfaced
two facts neither could check and that were then tested: a `PostToolUse` hook receives the tool's
`tool_response`, and a `Stop` hook can block the first stop and let the second through
(`stop_hook_active`) without looping. The final Antigravity round found three real defects in the
merged plan. The merged protocol is a design; its hooks were not built.

Tested twice by letting a fresh Claude Code session run the skill on its own. The first run broke
three rules, all caused by the skill or its hooks: an `advisor()` call batched with the Antigravity
command returned nothing, so Claude's advisor was called again after it had read Gemini's answer
(not independent); the synthesis request was skipped; and a hook blocked a command that merely wrote
the briefing. After rewording the order (Claude's advisor first, its answer in hand before the
Antigravity command) and anchoring the hooks to commands that start with `agy -p`, the second run
(a new problem: how to package the three skills) kept the order, included the synthesis request,
checked facts itself, ran the Antigravity check round and reported an unverified design as such, for
about 1.25 USD of orchestration. One lesson from fixing the hooks: on Windows Claude Code hands an
inline hook script to bash so that two adjacent backslashes become one, so hook scripts must not
contain `\\` (the first hook rewrite silently did nothing for that reason).

## How `agy -p` behaves (verified)

| | |
|---|---|
| Output | `--output-format json` prints `{conversation_id, status, response, error, finished_reason, usage, ...}` on stdout. |
| Exit codes | `0` success, `1` error (bad model, auth, ...), `2` usage error (no JSON), `3` print timeout (partial response). |
| Timeout | `--print-timeout` defaults to `0`, which waits forever: always pass it. |
| Working directory | The directory you start `agy` in, **unless you pass `--add-dir`**: that re-roots the agent's cwd to the added directory (tested). So the skill never uses `--add-dir`; under `--dangerously-skip-permissions` the agent reads briefs and diffs stored outside the repo anyway. |
| Permissions | Headless mode cannot prompt. In a workspace `agy` does not trust, tool calls are auto-denied and the reply is empty, so tasks need `--dangerously-skip-permissions` (or an allow-rule / a trusted workspace in `~/.gemini/antigravity-cli/settings.json`, which is yours to configure). |
| Deny rules | `--settings '{"permissions":{"deny":["command(*)","write_file(*)"]}}'` still blocks shell commands and every file write/edit **under** `--dangerously-skip-permissions`. Only these two rules were tested. |
| Slash commands | Some run in print mode without a model call: `-p "/quota"` (alias `/usage`) prints the remaining limits. In Git Bash on Windows set `MSYS_NO_PATHCONV=1` or the leading `/` is rewritten into a path. |
| Concurrency | Two runs in different directories at once both succeed, each with its own `conversation_id`. |
| Stopping | Stopping the Claude Code background task killed `agy` and its child process (tested on Windows). On `--print-timeout`, `agy` ends the turn and its background tasks itself and exits 3. |
| Model | Without `--model`, `agy` uses the model configured in its own settings. |
| Resume from another directory | `--conversation <id>` keeps the memory but the conversation stays **bound to the directory it started in**: resumed from `dirB`, a file the agent created landed in `dirA` (tested with the file, not just the agent's answer). Never resume across directories or worktrees. |
| Model and rules on resume | `--model`, `--effort` and `--settings` are per call. Resuming a Flash conversation with `--model gemini-4-argon` dropped Argon's own quota bucket (0.9166 to 0.9065), and a Flash call did not. Deny rules on a resumed conversation blocked a write that an earlier call (without them) had allowed. So one conversation can run a worker and a stronger read-only advisor. |
| Context growth | Input tokens grew 9.5k, 21.7k, 34.6k, 47k over four trivial turns of one conversation. In a full skill test (prime, one worker task, one advisor review, a three-round dual-advisor) the shared conversation went from about 16k to 244k input tokens. `duration_seconds` is cumulative (562, 824, 1081 s) while the calls really took about 130 s and 80 s, so time calls yourself. Skills now say: offer a fresh conversation at about 200k. |

## Compared with typing `agy` yourself

Same agent, same tools, same account and quota, same conversation history. Different: it is
headless and single-turn (it cannot ask you questions mid-run), it runs with permissions
auto-approved, it has a print timeout, and Claude Code, not you, writes the brief and reviews
the result.

## Limits

- **No lock.** Nothing stops two `agy` runs in the *same* repo at once; the skill tells Claude to
  run one at a time per repo. Different repos in parallel are fine.
- **No hard cleanup guarantee.** The tested stop path left nothing behind, but nothing here would
  reap an orphan if the host process itself were killed outright (the old wrapper did this with a
  Windows Job Object). The skill tells Claude to look for strays and ask you.
- **Hooks are Claude Code only.** Other harnesses have their own hook configuration; "always
  verify yourself" in the skill is the portable safeguard.
- **No account rotation** (it relied on a private script this repo never shipped); a quota error is
  reported as is.
- **Not a sandbox.** `--dangerously-skip-permissions` lets the agent run any command and edit any
  file the OS permits. Use a clean `git status` and a restricted environment for untrusted tasks.

## History

Earlier versions were an MCP server (`server.py`), then a Python package with an
`antigravity-agent` CLI that wrapped `agy` (file lock, process-tree cleanup, result record, hooks).
Both are removed: `agy -p --output-format json` now provides the result record, exit codes and
conversation ID itself, starting it in the repo fixes the working directory, `/quota` replaces the
quota command, and deny rules replace the old text-only review backend. To get the old
code back, check out the commit before this change (`git log --oneline -- server.py agy_agent.py`).

A forked variant was also tried and dropped: `context: fork` with a custom Haiku subagent that only
drives `agy` and reports back. It works (about $0.006 on a small task, report matched the real
diff), but it needs a second file, the subagent cannot see the conversation or ask questions, and
hooks declared in a *skill's* frontmatter do not fire inside a fork (they must live in the
subagent's own frontmatter, where they do). The `agy`-native worker pattern above gives the same
isolation and background behavior without a Claude model in the middle.

## License

MIT

TDQS

B3.3/5.0

Scored across 7 tools

Disambiguation4/5

Most tools have clearly distinct purposes: asking the agent, reviewing diffs, generating tests, checking quota, listing models, and health checking. The only overlap is ask-gemini being explicitly documented as an alias for ask-antigravity, so while redundant, it does not create real selection ambiguity.

Naming Consistency5/5

All tools follow a consistent lowercase hyphenated verb-noun pattern: ask-antigravity, review-diff, check-quota, generate-tests, list-models. Even ping fits the simple verb style, and there are no mixed naming conventions.

Tool Count5/5

Seven tools is a well-scoped set for an Antigravity integration. Each tool covers a meaningful capability, and the only minor redundancy is the explicitly marked ask-gemini alias.

Completeness4/5

The server covers the main workflows: invoking the agent, reviewing changes, generating tests, checking quota/model availability, and health checks. Session resume and workspace control are handled through ask-antigravity parameters, so there are no critical gaps, though a dedicated session-management tool could be a potential enhancement.