Antigravity hooks are commands that Google Antigravity runs at fixed points in a session: when a session starts, before and after the model is invoked, before and after a tool runs, and when a turn ends. You define them in ~/.gemini/config/hooks.json for every project, or in .agents/hooks.json inside one project. Each hook gets JSON about the event on stdin and can answer with JSON on stdout, which lets it log, notify, allow or deny a tool call, or start a new turn. There is no trust step, but there is one rule that catches people out: a PreToolUse hook must always print a decision, or Antigravity blocks the tool.
01Where hooks live
Antigravity reads two files, and both load:
~/.gemini/config/hooks.json, read by the agy command line, the desktop app and the IDE.agents/hooks.json in the project folderWhen both files have a hook for the same event, both run, the project's first. A project file adds to the global one rather than replacing it. Where is Antigravity's hooks.json? covers the paths in more detail.
02No trust step
A hook you add to the global file runs from the next session. You don't review or approve it first, and it runs even in a workspace you haven't marked as trusted. That makes hooks easy to set up, and it also means anything that can write to ~/.gemini/config/hooks.json can run commands in every future session. Treat the file like a shell startup file.
A session that is already open keeps the hooks it started with. Start a new session after you edit the file.
03The shape of hooks.json
The top level of the file is a set of named groups. Each group holds events, and each event holds a list of handlers. A group is just a name you choose, so several tools can keep their hooks in one file without stepping on each other:
{
"my-alerts": {
"Stop": [
{ "type": "command", "command": "/Users/me/bin/agy-done.sh", "timeout": 10 }
],
"PreToolUse": [
{
"matcher": "*",
"hooks": [
{ "type": "command", "command": "/Users/me/bin/agy-pretool.py", "timeout": 30 }
]
}
]
}
}
- Groups. Every group whose event matches runs. Two groups with a
Stophook both fire. - Tool events (
PreToolUse,PostToolUse) wrap their handlers in amatcherentry."*"matches every tool. The simplest way to act on one tool is to match"*"and checktoolCall.namein your script. - Other events (
SessionStart,PreInvocation,PostInvocation,Stop) take the handlers directly. timeoutis in seconds. The default is 30. Values up to 900 have been accepted, and hooks that held for 45, 200 and 600 seconds completed.commandis run as a command line. Use a full path to your script.
04Every event and what it is for
SessionStartA session startsStart a log, check setupPreInvocationBefore the model is invokedNotice a new promptPostInvocationAfter the model is invokedLoggingPreToolUseBefore a tool runsAllow, deny or ask about a command or file changePostToolUseAfter a tool ranCount changes, run checksStopA turn ends"Finished" alerts, start another turnThat is the whole list. Antigravity has no notification event, no permission-request event, no prompt-submit event and no session-end event. If you come from Claude Code or Codex, this is the big difference: "Antigravity wants to run a command" can only be seen from PreToolUse, and "finished" comes from Stop.
05What a hook receives
Every hook gets one JSON object on stdin. The keys are camelCase. These were measured on agy 1.5.18 and differ from Google's documentation in places:
- All events:
hookEventName,cwd,conversationId,transcriptPath,lastUserInput. PreToolUseandPostToolUse:toolCall, withname,argsandid.Stop:terminationReason,fullyIdle,executionNumandcontinuationActive.
A trimmed PreToolUse payload for a shell command looks like this:
{
"hookEventName": "PreToolUse",
"conversationId": "32fc0aec-d58e-47c7-b08c-f489e3a4644a",
"cwd": "/Users/dev/projects/demo",
"lastUserInput": "Run the shell command 'echo first-step' and tell me what it printed.",
"toolCall": {
"name": "run_command",
"args": { "CommandLine": "echo first-step" },
"id": "call_18357403015624551586"
}
}
The tool names the command line sends are run_command (the command is in args.CommandLine), write_file, edit_file, read_file and ask_question. Google's docs mention write_to_file and replace_file_content, but those are not what agy sends, so a script that checks for them never matches.
06Answering: PreToolUse decisions
A PreToolUse hook answers with a decision:
{ "decision": "deny", "reason": "Not on the main branch, please." }
The decisions are allow, auto_approve, deny, ask, force_ask and deny_unless_prior_grant. A deny reason reaches the model word for word, so it can adjust and try something else. force_ask shows Antigravity's normal approval prompt, with your reason on it. The PreToolUse guide goes through each one.
07Fail-closed: the rule that blocks tools
Antigravity is fail-closed. A PreToolUse hook that prints no decision, prints {}, exits with a non-zero code or runs past its timeout blocks the tool. A typo in a script can stop every command Antigravity tries to run.
So a PreToolUse hook should always exit 0 and always print a decision. When it has nothing to say, print {"decision":"allow"}, which leaves the call to Antigravity's own permission rules, as if the hook weren't there. Wrap the work in error handling so a crash still ends in that line.
08Answering: Stop
A Stop hook can start another turn by answering {"decision":"continue","reason":"..."}. Antigravity treats the reason as the next instruction. continuationActive stays false afterwards, so a hook that always continues loops. The Stop hook guide shows how to guard against that, and how to read Antigravity's last message, which is not in the payload.
09Hooks for notifications
- For "Antigravity has finished", use
Stop. See how to get a notification when Antigravity finishes. - For "Antigravity wants to run something", use
PreToolUseonrun_command, and always print a decision.
Antigravity Notifier is built on these hooks. antigravity-notifier pair adds one named group, antigravity-notifier, to ~/.gemini/config/hooks.json with SessionStart, PreInvocation, PreToolUse, PostToolUse and Stop hooks, keeps a one-time backup of the file, refuses to touch a file that isn't valid JSON, and leaves every other group alone. Its PreToolUse hook always prints a decision. It runs on Mac, Windows (beta) and Linux and sends the moments that need you to an iPhone or Android app. It is independent and not made by Google, and it supports the agy command line; the desktop app and IDE read the same file but aren't supported yet.
10FAQ
Do I need to restart Antigravity after editing hooks.json?
Start a new session. A global hook runs from the next session; one that is already open was set up before your edit.
Why did my hook block every command?
It is almost always a PreToolUse hook that crashed, timed out, exited non-zero or printed nothing. Antigravity treats all of those as a "no". Make it print {"decision":"allow"} on every path where it has no other answer.
Do project hooks replace my global hooks?
No. Both files load and both fire, the project's first.
Does --dangerously-skip-permissions turn hooks off?
No. Hooks still run with that flag.
Do hooks run in agy -p?
Yes, project and global hooks load in print mode too. A force_ask there is answered with a denial, because nobody is at a prompt. See running agy -p in scripts.
Do the desktop app and IDE use the same hooks?
They read the same ~/.gemini/config/hooks.json. We have only tested hook behaviour in the agy command line, so check anything you rely on in the desktop app or IDE yourself.