All guides

The Antigravity PreToolUse hook: allow, deny and force_ask

Updated 27 November 2026 · 6 min read

The PreToolUse hook runs before Google Antigravity uses a tool, such as running a shell command or writing a file, and it is the only hook that can approve or refuse that call. It gets the tool's name and arguments as JSON on stdin and answers with a decision: allow, auto_approve, deny, ask, force_ask or deny_unless_prior_grant. Antigravity is fail-closed, so a PreToolUse hook that prints no decision, crashes, exits non-zero or times out blocks the tool. Always print a decision, {"decision":"allow"} when you have nothing else to say.

01When it fires

PreToolUse fires before each tool call: shell commands, file reads, writes and edits, and Antigravity's questions to you. Antigravity has no separate permission-request event, so this is also the only place a hook can see "Antigravity is about to run a command", whether or not Antigravity would have asked you about it.

02Setting it up

Add the hook to a named group in ~/.gemini/config/hooks.json (or .agents/hooks.json in a project). Tool events wrap their handlers in a matcher entry:

{
  "my-policy": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "/Users/me/bin/agy-policy.py", "timeout": 30 }
        ]
      }
    ]
  }
}

"*" matches every tool. Match everything and check the tool's name in your script: that is reliable, and your script can still answer allow for tools it doesn't care about. The hook runs from the next session, with no trust step.

03What the hook receives

A run_command call, trimmed:

{
  "hookEventName": "PreToolUse",
  "conversationId": "32fc0aec-d58e-47c7-b08c-f489e3a4644a",
  "cwd": "/Users/dev/projects/demo",
  "transcriptPath": "/Users/dev/.gemini/antigravity-cli/brain/32fc0aec-d58e-47c7-b08c-f489e3a4644a/.system_generated/logs/transcript_full.jsonl",
  "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 agy command line sends:

ToolWhat it doesUseful argument
run_commandRuns a shell commandargs.CommandLine
write_fileCreates or overwrites a fileargs.Path
edit_fileChanges part of a fileargs.Path
read_fileReads a fileargs.Path
ask_questionAsks you a question, with optionsargs.questions

Google's docs name write_to_file and replace_file_content. The command line doesn't send those, so check for write_file and edit_file.

04The decisions

Print one JSON object with a decision, and optionally a reason:

DecisionWhat happens
allowThe call goes ahead under Antigravity's own rules, as if no hook had answered. If Antigravity would have asked you, it still asks.
auto_approveThe call runs without Antigravity asking you.
denyThe call is refused. The reason reaches the model word for word, so it can change course.
force_askAntigravity shows its normal approval prompt, with your reason on it.
askListed in Google's docs.
deny_unless_prior_grantListed in Google's docs.

We have tested allow, auto_approve, deny and force_ask on a real agy. ask and deny_unless_prior_grant are documented by Google; check their behaviour on your version before you rely on them.

A deny with a reason the model can use:

{ "decision": "deny", "reason": "Don't push from this machine. Commit and stop; I'll push myself." }

05Always print a decision

This is the part that trips people up. Antigravity blocks the tool when a PreToolUse hook:

  • prints nothing, or prints {}
  • exits with a non-zero code
  • runs past its timeout

So a half-finished script, a missing Python module or a slow network call can stop every command. Write the hook so that every path, including an exception, ends with exit code 0 and a decision. When you're unsure, answer allow: that hands the call back to Antigravity's own permission rules.

06A small policy script

This Python script refuses git push and rm -rf, and allows everything else. It works the same on Mac, Windows and Linux wherever Python 3 is installed.

#!/usr/bin/env python3
# agy-policy.py: a PreToolUse hook for Google Antigravity
import json, sys

def decide(event):
    call = event.get("toolCall") or {}
    if call.get("name") != "run_command":
        return {"decision": "allow"}
    command = (call.get("args") or {}).get("CommandLine", "")
    if "git push" in command:
        return {"decision": "deny", "reason": "Pushing is off for this project. Commit and stop."}
    if "rm -rf" in command:
        return {"decision": "force_ask", "reason": "This deletes files. Please confirm."}
    return {"decision": "allow"}

try:
    answer = decide(json.load(sys.stdin))
except Exception:
    answer = {"decision": "allow"}
print(json.dumps(answer))
sys.exit(0)

Make it executable (chmod +x agy-policy.py on Mac and Linux) and point command at its full path. On Windows, use a command such as python C:\Users\me\bin\agy-policy.py; we haven't tested agy on Windows, so try it on a harmless command first.

The except branch is what keeps a bug from blocking everything. If you'd rather a broken policy refuse risky calls, change that fallback to force_ask, which puts the decision in front of you instead of failing silently.

07Timeouts and long holds

timeout is in seconds, and the default is 30. Antigravity accepted 900, and hooks that held for 45, 200 and 600 seconds completed. A hook that runs past its timeout blocks the tool, so give a hook that waits on something (a person, a network call) a timeout well above the longest wait, and have it answer on its own before then.

While a PreToolUse hook is holding, Antigravity shows no prompt of its own. The screen just says the command is running. If your hook waits for an answer from somewhere else, someone at the keyboard can't step in until it returns. A force_ask after the wait shows the usual prompt, with your reason on it, so they can still decide.

08Questions go through PreToolUse too

When Antigravity wants to ask you something, it calls the ask_question tool, with the questions and options in args.questions (questions can allow several answers). A hook can answer on your behalf by denying the call with the answer as the reason: the model reads the reason and carries on from it. Answering Antigravity's questions from your phone uses exactly this.

09Approving from your phone

Antigravity Notifier's PreToolUse hook holds a run_command while you're away from the keyboard and sends it to your iPhone or Android phone. Allow answers auto_approve; Allow for this session lets that tool through for the rest of the conversation; Deny sends your note as the deny reason. If you don't answer in time, it returns force_ask with "No answer from your phone", so Antigravity's own prompt is waiting when you get back. Read-only tools never wait, nothing waits while you're at the keyboard, and on every error it answers allow. The antigravity-notifier tool is free for Mac, Windows (beta) and Linux; it is independent and not made by Google. See approving Antigravity commands from your phone.

10FAQ

Why did my PreToolUse hook block every command?

It printed nothing, printed {}, exited non-zero or timed out. Antigravity is fail-closed, so each of those blocks the tool. Print {"decision":"allow"} on every path where you have no other answer.

What is the difference between allow and auto_approve?

allow steps aside: Antigravity's own rules decide, so it may still ask you. auto_approve runs the call without asking.

Does --dangerously-skip-permissions skip my hook?

No. Hooks still run with that flag.

What does force_ask do in agy -p?

There is no prompt in print mode, so a force_ask is answered with a denial. A hook that might be used in scripts should not rely on force_ask. See running agy -p in scripts.

Can I match just run_command in hooks.json?

Matching "*" and checking toolCall.name in the script is the approach we've tested. It costs one quick process start per tool call.

Does the deny reason reach the model?

Yes, word for word. Write it as an instruction the model can act on.

Antigravity Notifier Get a push on your phone when Antigravity finishes or needs you, then allow, deny or answer from there. The antigravity-notifier command line tool is free on Mac, Windows and Linux.