# Debug Hooks

Systematic hook debugging workflow.

- Repository: https://github.com/parcadei/Continuous-Claude-v3 (3947 stars)
- Category: Testing
- License: MIT
- Last updated: 2026-01-26
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add parcadei/Continuous-Claude-v3 --skill debug-hooks -g -a claude-code -y`
Codex: `npx skills add parcadei/Continuous-Claude-v3 --skill debug-hooks -g -a codex -y`
Cursor: `npx skills add parcadei/Continuous-Claude-v3 --skill debug-hooks -g -a cursor -y`
Gemini CLI: `npx skills add parcadei/Continuous-Claude-v3 --skill debug-hooks -g -a gemini-cli -y`

## Description

Systematic hook debugging workflow. Use when hooks aren't firing, producing wrong output, or behaving unexpectedly.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Debug Hooks

Systematic workflow for debugging Claude Code hooks.

## When to Use

- "Hook isn't firing"
- "Hook produces wrong output"
- "SessionEnd not working"
- "PostToolUse hook not triggering"
- "Why didn't my hook run?"

## Workflow

### 1. Check Outputs First (Observe Before Editing)

```bash
# Check project cache
ls -la $CLAUDE_PROJECT_DIR/.claude/cache/

# Check specific outputs
ls -la $CLAUDE_PROJECT_DIR/.claude/cache/learnings/

# Check for debug logs
tail $CLAUDE_PROJECT_DIR/.claude/cache/*.log 2>/dev/null

# Also check global (common mistake: wrong path)
ls -la ~/.claude/cache/ 2>/dev/null
```

### 2. Verify Hook Registration

```bash
# Project settings
cat $CLAUDE_PROJECT_DIR/.claude/settings.json | grep -A 20 '"SessionEnd"\|"PostToolUse"\|"UserPromptSubmit"'

# Global settings (hooks merge from both)
cat ~/.claude/settings.json | grep -A 20 '"SessionEnd"\|"PostToolUse"\|"UserPromptSubmit"'
```

### 3. Check Hook Files Exist

```bash
# Shell wrappers
ls -la $CLAUDE_PROJECT_DIR/.claude/hooks/*.sh

# Compiled bundles (if using TypeScript)
ls -la $CLAUDE_PROJECT_DIR/.claude/hooks/dist/*.mjs
```

### 4. Test Hook Manually

```bash
# SessionEnd hook
echo '{"session_id": "test-123", "reason": "clear", "transcript_path": "/tmp/test"}' | \
  $CLAUDE_PROJECT_DIR/.claude/hooks/session-end-cleanup.sh

# PostToolUse hook (Write tool example)
echo '{"tool_name": "Write", "tool_input": {"file_path": "test.md"}, "session_id": "test-123"}' | \
  $CLAUDE_PROJECT_DIR/.claude/hooks/handoff-index.sh
```

### 5. Check for Silent Failures

If using detached spawn with `stdio: 'ignore'`:

```typescript
// This pattern hides errors!
spawn(cmd, args, { detached: true, stdio: 'ignore' })
```

**Fix:** Add temporary logging:

```typescript
const logFile = fs.openSync('.claude/cache/debug.log', 'a');
spawn(cmd, args, {
  detached: true,
  stdio: ['ignore', logFile, logFile]  // capture stdout/stderr
});
```

### 6. Rebuild After Edits

The rest: https://github.com/parcadei/Continuous-Claude-v3/blob/HEAD/.claude/skills/debug-hooks/SKILL.md
