<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->
---
name: setup-hooks
description: Install NERF hooks (statusline + context monitor) into Claude Code
disable-model-invocation: true
---

You are installing NERF's Claude Code hooks. Follow these steps precisely.

## Step 1: Locate NERF hooks

Check if the NERF hook files exist. Try these locations in order:
1. The current project directory: `./hooks/nerf-statusline.js` and `./hooks/nerf-context-monitor.js`
2. The installed package location: run `python3 -c "from importlib.resources import files; print(files('nerf_security'))" 2>/dev/null` then check for hooks there
3. Common dev locations: `hooks/`

If no hooks are found, tell the user:
> NERF hooks not found. If you installed via pip, clone the repo to get hooks:
> `git clone https://github.com/defconxt/NERF.git && cd NERF`
> Then run `/nerf:setup-hooks` from within the repo.

Stop if hooks aren't found.

Store the absolute path to the hooks directory as `HOOKS_DIR`.

## Step 2: Detect existing hook setup

Read `~/.claude/settings.json` (create it if it doesn't exist with `{}`).

Check for:
- **GSD statusline**: Look for `gsd-statusline` in the statusLine command
- **GSD context monitor**: Look for `gsd-context-monitor` in PostToolUse hooks
- **NERF statusline**: Look for `nerf-statusline` in the statusLine command
- **NERF context monitor**: Look for `nerf-context-monitor` in PostToolUse hooks

## Step 3: Determine action based on what's installed

### Case A: GSD hooks already present, no NERF hooks

Display:
> **GSD hooks detected.** GSD is already providing statusline and context monitoring.
>
> NERF's context monitor adds engagement-aware warnings (detects `.nerf/ENGAGEMENT.md`
> and tailors context exhaustion advice for security engagements).
>
> Options:
> 1. **Add NERF context monitor alongside GSD** — both monitors run (recommended)
> 2. **Replace GSD hooks with NERF hooks** — use NERF's statusline and monitor instead
> 3. **Skip** — keep GSD hooks only

Ask the user which option they want.

- **Option 1**: Add NERF's context monitor as a second entry in the PostToolUse hooks array. Keep GSD's statusline. Do NOT replace anything.
- **Option 2**: Replace the statusLine command with NERF's statusline. Replace the PostToolUse hooks with NERF's context monitor only (remove GSD's).
- **Option 3**: Stop. Display "No changes made."

### Case B: No hooks installed (no GSD, no NERF)

Display:
> **No existing hooks detected.** Installing NERF statusline and context monitor.

Then proceed to install both:
- Set `statusLine` to NERF's statusline
- Add NERF's context monitor to `PostToolUse`

### Case C: NERF hooks already installed

Display:
> **NERF hooks already installed.** No changes needed.

Stop.

### Case D: GSD and NERF hooks both present

Display:
> **Both GSD and NERF hooks are already installed.** No changes needed.

Stop.

## Step 4: Apply changes to settings.json

Read the current `~/.claude/settings.json`, modify the JSON in-memory, and write it back.

For the **statusLine** (when installing NERF's):
```json
"statusLine": {
  "type": "command",
  "command": "node \"HOOKS_DIR/nerf-statusline.js\""
}
```

For the **PostToolUse** context monitor (when adding alongside GSD):
Add a new entry to the existing PostToolUse array:
```json
{
  "hooks": [
    {
      "type": "command",
      "command": "node \"HOOKS_DIR/nerf-context-monitor.js\""
    }
  ]
}
```

When replacing, set the entire PostToolUse array to just NERF's hook.

**IMPORTANT**: Preserve all other settings.json fields (skipDangerousModePermissionPrompt, enabledPlugins, SessionStart hooks, etc.). Only modify statusLine and PostToolUse.

## Step 5: Verify

Read back `~/.claude/settings.json` and confirm the hooks are registered.

Display:
> ### NERF Hooks Installed
>
> - **Statusline**: `nerf-statusline.js` (shows model, directory, context bar)
> - **Context monitor**: `nerf-context-monitor.js` (warns at 35%/25% remaining)
>
> Restart Claude Code to activate the new hooks.
