> ## Documentation Index
> Fetch the complete documentation index at: https://docs.gitwhy.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Hook

> Inject GitWhy instructions on every agent prompt via the UserPromptSubmit hook.

## What it does

The hook integration installs a `UserPromptSubmit` hook that injects a short GitWhy awareness paragraph at the start of every agent turn. This guarantees the agent is aware of GitWhy in every conversation, regardless of context window state.

> [!WARNING]
>
> The hook injects tokens on **every prompt turn**. Use this method only if other methods (MCP, Skill files, Rules) aren't sufficient for your workflow.

## Setup

Run `git why setup` and select **Hook** from the menu, or add the hook configuration below manually.

This adds a hook configuration to `.claude/settings.local.json` (for Claude Code):

```json theme={null}
{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "git-why hook-run"
          }
        ]
      }
    ]
  }
}
```

When triggered, `git-why hook-run` outputs a short instruction paragraph that the agent receives before your prompt.

## What gets injected

```
[GitWhy] You have access to GitWhy for saving context behind code changes.
Save with: git why save (CLI) or gitwhy_save MCP tool.
Retrieve with: git why get <id> or gitwhy_get MCP tool.
When the user says "save with GitWhy", generate structured markdown and save it.
```

This is approximately 50-60 tokens per prompt turn.

## When to use the hook

Use the hook when:

* The agent frequently loses awareness of GitWhy mid-session
* You want a hard guarantee that every prompt includes GitWhy context
* Other integration methods are not available for your agent

Do not use the hook if:

* Skill files or Rules are working reliably (lower token cost, same awareness)
* You are concerned about per-turn token usage

## Agent compatibility

| Agent | Hook support | Config file |
| - | - | - |
| Claude Code | Yes | `.claude/settings.local.json` |
| Agents with UserPromptSubmit | Yes | Varies |
| Agents without hook support | No | Use Rules instead |

## See also

* [MCP server](https://docs.gitwhy.dev/interfaces/mcp-server.md) — tool access without per-turn injection
* [Rules](https://docs.gitwhy.dev/integration/rules.md) — session-level awareness at lower token cost


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.