Home › Rules › Antigravity hooks
Antigravity hooks: where hooks.json goes, the six events, copy-paste examples and fixes
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:
| Where | Project hooks | Hooks for every project | See or manage them | <app_data_dir> in payloads |
|---|---|---|---|---|
| Antigravity App | .agents/hooks.json in the workspace root | ~/.gemini/config/hooks.json | Plugin 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 plugin | hooks.json at the plugin's root folder (not hooks/hooks.json) | Turn the plugin on or off | Same 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.
| Event | Fires | Matcher | What your script can send back |
|---|---|---|---|
SessionStart | Once, when a new conversation starts, before the first model call | Ignored | injectSteps to add starting context |
PreToolUse | Before a tool runs | Tool name (regex) | A decision (required), a reason, overwrite to change the tool's arguments, permissionOverrides |
PostToolUse | After a tool finishes | Tool name (regex) | Nothing: return {}. It gets the call and any error, not the tool's output |
PreInvocation | Before each model call | Ignored | injectSteps, or terminationBehavior: "terminate" to stop the turn |
PostInvocation | Right after each model call | Ignored | injectSteps, plus "force_continue" or "terminate" |
Stop | When the loop is about to end | Ignored | decision: "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:
- Shell:
run_command(the command is inCommandLine),manage_task,schedule. - Writing files:
write_to_file,replace_file_content,multi_replace_file_content(the path is inTargetFile). - Reading and searching:
view_file,list_dir,find_by_name,grep_search,search_web,read_url_content. - Agents and permissions:
invoke_subagent,define_subagent,send_message,manage_subagents,list_permissions,ask_permission. - Other:
ask_question,generate_image.
PreToolUse decisions
This is the hook that can stop things. Your script prints one of six decisions:
| Decision | What happens |
|---|---|
allow | Lets the call go on to the next hook or the normal permission check |
auto_approve | Approves it where you'd normally be asked, but still follows rules you set yourself |
deny | Blocks it right away |
ask | Asks you, but an "Always Allow" you gave earlier still counts |
force_ask | Always asks you, ignoring saved permissions |
deny_unless_prior_grant | Blocks 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:
- Tool hooks get
toolCall.name,toolCall.argsandstepIdx;PostToolUsealso getserrorif the tool failed. - Model hooks get
invocationNum(starting at 0) andinitialNumSteps. - Stop gets
executionNum,terminationReason(for examplemodel_stopormax_steps_exceeded),errorandfullyIdle, which is false while background commands are still running.
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.
{
"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 }
]
}
}
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.
Free. No spam. Unsubscribe anytime. See our privacy note.
The tests hook starts with "enabled": false so nothing surprises you. Flip it to true once npm test passes on its own.
#!/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
#!/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
#!/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:
# 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
- Plugins. A plugin keeps its hooks in
hooks.jsonat its root. The commands run with the plugin's folder as the working directory, and Google's build guide says to use relative paths likenode ./scripts/policy.mjs. Runagy plugin validatebefore you share one; it checks hooks.json for bad JSON, unknown events, matchers that aren't valid regular expressions and missing scripts. Plugin hooks only run while the plugin is turned on (CLI 1.1.7 fixed disabled plugins still running theirs). - Custom agents. Since App 2.17.0 (Sep 22, 2026), a Markdown custom agent can list hook files in its front matter with a
hooks:entry, as paths relative to the agent, the project, or absolute.inheritCustomizationsdecides whether a plugin's agent also picks up your workspace's skills, rules and hooks. - Coming from Claude Code.
agy plugin import claudecopies plugins from~/.claude/plugins/. Since CLI 1.5.5 it convertsPreToolUse,PostToolUse,Stopand startupSessionStarthooks, maps tool names (for exampleBashtorun_command), gives them a 60-second timeout, and lists anything it couldn't convert as a warning. For writing hooks by hand in each tool, see Claude Code hooks examples, Cursor hooks and Kiro hooks. - Not the same thing: Google's SDK docs have a "Lifecycle and hooks" page. That's for the Python SDK (decorators like
@hooks.pre_turn), nothooks.json.
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.
| Date | Version | What changed |
|---|---|---|
| Jun 12, 2026 | CLI 1.0.8 | /hooks writes to the shared ~/.gemini/config/hooks.json instead of a CLI-only file |
| Aug 3, 2026 | CLI 1.1.10 | Your hooks run before the built-in end-of-turn checks, so Stop hooks actually run |
| Aug 7, 2026 | App 2.6.0 | Hooks that could never run are rejected at load with an error; a Stop hook that keeps blocking no longer hangs the turn |
| Aug 20, 2026 | Extensions 1.0.0 | Editor extensions load hooks.json; project hooks wait until you trust the workspace |
| Sep 2, 2026 | App 2.12.0 | A failing hook is reported as an error instead of ending the session |
| Sep 22, 2026 | App 2.17.0 | Custom agents can list hooks in front matter (hooks:) |
| Oct 24, 2026 | CLI 1.4.7 | lastUserInput added, so a hook can check your prompt (App 2.28.0, Oct 27) |
| Oct 30, 2026 | CLI 1.4.11 | PreInvocation can stop a turn and show you an error message |
| Nov 7, 2026 | CLI 1.5.3 | PLUGIN_ROOT and PLUGIN_DATA set for plugin hook commands |
| Nov 10, 2026 | CLI 1.5.4 | hookEventName, cwd and toolCall.id in the input |
| Nov 11, 2026 | CLI 1.5.6 | continuation_active on Stop hooks |
| Nov 13 / 17, 2026 | CLI 1.5.8, App 2.33.0 | Windows: hooks.json saved with a byte order mark, and commands with double quotes, no longer silently skipped |
Fixes for hooks that don't work
- Hooks in settings.json do nothing. The CLI never loads them. Move them to
~/.gemini/config/hooks.jsonor.agents/hooks.json. - A plugin's hooks never run.
hooks/hooks.jsonisn't read in an Antigravity plugin. Puthooks.jsonat the plugin root, or runagy plugin import(CLI 1.5.5 converts Claude-style hooks). - 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
denyJSON and exit 0. For aPostToolUsehook, CLI 1.4.3 stopped a broken hook from marking a good tool call as failed. - The matcher never fires. Use Antigravity's tool names (
run_command, notBash) and a valid regular expression.agy plugin validatewarns about both inside plugins. - 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.
- 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.
- The agent keeps going around in circles. A Stop hook that always says
continueused to hang the agent. App 2.6.0 and CLI 1.1.9 now end the turn after repeated blocks. In the CLI, checkcontinuation_activelike our Stop example does. - The hook times out. The default is 30 seconds. Set
timeouthigher for slow jobs like a test run. /hooksdoesn'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.- 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
- Hook types. The hooks page says only
"command"is supported. The plugins and build plugins pages describe hooks as "shell commands or prompt evaluations", and the changelog mentions hooks that call a model (App 2.6.0) and prompt hooks (CLI 1.1.23). - Input fields. The hooks page doesn't list
hookEventName,cwd,toolCall.idorcontinuation_active, which the CLI changelog added in 1.5.4 and 1.5.6. PLUGIN_ROOTin hook commands. The build plugins page says to use relative paths rather than${PLUGIN_ROOT}. CLI 1.5.3 setsPLUGIN_ROOTandPLUGIN_DATAfor plugin hooks, and 1.5.6 warns that older CLI versions don't. Relative paths work either way.- Which events a plugin can use. The plugins page names four (
PreToolUse,PostToolUse,SessionStart,Stop). The build plugins page lists all six. - Letting the agent stop. The hooks page says
decisionis required on Stop. The build plugins page says return{}to allow the stop. Our example prints a decision, which fits both. systemMessageshape. The field list calls it an object but shows a plain string inside it; theSessionStartexample nests asystemMessageinside another one.edit_file. The build plugins example matchesrun_command|edit_file, but Google's tool list has noedit_file. The edit tools arewrite_to_file,replace_file_contentandmulti_replace_file_content.- Hooks in custom agents. The 2.17.0 changelog adds a
hooks:front matter entry, but the custom subagents page's field table doesn't list it.
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
- Google Antigravity plugins (install, marketplace, plugin vs skill)
- Google Antigravity subagents (custom agents, agents folder, examples)
- Google Antigravity MCP (mcp_config.json location, MCP Store, Figma, GitHub, fixes)
- Google Antigravity rules (examples, triggers, where the files go)
- Antigravity CLI vs Gemini CLI (who uses which, commands, settings, how to switch)
- Antigravity Agent Manager (now the Antigravity App) (where it went in 2.0, shortcuts, plans, fixes)
- Antigravity permissions and sandbox (presets, allow and deny rules, Turbo, sandbox fixes)
- Claude Code hooks examples (7 copy-paste hooks, plus Cursor)
- Cursor hooks (hooks.json, every event, examples, fixes)
- Kiro hooks (.kiro/hooks JSON, every trigger, exit codes, examples)
- Vibe coding security checklist (12 checks before you launch)
- Free rules file generator
Sources
- Google Antigravity docs: Hooks
- Google Antigravity docs: Plugins
- Google Antigravity docs: Build plugins
- Google Antigravity docs: Customization discovery
- Google Antigravity docs: Settings (CLI)
- Google Antigravity docs: Custom subagents
- Google Antigravity docs: CLI command reference
- Google Antigravity docs: SDK lifecycle and hooks
- Google Antigravity changelog
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.