Home › Rules › Antigravity hooks

Antigravity hooks: where hooks.json goes, the six events, copy-paste examples and fixes

From Google's Antigravity docs (hooks, plugins, build plugins, customization discovery, CLI settings) and the Antigravity changelog, checked Nov 21, 2026. Sources below.

Short answer: Antigravity hooks are your own scripts that Antigravity runs at set points: when a conversation starts, before and after each tool call, before and after each model call, and when the agent is about to stop. You list them in one file, .agents/​hooks.​json for a project or ~/.gemini/​config/​hooks.​json for all of them, and the App, the CLI and the IDE all read it. Each script gets JSON on stdin and answers with JSON on stdout. A PreToolUse hook can allow, deny or ask about a tool call before it runs.

Two things trip people up most, so here they are up front. In the CLI, hooks put in settings.​json are never loaded. And a hook script that crashes or exits with a non-zero code is logged and ignored, so a safety check that breaks lets everything through. The rest of this page covers where the file goes, all six events, what your script receives and can send back, plugin and custom agent hooks, four examples you can copy, and fixes with version numbers.

Where hooks.json goes

The same file format works everywhere. Only where you manage it changes:

WhereProject hooksHooks for every projectSee or manage them<app_​data_​dir> in payloads
Antigravity App.agents/​hooks.​json in the workspace root~/.gemini/​config/​hooks.​jsonPlugin hooks under Customizations → Installed~/.gemini/​antigravity
Antigravity CLI (agy).agents/​hooks.​json at the project root~/.gemini/​config/​hooks.​json (not settings.​json)Type /hooks to list, add, edit and turn hooks on or off~/.gemini/​antigravity-cli
Antigravity IDE.agents/​hooks.​json in the open project~/.gemini/​config/​hooks.​json… → Customizations → Hooks in the agent side panel~/.gemini/​antigravity-ide
Inside a pluginhooks.​json at the plugin's root folder (not hooks/​hooks.​json)Turn the plugin on or offSame as the app it runs in

Google's settings page adds that the CLI's /hooks saves new hooks to the global file, and that the CLI keeps a hooks key in settings.​json but never loads it. If your hooks lived in settings.​json before, that's the first thing to move. Custom agents can also carry their own hooks (more on that below).

The six hook events

Each top-level key in hooks.​json is a name you pick (like guard-commands). Inside it go one or more events. PreToolUse and PostToolUse wrap their handlers in a matcher plus a hooks list; the other four take a plain list of handlers.

EventFiresMatcherWhat your script can send back
SessionStartOnce, when a new conversation starts, before the first model callIgnoredinjectSteps to add starting context
PreToolUseBefore a tool runsTool name (regex)A decision (required), a reason, overwrite to change the tool's arguments, permissionOverrides
PostToolUseAfter a tool finishesTool name (regex)Nothing: return {}. It gets the call and any error, not the tool's output
PreInvocationBefore each model callIgnoredinjectSteps, or terminationBehavior: "terminate" to stop the turn
PostInvocationRight after each model callIgnoredinjectSteps, plus "force_​continue" or "terminate"
StopWhen the loop is about to endIgnoreddecision: "continue" plus a reason keeps the agent working; any other value lets it stop

Each handler has three fields: type (only "command" today, and that's the default), command (required) and timeout in seconds (default 30). Put "enabled": false on a named hook to turn it off without deleting it.

Matchers and tool names

The matcher is a regular expression on the tool name. "" or "*" matches every tool, "run_​command|view_​file" matches either one, and "browser_.*" matches every tool whose name starts with browser_. The names are Antigravity's own, so a Claude Code habit like Bash won't match anything. The ones you'll use most, from Google's list:

PreToolUse decisions

This is the hook that can stop things. Your script prints one of six decisions:

DecisionWhat happens
allowLets the call go on to the next hook or the normal permission check
auto_​approveApproves it where you'd normally be asked, but still follows rules you set yourself
denyBlocks it right away
askAsks you, but an "Always Allow" you gave earlier still counts
force_​askAlways asks you, ignoring saved permissions
deny_​unless_​prior_​grantBlocks it unless you approved that resource before

overwrite merges new values into the tool's arguments before it runs (top-level keys only), and the agent sees a note naming the keys you changed. One limit worth knowing: CLI 1.5.7 and App 2.33.0 fixed auto_​approve getting around a company's admin-enforced review, so on a managed account it can't skip those prompts. The allow, ask and deny rules a hook works alongside are in Antigravity permissions.

What your script receives

Input comes as JSON on stdin, output goes as JSON on stdout, and field names are camelCase. Every hook gets conversationId, workspacePaths, transcriptPath (the conversation log, a transcript.​jsonl file), artifactDirectoryPath, modelName and lastUserInput, your latest message. On top of that:

The changelog lists a few more fields the hooks page doesn't show yet: hookEventName, cwd and toolCall.​id (CLI 1.5.4, Nov 10), so one script can handle several events and pair a PostToolUse with its PreToolUse; and continuation_​active on Stop (CLI 1.5.6, Nov 11).

The steps you can inject are systemMessage, userMessage, ephemeralMessage (a passing note) and errorMessage, which shows you a message without sending it to the model. Pair errorMessage with "terminationBehavior": "terminate" in PreInvocation to block a prompt; in a -p run that also makes agy exit with a non-zero code.

Four hooks you can copy

These are our examples, built only from the fields above. Save the JSON as .agents/​hooks.​json, put the scripts in a scripts folder in the project, and install jq. Google's own examples use paths like ./scripts/​lint.​sh. For plugin hooks Google says the command runs in the plugin's folder; for your own .agents/​hooks.​json the docs don't say where relative paths start, so if a hook never fires, try the full path.

Our example (VibeKits): .agents/hooks.json
{
  "guard-commands": {
    "PreToolUse": [
      {
        "matcher": "run_command",
        "hooks": [
          { "type": "command", "command": "./scripts/guard-commands.sh", "timeout": 10 }
        ]
      }
    ]
  },
  "format-after-edit": {
    "PostToolUse": [
      {
        "matcher": "write_to_file|replace_file_content|multi_replace_file_content",
        "hooks": [
          { "type": "command", "command": "./scripts/format-file.sh", "timeout": 30 }
        ]
      }
    ]
  },
  "tests-before-done": {
    "enabled": false,
    "Stop": [
      { "type": "command", "command": "./scripts/tests-before-done.sh", "timeout": 120 }
    ]
  }
}

The tests hook starts with "enabled": false so nothing surprises you. Flip it to true once npm test passes on its own.

Our example (VibeKits): scripts/guard-commands.sh (PreToolUse)
#!/bin/bash
# Antigravity PreToolUse hook: block or double-check a few risky shell commands.
# Reads the hook JSON on stdin, prints a decision as JSON on stdout.
# Always exit 0: Google's docs say a non-zero exit is logged and ignored,
# which means the command would just run.
input=$(cat)
cmd=$(printf '%s' "$input" | jq -r '.toolCall.args.CommandLine // ""')

case "$cmd" in
  *"rm -rf"*|*"git push --force"*|*"git push -f"*|*"DROP TABLE"*|*"drop table"*)
    jq -cn --arg r "Blocked by the guard-commands hook: $cmd" '{decision: "deny", reason: $r}'
    ;;
  *"git push"*)
    jq -cn '{decision: "force_ask", reason: "Pushing to a remote. Check the branch first."}'
    ;;
  *)
    echo '{"decision": "allow"}'
    ;;
esac
exit 0
Our example (VibeKits): scripts/format-file.sh (PostToolUse)
#!/bin/bash
# Antigravity PostToolUse hook: format the file the agent just saved, with Prettier.
# PostToolUse gets the tool call and any error, not the tool's output.
input=$(cat)
file=$(printf '%s' "$input" | jq -r '.toolCall.args.TargetFile // ""')
err=$(printf '%s' "$input" | jq -r '.error // ""')

if [ -n "$file" ] && [ -z "$err" ] && [ -f "$file" ]; then
  case "$file" in
    *.ts|*.tsx|*.js|*.jsx|*.json|*.css|*.html|*.md)
      npx --no prettier --log-level silent --write "$file"
      ;;
  esac
fi
echo '{}'
exit 0
Our example (VibeKits): scripts/tests-before-done.sh (Stop)
#!/bin/bash
# Antigravity Stop hook: don't let the agent call it done while tests fail.
input=$(cat)

# CLI 1.5.6+ sends continuation_active=true when an earlier Stop hook already
# sent the agent back to work. Let it stop then, so it can't loop.
if [ "$(printf '%s' "$input" | jq -r '.continuation_active // false')" = "true" ]; then
  echo '{"decision": "stop"}'
  exit 0
fi

dir=$(printf '%s' "$input" | jq -r '.workspacePaths[0] // empty')
[ -n "$dir" ] && cd "$dir"

if npm test >/tmp/agy-stop-tests.log 2>&1; then
  echo '{"decision": "stop"}'
else
  echo '{"decision": "continue", "reason": "npm test is failing. Read /tmp/agy-stop-tests.log, fix the failures, then finish."}'
fi
exit 0

Run the guard once yourself before relying on it:

Our example (VibeKits): test the guard, then check it loaded
# make the scripts runnable (they need jq installed)
chmod +x scripts/*.sh

# feed the guard a fake PreToolUse payload, same shape as Google's example
echo '{"toolCall":{"name":"run_command","args":{"CommandLine":"rm -rf build"}}}' | ./scripts/guard-commands.sh
# prints: {"decision":"deny","reason":"Blocked by the guard-commands hook: rm -rf build"}

# then, inside agy, check that Antigravity loaded them
/hooks

Hooks in plugins and custom agents

How hooks changed, by date

Every row is from Google's changelog. Hooks got a lot of fixes this year, so if a hook acts strange, update first.

DateVersionWhat changed
Jun 12, 2026CLI 1.0.8/hooks writes to the shared ~/.gemini/​config/​hooks.​json instead of a CLI-only file
Aug 3, 2026CLI 1.1.10Your hooks run before the built-in end-of-turn checks, so Stop hooks actually run
Aug 7, 2026App 2.6.0Hooks that could never run are rejected at load with an error; a Stop hook that keeps blocking no longer hangs the turn
Aug 20, 2026Extensions 1.0.0Editor extensions load hooks.​json; project hooks wait until you trust the workspace
Sep 2, 2026App 2.12.0A failing hook is reported as an error instead of ending the session
Sep 22, 2026App 2.17.0Custom agents can list hooks in front matter (hooks:)
Oct 24, 2026CLI 1.4.7lastUserInput added, so a hook can check your prompt (App 2.28.0, Oct 27)
Oct 30, 2026CLI 1.4.11PreInvocation can stop a turn and show you an error message
Nov 7, 2026CLI 1.5.3PLUGIN_​ROOT and PLUGIN_​DATA set for plugin hook commands
Nov 10, 2026CLI 1.5.4hookEventName, cwd and toolCall.​id in the input
Nov 11, 2026CLI 1.5.6continuation_​active on Stop hooks
Nov 13 / 17, 2026CLI 1.5.8, App 2.33.0Windows: hooks.json saved with a byte order mark, and commands with double quotes, no longer silently skipped

Fixes for hooks that don't work

  1. Hooks in settings.json do nothing. The CLI never loads them. Move them to ~/.gemini/​config/​hooks.​json or .agents/​hooks.​json.
  2. A plugin's hooks never run. hooks/​hooks.​json isn't read in an Antigravity plugin. Put hooks.​json at the plugin root, or run agy plugin import (CLI 1.5.5 converts Claude-style hooks).
  3. Your block didn't block. Google's build plugins page says a non-zero exit is logged and ignored ("failing open"), and since App 2.12.0 a failing hook is reported as an error while the conversation carries on. Print the deny JSON and exit 0. For a PostToolUse hook, CLI 1.4.3 stopped a broken hook from marking a good tool call as failed.
  4. The matcher never fires. Use Antigravity's tool names (run_​command, not Bash) and a valid regular expression. agy plugin validate warns about both inside plugins.
  5. hooks.json ignored on Windows. Save it as UTF-8 without a byte order mark, or update: App 2.33.0 and CLI 1.5.8 fixed it, plus commands with quoted paths.
  6. Project hooks missing after you trust the folder. CLI 1.1.1 fixed workspace hooks not loading after trusting a folder. The editor extensions also wait for workspace trust before loading project hooks.
  7. The agent keeps going around in circles. A Stop hook that always says continue used to hang the agent. App 2.6.0 and CLI 1.1.9 now end the turn after repeated blocks. In the CLI, check continuation_​active like our Stop example does.
  8. The hook times out. The default is 30 seconds. Set timeout higher for slow jobs like a test run.
  9. /hooks doesn't show a plugin's hooks. Fixed in CLI 1.2.3. A disabled plugin's hooks still running was fixed in 1.1.7.
  10. Hooks see the wrong model name. With a custom model, hooks got an empty or placeholder name until CLI 1.5.3.

Where the docs disagree

FAQ

Does Google Antigravity have hooks?

Yes. Google's hooks page says hooks run your own scripts or shell commands at set points in Antigravity's loop, to enforce rules, run linters or capture diagnostics. They work in the Antigravity App, the Antigravity CLI, the Antigravity IDE and the editor extensions, and all of them read the same hooks.json file.

Where does hooks.json go in Antigravity?

For one project, .agents/hooks.json at the project root. For every project, ~/.gemini/config/hooks.json. Plugins can bring their own hooks.json at the plugin's root folder. In the CLI, hooks put in ~/.gemini/antigravity-cli/settings.json are not loaded.

Why are my Antigravity hooks not running?

Check five things: the file is in .agents/ or ~/.gemini/config/ and not in settings.json; the JSON is valid and, on Windows, saved without a byte order mark (App 2.33.0 and CLI 1.5.8 fixed that); the matcher uses Antigravity's tool names such as run_command, not Claude Code's Bash; the hook isn't set to enabled: false; and the folder is trusted. Then type /hooks in the CLI to see what loaded.

How do I block a command with an Antigravity hook?

Add a PreToolUse hook with the matcher run_command. Your script reads the command from toolCall.args.CommandLine on stdin and prints {"decision": "deny", "reason": "..."} on stdout. Exit with code 0, because Google's docs say a non-zero exit is logged and ignored, so the command would run anyway.

Can I use my Claude Code hooks in Antigravity?

Partly. agy plugin import claude brings in Claude Code plugins, and since CLI 1.5.5 it converts PreToolUse, PostToolUse, Stop and startup SessionStart hooks, maps tool names like Bash to run_command and gives them a 60-second timeout. Hooks with no match are listed as warnings. A plugin's hooks/hooks.json file isn't read; Antigravity wants hooks.json at the plugin root.

What's the difference between hooks and rules in Antigravity?

Rules are instructions the agent reads and should follow. Hooks are scripts Antigravity itself runs at fixed points, like before a tool call or before the agent stops, so they still fire if the agent forgets a rule. A PreToolUse hook can deny a command outright.

Related setups

Hooks often ride in a plugin, so Google Antigravity plugins covers installing and turning them on and off. Custom agents with their own hooks are in Google Antigravity subagents. If you're moving from the terminal tools, Antigravity CLI vs Gemini CLI covers the settings move, and the same idea in other tools is in Claude Code hooks examples, Cursor hooks and Kiro hooks.

Next step for Antigravity: Agent Skills

Skills are folders your AI coding agent loads only when the job comes up, and Claude Code, Cursor and OpenAI Codex all read the same SKILL.md format. The Vibe Coder Skills Pack ($9) is 6 ready-to-copy SKILL.md skills (fix-one-bug, stop-the-loop, leak-check, ship-check, explain-project, builder-handoff) for Claude Code, Cursor and OpenAI Codex. Also included in the 6-kit bundle.

Get the Skills Pack for $9 on Gumroad → See what's inside

One .zip of skill folders plus one markdown file. 7-day refund, no questions asked.

Best value

All 6 kits for $29 — or $20.30 with code WELCOME30 (through Nov 30)

Hooks keep the agent in line. The kits tell it what to build, step by step: a small game, a Discord bot, an email-triage agent, an MVP, or a cleanup of messy code.

Get all 6 kits for $29 → See what's in each kit

$29 instead of $48 for the six kits bought separately; WELCOME30 takes 30% off that at checkout ($20.30). Instant download from Gumroad. 7-day refund, no questions asked.

Related

Sources

Every file path, field name, event, version number and date here was checked Nov 21, 2026 on Google's own Antigravity docs and changelog. Antigravity ships updates every few days and hooks have changed a lot since July, so check the linked pages if something doesn't match.

Free rules starter pack for Cursor, Claude Code, Codex and Antigravity

One shared AGENTS.md that works across Cursor, Claude Code, Codex, Copilot and Antigravity, plus database and test rules in each tool's format. Unzip it into your project and fill in two sections. I'll email you the link.

After that, an occasional email when I publish a new guide or rules file.

Free. No spam. Unsubscribe anytime. See our privacy note.