#### Reference

# Third party hooks

> [!NOTE]
> On the other surface
>
> This page covers the Agents Window. For the Terminal UI, see [the `[compat.claude]` section of `config.toml`](/build/settings/reference#skills-plugins-and-compat).

Grok Build supports loading hooks from third-party tools, enabling compatibility with existing hook configurations from other AI coding assistants.

## Claude Code hooks

Grok Build can load and execute hooks configured for Claude Code, allowing you to use the same hook scripts across both tools.

### Requirements

Claude Code hooks load when **Include Third-Party Plugins, Skills, and Other Configs** is enabled in Grok Build Settings → Agents → Third-Party Imports. The setting is on by default.

### Configuration locations

Claude Code hooks are loaded from these locations (in priority order):

| Location | Path | Description |
|----------|------|-------------|
| **Project local** | `.claude/settings.local.json` | Project-specific, gitignored overrides |
| **Project** | `.claude/settings.json` | Project-level hooks, checked into repo |
| **User** | `~/.claude/settings.json` | User-level hooks, apply globally |

### Priority order

When hooks are configured in multiple locations, they are merged in this priority order (highest to lowest):

1. Enterprise hooks (managed deployment)
2. Team hooks (dashboard-configured)
3. Project hooks (`.cursor/hooks.json`)
4. User hooks (`~/.cursor/hooks.json`)
5. Claude project local (`.claude/settings.local.json`)
6. Claude project (`.claude/settings.json`)
7. Claude user (`~/.claude/settings.json`)

All matching hooks from every source run. When responses conflict, higher-priority sources take precedence during merge.

Enterprise-managed hooks and dashboard distribution require an Enterprise plan. [Contact sales](https://cursor.com/contact-sales?source=docs-third-party-hooks) to learn more.

### Claude Code hook format

Claude Code hooks use a similar but slightly different format. Grok Build automatically maps Claude hook names to their Grok Build equivalents.

**Example Claude Code settings.json:**

```json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Shell",
        "hooks": [
          {
            "type": "command",
            "command": "./hooks/validate-shell.sh"
          }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": ".*",
        "hooks": [
          {
            "type": "command",
            "command": "./hooks/audit.sh"
          }
        ]
      }
    ]
  }
}
```

### Response format compatibility

Grok Build supports both Claude Code's nested `hookSpecificOutput` response format and the older flat response format. Hook scripts written for Claude Code will work in Grok Build regardless of which format they use.

#### `PreToolUse` Response formats

**Nested format (Claude Code style):**

```json
{
  "hookSpecificOutput": {
    "hookEventName": "PreToolUse",
    "permissionDecision": "deny",
    "permissionDecisionReason": "Blocked by policy",
    "updatedInput": { "command": "npm ci" }
  }
}
```

**Flat format (Grok Build native style):**

```json
{
  "permission": "deny",
  "user_message": "Blocked by policy",
  "updated_input": { "command": "npm ci" }
}
```

Both formats are equivalent. The nested `permissionDecision` maps to `permission`, `permissionDecisionReason` maps to `user_message`, and `updatedInput` maps to `updated_input`.

#### `Stop` / `SubagentStop` response formats

**Nested format (Claude Code style):**

```json
{
  "hookSpecificOutput": {
    "decision": "block",
    "reason": "Tasks incomplete, continue working"
  }
}
```

**Flat format (Claude Code legacy style):**

```json
{
  "decision": "block",
  "reason": "Tasks incomplete, continue working"
}
```

**Grok Build native format:**

```json
{
  "followup_message": "Tasks incomplete, continue working"
}
```

For `Stop` and `SubagentStop` hooks, a `decision` of `"block"` with a `reason` is treated as an automatic follow-up, equivalent to providing `followup_message` in the native Grok Build format.

### Hook step mapping

Claude Code hook names are automatically mapped to Grok Build hook names:

| Claude Code Hook | Grok Build Hook |
|------------------|-------------|
| `PreToolUse` | `preToolUse` |
| `PostToolUse` | `postToolUse` |
| `UserPromptSubmit` | `beforeSubmitPrompt` |
| `Stop` | `stop` |
| `SubagentStop` | `subagentStop` |
| `SessionStart` | `sessionStart` |
| `SessionEnd` | `sessionEnd` |
| `PreCompact` | `preCompact` |

### Exit code behavior

Both Grok Build and Claude Code hooks support exit code `2` to block an action. This provides consistent behavior when sharing hooks between tools:

```bash
#!/bin/bash
# Block dangerous commands
if [[ "$COMMAND" == *"rm -rf"* ]]; then
  echo '{"permission": "deny", "user_message": "Destructive command blocked"}'
  exit 2
fi
echo '{"permission": "allow"}'
exit 0
```

* **Exit code 0**: Hook succeeded, use the JSON output
* **Exit code 2**: Block the action (equivalent to `permission: "deny"`)
* **Other exit codes**: Hook failed, action proceeds (fail-open)

### Migration from Claude Code

If you have existing Claude Code hooks, you can:

1. **Keep using Claude Code config files**: Leave **Include Third-Party Plugins, Skills, and Other Configs** enabled and your existing `.claude/settings.json` hooks will work automatically
2. **Migrate to Grok Build format**: Copy your hooks to `.cursor/hooks.json` using the Grok Build format for full feature support

**Grok Build format equivalent:**

```json
{
  "version": 1,
  "hooks": {
    "preToolUse": [
      {
        "command": "./hooks/validate-shell.sh",
        "matcher": "Shell"
      }
    ],
    "postToolUse": [
      {
        "command": "./hooks/audit.sh"
      }
    ]
  }
}
```

## Supported features

When using Claude Code hooks in Grok Build, the following features are supported:

| Claude Code Event | Grok Build Mapping | Supported |
|-------------------|----------------|-----------|
| `PreToolUse` | `preToolUse` | Yes |
| `PostToolUse` | `postToolUse` | Yes |
| `Stop` | `stop` | Yes |
| `SubagentStop` | `subagentStop` | Yes |
| `SessionStart` | `sessionStart` | Yes |
| `SessionEnd` | `sessionEnd` | Yes |
| `PreCompact` | `preCompact` | Yes |
| `UserPromptSubmit` | `beforeSubmitPrompt` | Yes |
| `Notification` | - | No |
| `PermissionRequest` | - | No |

**Additional supported features:**

| Feature | Supported |
|---------|-----------|
| Command-based hooks (`type: "command"`) | Yes |
| Prompt-based hooks (`type: "prompt"`) | Yes |
| Nested `hookSpecificOutput` responses | Yes |
| Exit code 2 blocking | Yes |
| Tool matchers (regex patterns) | Yes |
| Timeout configuration | Yes |

### Tool name mapping

Claude Code tool names are mapped to Grok Build tool names:

| Claude Code Tool | Grok Build Tool | Supported |
|------------------|-------------|-----------|
| `Bash` | `Shell` | Yes |
| `Read` | `Read` | Yes |
| `Write` | `Write` | Yes |
| `Edit` | `Write` | Yes |
| `Grep` | `Grep` | Yes |
| `Task` | `Task` | Yes |
| `WebFetch` | `WebFetch` | Yes |
| `WebSearch` | `WebSearch` | Yes |
| `Glob` | - | No |

### Limitations

Some features are only available when using the native Grok Build format:

* `subagentStart` hook (Claude Code only has `SubagentStop`)
* Loop limit configuration (`loop_limit`)
* Team/Enterprise hook distribution via dashboard

## Troubleshooting

**Claude Code hooks not loading**

1. Verify "Include Third-Party Plugins, Skills, and Other Configs" is enabled in Grok Build Settings → Agents → Third-Party Imports
2. Check that your `.claude/settings.json` file is valid JSON
3. Grok Build watches config files and reloads them automatically. If hooks still do not load, restart Grok Build.

**Hooks running but not blocking**

1. Ensure your hook script exits with code `2` to block actions
2. Check the JSON output format matches the expected schema
3. View the Hooks output channel in Grok Build for error details

**Different behavior between Grok Build and Claude Code**

Some behavior differences may exist due to different execution environments. Test your hooks in both tools to ensure compatibility.
