All guides

Running agy -p in scripts and CI without stalling

Updated 27 November 2026 · 5 min read

agy -p runs Google Antigravity on one prompt and exits, which makes it the way to use Antigravity in scripts, cron jobs and CI. Nobody is at a prompt in print mode, so anything that would normally ask you can't be answered: a PreToolUse hook that returns force_ask gets a denial, and the tool doesn't run. Your global and project hooks still load. To keep a scripted run from stalling or failing, make sure no hook waits for a person or asks for confirmation when it runs under agy -p, and that every PreToolUse hook prints a decision quickly.

01What changes in print mode

agy -p "Update the changelog for the last three commits"

Compared with an interactive session:

  • There is no prompt. A force_ask from a hook is answered with a denial, and the tool doesn't run.
  • Hooks still run. Both ~/.gemini/config/hooks.json and the project's .agents/hooks.json load, the same as in an interactive session.
  • Fail-closed still applies. A PreToolUse hook that prints nothing, crashes, exits non-zero or times out blocks the tool, here as anywhere.
  • --dangerously-skip-permissions doesn't skip hooks. If you use that flag in a sandboxed CI job, your hooks still decide.

Interactive sessions start in Auto mode, where sandboxed "safe" commands run without asking. We haven't measured exactly which commands print mode runs on its own, so test your script on the commands it really needs before you rely on it.

02How a run stalls or fails

Two things go wrong in scripted runs, and both come from hooks written for interactive use:

  1. A hook that waits for a person. A PreToolUse hook that holds a command until someone answers from elsewhere (a chat message, a phone) makes the whole run sit there until its timeout. Then, if it falls back to force_ask, print mode turns that into a denial, so the run waited and still lost the command.
  2. A hook that times out. A slow network call in a PreToolUse hook that runs past its timeout blocks the tool. In a CI log this looks like Antigravity refusing to run a command for no reason.

03Make your hooks print-mode aware

The simplest fix is to have your hooks recognise a scripted run and answer straight away. None of the payload fields we've seen says whether it's print mode, so set an environment variable in the script that calls agy, and check it in the hook:

#!/bin/sh
# nightly.sh
export AGY_SCRIPTED=1
agy -p "Run the test suite and summarise any failures in FAILURES.md"
#!/usr/bin/env python3
# agy-policy.py: a PreToolUse hook that never waits in scripts
import json, os, sys

def decide(event):
    if os.environ.get("AGY_SCRIPTED") == "1":
        return {"decision": "allow"}
    # ... your interactive rules here ...
    return {"decision": "allow"}

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

Hooks are started by Antigravity, so they normally see the environment of the agy process. Check that yours does before you depend on it: have the hook write the variable to a log file on a test run.

If your CI job should refuse certain commands, use deny with a clear reason rather than force_ask. A deny reason reaches the model word for word, so it can work around the refusal ("Don't install packages; use what is in requirements.txt"), while a force_ask in print mode is just a bare denial.

04Use a project hook for the job

A .agents/hooks.json in the repository applies to every run in that folder, including agy -p, and can be committed with the code. That keeps CI policy next to the project rather than in the build machine's home folder:

{
  "ci-policy": {
    "PreToolUse": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "/opt/ci/agy-policy.py", "timeout": 10 }
        ]
      }
    ]
  }
}

Keep the timeout short for policy hooks: they should decide in milliseconds. The default is 30 seconds.

05Knowing when a scripted run is done

A Stop hook is a simple way to hear that a long agy -p run has finished, on any machine where it runs: Mac, Windows or Linux, a laptop or a build server. Make it fast and have it print {}. If you use decision: continue in a Stop hook, remember that continuationActive stays false, so a scripted run with a hook that always continues never ends. See the Stop hook guide.

For a script, checking the exit code and output of agy in the script itself is often enough, without a hook.

06Antigravity Notifier and print mode

Antigravity Notifier's hooks never hold a call in agy -p. Its PreToolUse hook spots print mode by looking for agy -p among its parent processes and answers straight away, so a script never waits for a phone. Anything it would have sent as a card with buttons arrives on your iPhone or Android phone as a note instead, so you still hear that a run finished. It is independent and not made by Google, and the antigravity-notifier tool is free for Mac, Windows (beta) and Linux.

07FAQ

Do hooks run in agy -p?

Yes. Global and project hooks both load in print mode.

What happens to force_ask in agy -p?

It is answered with a denial, because there is no prompt to show. The tool doesn't run.

Does --dangerously-skip-permissions disable hooks?

No. Hooks run with that flag too, so a hook that denies or blocks still applies.

Why does Antigravity refuse commands in CI that work on my laptop?

Usually a PreToolUse hook that can't run on the CI machine (a missing script or interpreter), times out, or returns force_ask. Antigravity is fail-closed, so each of those stops the tool. Check the hooks in ~/.gemini/config/hooks.json on that machine and in the project's .agents/hooks.json.

Can I tell print mode from the hook's input?

Not from any payload field we've seen. Set an environment variable in the calling script, or look at the hook's parent processes for agy -p.

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.