Skip to content

[Bug]: PreToolUse hook returning decision: "allow" does not allow the call #1053

Open

Description

@Emily2040

Antigravity CLI Version

1.2.7

Environment Context

  • OS: Windows 11 Pro 10.0.26340 (AMD64)
  • Shell: PowerShell 7.x and Git Bash
  • Terminal Emulator: n/a, all runs were non-interactive agy -p
  • Runtime Version: agy CLI 1.2.7, Antigravity Hub 2.15.0
  • Hardware Details: AMD Ryzen 7 5800H, 29 GB RAM

Steps to Reproduce

  1. Create a hook that returns only an allow decision:
# h_allow.py
import sys, json
p = json.loads(sys.stdin.read() or "{}")
cmd = ((p.get("toolCall") or {}).get("args") or {}).get("CommandLine", "")
sys.stderr.write("hook saw: %r\n" % cmd)
sys.stdout.write(json.dumps({"decision": "allow", "reason": "isolation test"}))
  1. Register it in ~/.gemini/config/hooks.json:
{ "iso-allow": { "PreToolUse": [ { "matcher": "run_command",
  "hooks": [ { "type": "command", "command": "python h_allow.py", "timeout": 15 } ] } ] } }
  1. With no command(...) grant matching the target, run:
agy -p "Run exactly: echo ISOLATION_TEST_MARKER"

Expected Behavior

The command executes. Per agy-customizations/docs/hooks.md:

"allow": Automatically allow the tool execution.

Actual Behavior / Error Screenshots

The call is auto-denied:

jetski: no output produced - a tool required the "command" permission that headless
mode cannot prompt for, so it was auto-denied.

The hook ran and saw the call. Its own stderr:

hook saw: 'echo ISOLATION_TEST_MARKER'

So this is not a matcher miss. The response is also not thrown away wholesale, because overwrite from the same response object is applied.

Logs & Configurations

What each field actually does

I tested all three against the same gate.

Field returned Result
decision: "deny" Honoured. Blocks a command that has an explicit grant.
decision: "allow" Ignored. Ungranted command is still auto-denied.
overwrite Honoured. Arguments rewritten and announced to the agent.

deny test, with command(echo DENY_TEST_MARKER) granted and a hook returning {"decision": "deny", "reason": "blocked by safety hook (test)"}:

Execution of the command was denied by the environment's pre-tool safety hook:
tool call denied by pre-tool hook: blocked by safety hook (test)

overwrite test, with a grant present so the call could run:

A pre-tool hook changed the arguments of this tool call before it ran. Changed: CommandLine.

The command exited with code 0.
Output:
SUBSTITUTED_BY_HOOK

Reading of the cause

The gate consumes decision, since deny reaches it and overrides a grant. It lets a hook veto a granted call. It will not let a hook approve an ungranted one.

That fits a gate treating hooks as a restriction layer only, with deny-overrides semantics, where allow parses as valid input and never reaches the grant lookup. Conservative as a security posture. It does not match the documented contract.

Impact

A hook can restrict and never permit. PreToolUse works as a safety guard and fails as a policy engine. The obvious pattern, auto-approve a known-safe command set and ask about everything else, cannot be expressed in headless mode.

Anyone implementing the documented contract for CI gets a hook that fires, logs, returns valid JSON, raises no error, and has no effect. Nothing in the output points at the cause.

It also removes the remaining escape hatch. autoExecutionPolicy is inert in headless as well, which I am filing separately. With both gone, the options are an exact-match grant list or --dangerously-skip-permissions, and nothing in between.

Suggested fix

  1. Wire "allow" into the gate the way "deny" already is. deny reaches the gate and overrides a grant, so the plumbing exists. allow needs to satisfy the grant lookup rather than run beside it. "ask" and "force_ask" can keep falling through to the existing cannot-prompt deny path.
  2. If allow is meant to be advisory in headless, say so in agy-customizations/docs/hooks.md and log the discard: hook returned decision=allow but headless permission gate requires an explicit grant.
  3. Name the hook in the denial message, so it is visible that a hook decided and was overruled.

One thing that already works correctly

While testing overwrite I checked whether a hook could launder an unapproved command through an approved one. Grant command(echo ORIGINAL_COMMAND), then rewrite it to something else in the hook.

The substituted command was denied. Permission evaluates against the post-overwrite arguments. That closes a privilege-escalation path through PreToolUse. Worth keeping through any refactor of this area.

Scope

agy -p headless only. IDE and Hub GUI untested.

Activity

  1. Emily2040 commented on Sep 24, 2026

    @Emily2040
    Author

    Re-checked on 1.2.9: unchanged. A PreToolUse hook returning {"decision": "allow"} for an ungranted command runs and is logged, and the call is still auto-denied.

    The shape from #1059, closed as a duplicate of this, does no better. {"decision": "ask", "permissionOverrides": ["command(<the exact line>)"]} is denied the same way in headless.

    deny still blocks. overwrite with decision: "allow" still rewrites the call and announces the change, and because the permission check runs against the rewritten command it still can't launder one.

    For the record, @konomings reported the allow half on #548 on 1.1.8, well before I filed this.

  2. probablysamir commented on Sep 28, 2026

    @probablysamir

    We're hitting this too. Drawa (a browser canvas that runs coding agents) drives agy in headless stream-json mode, and we'd like users to approve or deny each tool call from the UI, the same way we do for Claude Code and OpenCode. The only hook into that is PreToolUse, and since allow is ignored, we can deny but never approve. That leaves an Antigravity session either read-only or fully bypassed.

    Would it be possible to get allow (and permissionOverrides) honoured in headless mode? A way to answer permission prompts over stream-json stdin would work for us too.

  3. th3nolo commented on Sep 29, 2026

    @th3nolo

    Still reproduces on 1.2.13 (Windows 11, headless agy -p, one PreToolUse hook, no grant for the command): a hook that returns allow is ignored and the call is auto-denied. ask and force_ask are auto-denied the same way.

    @probablysamir, the "fully bypassed" side is not fully bypassed. With --dangerously-skip-permissions, a hook's deny still blocks the call, and a hook that crashes (exit 1, no output) also blocks it. So approve/deny from a UI works today:

    1. Run with --dangerously-skip-permissions. The hook returns deny with a reason for every call that needs approval. The agent sees the reason.
    2. The user approves in your UI. You save that exact command.
    3. The agent retries. The hook returns allow for the saved command, and the call runs.

    The hook has to deny by default: under the flag, every call it does not deny runs.

    One related gap: under the flag, a hook's ask and force_ask are auto-approved with no prompt. It would help if they showed the prompt in interactive mode and were a deny in headless mode.

  4. probablysamir commented on Sep 30, 2026

    @probablysamir

    I guess agy is still immature to use it in a full fledged headless session like claude code, opencode or codex, to mention a few we've integrated to so far. We've hit many other limitations too. CC: @th3nolo

  5. Emily2040 commented on Oct 5, 2026

    @Emily2040
    Author

    Re-checked on agy 1.2.17, Windows 11 Pro Insider Preview 10.0.26340 (64-bit), headless agy -p, using gemini-3.8-flash-high. The allow case still fails.

    The hook records the actual command it receives and returns {"decision":"allow"}. With no matching grant, the command is auto-denied. Adding an exact grant makes it run. Returning deny blocks a command that has an exact grant.

    Case Command result
    Hook returns allow, no grant Auto-denied
    Hook returns allow, exact grant Executed, exit 0
    Hook returns deny, exact grant Blocked by the hook

    I checked the tool results in the saved transcripts and the hook's input log. The current bundled hooks documentation still describes allow as automatically allowing execution. That contract still differs from the observed headless behaviour.

    These runs used an isolated configuration with no inherited permission grants.

  6. th3nolo commented on Oct 5, 2026

    @th3nolo

    @probablysamir The official ACP server gives per-call approval today. I tested it.

    Setup: agy_acp_server 1.3.0 (Windows x64, ACP registry entry antigravity-acp), a minimal ACP client over stdio. The server does not use the agy CLI login. The client must call authenticate once.

    For run_command, the server sends session/request_permission with allow_always, allow_once and reject_once. The client answer controls the call:

    PreToolUse hook Client answer Result
    none allow_once Runs, exit 0
    none reject_once Fails, "Rejected by user"
    allow reject_once Client is asked. Call is rejected.
    ask reject_once Client is asked. Call is rejected.
    deny not asked Blocked. Agent gets the hook reason.

    Drawa can approve and deny from the UI. It needs no hooks and no skip flag. If you add hooks, do not use shell syntax in the command (#1152).

    Two results for this issue:

    1. The ACP server also ignores hook allow. The call goes to the client prompt. The docs say allow approves the call. That is false on both the CLI and the ACP server.
    2. When a hook denies, the client gets no tool_call update. Only the agent text shows the block.

    My earlier workaround does not need --dangerously-skip-permissions. Set "toolPermission": "always-proceed" in ~/.gemini/antigravity-cli/settings.json. On 1.2.13 headless, a hook deny still blocks run_command with this setting. @Emily2040's table on #1054 shows that this setting runs ungranted commands on 1.2.17. The hook must deny by default.

    Testing note: GEMINI_HOME isolates the ACP server. It does not isolate the agy CLI. With GEMINI_HOME set to an empty folder, CLI 1.2.13 still reads ~/.gemini/antigravity-cli/settings.json and ~/.gemini/config/hooks.json.

  7. probablysamir commented on Oct 5, 2026

    @probablysamir

    @th3nolo but this is just a workaround by installing agy_acp_server and this works in a very different way than how we have wrapped other agents in drawa. This might definitely work but it's more about a rewrite than a simple fix. Hope agy supports this natively soon enough

  8. lpalvess commented on Oct 18, 2026

    @lpalvess

    Confirming this on agy 1.4.2 (Linux/WSL2), and adding two data points that may help: a behaviour change between 1.3.x and 1.4.x, and TUI results (the report above is headless only).

    Same bug in 1.4.2, headless (agy -p "Run this exact shell command with your terminal tool: touch proof.txt", PreToolUse hook on run_command):

    Hook stdout Command ran?
    {"decision":"allow"} no (auto-denied, command permission)
    {"decision":"allow","permissionOverrides":["command(touch proof.txt)"]} no
    {"decision":"allow","permissionOverrides":["command(touch)"]} no
    {"decision":"ask","permissionOverrides":["command(touch proof.txt)"]} no (also see #1059)
    {"permissionOverrides":["command(touch)"]} (no decision) no
    {"decision":"allow","overwrite":{}} no
    empty stdout, exit 0 no (normal flow, auto-denied in headless)

    Regression: {} no longer lets the call through. On agy 1.3.3, a hook printing {} made run_command run with no permission prompt (headless, 5/5 runs, while no hook was auto-denied; in the TUI it ran without the "Run this command?" prompt). On 1.4.1 and 1.4.2 the same {} makes the call fail (tool call denied by pre-tool hook: with an empty reason, reported independently on 1.4.1), and it also blocks view_file. I'm not claiming {} was documented behaviour, only that tools were relying on it, and it silently flipped from "allow" to "deny".

    TUI (1.4.2, pty): empty stdout shows the normal "Run this command?" prompt; {} shows no prompt and the command does not run. So there is still no way for a hook to approve a call in the TUI either.

    The practical effect: a PreToolUse hook can block (deny) but cannot approve, and decision: "allow", as documented in hooks.md, has no effect. Tools that forward approval decisions from another UI to agy (we hit this in an open-source dashboard) have no working option on 1.4.x. A working allow (or honouring permissionOverrides) would fix this and #1059.

  9. DevCop95 commented on Oct 24, 2026

    @DevCop95

    Cross-reference: I opened #1329 with evidence that in the Antigravity IDE App (not CLI print mode) PreToolUse/PostToolUse do fire and {"decision":"allow"} is honored (control case executed), while deny blocks. So the allow-ignored behavior reported in #1053 appears to be specific to the CLI print-mode executor, not the hook contract itself. The App side also shows deny > force_ask > allow/ask precedence when multiple hooks disagree. Full event lifecycle + counts by model (including gemini-4-argon-high) in #1329.

  10. Emily2040 commented on Oct 25, 2026

    @Emily2040
    Author

    Still present on 1.4.7. Windows 11 Pro Insider Preview 10.0.26340, headless agy -p, gemini-3.8-flash-low, fresh synthetic workspace and isolated CLI home for each case, no broad grants.

    Case Hook Command ran?
    PreToolUse hook on run_command returns {"decision":"allow"} fired (its stdin payload is in the log) No. The step failed with permission check failed ... user denied permission to run command
    No hook (baseline) none No, same denial
    Exact grant command(python <path>/touch.py) in settings, no hook none Yes, the side-effect file was written

    So the hook runs and answers allow, and the call is still denied exactly as if there were no hook. The grant control shows the command itself is fine.

    This matches what @lpalvess saw on 1.4.2. #1329 reports that the desktop app honours allow, so this looks specific to the CLI print-mode path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't workingdocumentationImprovements or additions to documentation

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions