---
name: nerf:setup-hooks
description: Install NERF hooks (statusline, context monitor, precommit scan) into Claude Code
---

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.cjs`, `./hooks/nerf-context-monitor.cjs`, and `./hooks/nerf-precommit-scan.cjs`
2. The npm global install: `npm root -g`/@defconxt/nerf/hooks/
3. Common dev locations: `hooks/`

If no hooks are found, tell the user:
> NERF hooks not found. 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:
- **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: No hooks installed

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 B: NERF hooks already installed

Display:
> **NERF hooks 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**:
```json
"statusLine": {
  "type": "command",
  "command": "node \"HOOKS_DIR/nerf-statusline.cjs\""
}
```

For the **PostToolUse** context monitor:
```json
{
  "hooks": [
    {
      "type": "command",
      "command": "node \"HOOKS_DIR/nerf-context-monitor.cjs\""
    }
  ]
}
```

**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.cjs` (shows model, directory, context bar)
> - **Context monitor**: `nerf-context-monitor.cjs` (warns at 35%/25% remaining)
> - **Pre-commit scan**: `nerf-precommit-scan.cjs` (blocks secrets, warns on dangerous patterns)
>
> Restart Claude Code to activate the new hooks.
