# Grok Build Hooks Reference: PreToolUse in Every Mode, Fail-Open by Default

How Grok Build's PreToolUse hook works: it fires in every permission mode including always-approve, fails open on timeout or crash, takes a top-level decision field, and why --local isn't wired yet.

<div style="background:var(--acp-surface,#f8f9fb);border:1px solid var(--acp-border,#e2e5ea);border-radius:12px;padding:20px 24px;margin:24px 0;">
<p style="margin:0 0 10px;font-weight:600;">Just want the answer?</p>
<p style="margin:0 0 12px;">Grok Build's <code>PreToolUse</code> hook fires in every permission mode, <code>--always-approve</code> included. The ACP hook registers itself in <code>~/.grok/hooks/acp.json</code>. Install it with:</p>
<pre style="margin:0 0 12px;overflow-x:auto;"><code>curl -sf https://agenticcontrolplane.com/install.sh | bash</code></pre>
<p style="margin:0;">Full walkthrough: <a href="/integrations/grok-build">Grok Build install guide</a>. Native control model: <a href="/controls/grok-build">Grok Build permissions, explained</a>.</p>
</div>

Grok Build is xAI's terminal coding agent. Of the harnesses in this reference series, its hooks are the closest to Claude Code's. It reads your Claude Code settings files and accepts Claude's tool names and JSON output shape. But its own hook runner fails open, and the field it reads for a decision isn't the one most Claude-style hooks write. This page covers what fires, what it returns, and what a hook has to do on its own to hold in every mode.

## Where hooks live

Grok Build reads hook registrations from three places:

- `~/.grok/hooks/*.json`: always trusted, no prompt.
- `<project>/.grok/hooks/*.json`: only after you trust the folder once.
- Inline `[[hooks]]` blocks in `config.toml`.

By default it also finds hooks in your existing `~/.claude/settings.json`, `~/.claude/settings.local.json` and `~/.cursor/hooks.json`. If you already run Claude Code or Cursor hooks, Grok Build may already be running them.

## Five permission modes

| Mode | What it means |
|---|---|
| `default` | Prompts for anything not pre-approved |
| `plan` | Read-only; no edits or shell commands run |
| `acceptEdits` | File edits auto-approved; shell commands still prompt |
| `always-approve` (`--yolo`) | Every native prompt answered yes automatically |
| `dontAsk` (headless) | No prompts at all; unmatched calls are silently denied |

Don't mix up the last two. `always-approve` answers yes to a prompt a human would have seen. `dontAsk` denies anything a rule doesn't cover. For hooks they behave the same way: **deny rules and PreToolUse hooks fire in every mode, `always-approve` included.** The flag removes the confirmation dialog. It doesn't remove the hook.

## Only one event blocks

Grok Build fires `SessionStart`, `SessionEnd`, `UserPromptSubmit` (observe-only; unlike Claude Code it can't deny here), `PreToolUse`, `PostToolUse`, `PostToolUseFailure`, `PermissionDenied`, `Stop`, `SubagentStop`, and a compaction event. Only `PreToolUse` can stop a call before it runs.

## The output contract: a top-level field

A Grok Build hook writes JSON to stdout. The field the runner reads is a top-level `decision`:

```json
{ "decision": "deny", "reason": "Blocked by policy" }
```

`"allow"` or no field lets the call proceed. Exit code `2` is an alternate deny, read from stderr.

Here's the trap. Claude Code hooks put their verdict under `hookSpecificOutput.permissionDecision`. Grok Build's docs say they accept that shape too, "for forward-compatibility." We read Grok Build's open-source hook runner (August 2026). It parses only the top-level `decision`. A hook that only sets `hookSpecificOutput.permissionDecision: "deny"` leaves it unset, which reads as no decision, which means allow. The hook can compute a deny correctly and still let the call through because it wrote the answer in the wrong place. A hook for Grok Build has to write the flat `decision` field to block anything.

## Fail-open, and what the ACP hook does about it

Grok Build's default hook timeout is 5 seconds. A timeout, a crash or malformed output all mean allow. Only an explicit `"decision": "deny"` stops a call. That's reasonable for the harness: a broken hook shouldn't brick your session. But anything built on this contract inherits "proceed" as its failure mode unless it adds its own.

The ACP hook adds its own, and it isn't the same everywhere. In interactive and auto sessions it fails open loudly: a `[ACP] ⚠ UNGOVERNED` warning on stderr and a line in `~/.acp/lapse.log`. In unattended sessions (headless, CI, `dontAsk`, bypass) it fails closed, because nobody is reading the scrollback. The gateway call is retried once before either happens.

## No "ask" in Grok Build

Grok Build's hook contract has no `ask`, only allow or deny. The ACP hook handles an ACP ask by mode:

- In `default` and `plan`, Grok Build's own confirmation prompt still stands after the hook returns, so the ask lands there.
- In `auto`, `always-approve` and headless modes there is no prompt to fall back on. The ask becomes a deny with a link to approve it on the console. You approve, then ask the agent to retry.

A local allow rule outranks an ask in attended modes. A deny always holds, in any mode. The [coverage matrix](/coverage) has the same story for every harness.

## Installing it

```bash
curl -sf https://agenticcontrolplane.com/install.sh | bash
```

By hand:

```bash
mkdir -p ~/.acp/hooks/grok-build ~/.grok/hooks
curl -fsSL https://agenticcontrolplane.com/hooks/grok-build/hook.mjs \
  -o ~/.acp/hooks/grok-build/hook.mjs
curl -fsSL https://agenticcontrolplane.com/hooks/grok-build/acp.json \
  -o ~/.grok/hooks/acp.json
```

The registration file points Grok Build at the local script. The script calls the gateway, so rotating your ACP key means overwriting the credentials file, not reinstalling.

## `--local` skips Grok Build

In the installer's source, Grok Build is skipped under `--local`. It prints that the hook needs a workspace and that local decisions aren't wired there yet. Claude Code's and Cursor's hooks can use an on-device rules file (`~/.acp/policy.json`) in local mode. Grok Build's hook always calls the hosted `/govern/tool-use` endpoint, so with no workspace key it has nothing to check against. The installer skips the setup instead of registering a hook that would never do anything.

## Known limits

- The hook sees tool calls, not tokens. We don't have a model-spend path for Grok Build, so the log records each call and its allow or deny, with Grok's native tool name kept.
- A hook can only judge what it is shown when it's called. That's true of every hook-based control, Grok Build's included.
- Grok Build's own session log (`~/.grok/sessions`) has no documented way to query it. The ACP activity log is the searchable record of what the hook decided.

## Compared with Claude Code hooks

The two are close but not the same. Claude Code reads `hookSpecificOutput.permissionDecision` and has a real `ask`. Grok Build reads a flat `decision` and only has allow or deny. Both run hooks in their "approve everything" modes, Claude Code's `bypassPermissions` and Grok Build's `--always-approve`. The [Claude Code hooks reference](/blog/claude-code-hooks-reference) covers the other side.

## Frequently asked questions



## Where to read more

- [Grok Build permissions, explained](/controls/grok-build)
- [Grok Build install guide](/integrations/grok-build)
- [Claude Code hooks reference](/blog/claude-code-hooks-reference)
- [Codex hooks reference](/blog/codex-cli-hooks-reference)
- [grok-build-acp-plugin source](https://github.com/agentic-control-plane/grok-build-acp-plugin)
- <!-- source: https://docs.x.ai/build/features/hooks --> [Grok Build hooks documentation](https://docs.x.ai/build/features/hooks)
