# Debug Claude Code Hooks with Saved JSON Fixtures

> Debug Claude Code hooks with saved JSON fixtures. Replay the script locally, then test the live matcher and compare stdout, stderr and the exit code.

URL: https://www.matthewswong.com/en/blog/claude-code-hook-fixture-debugging/

- Author: Matthews Wong (https://www.matthewswong.com/en/about/)
- Published: 2026-12-03
- Updated: 2026-12-03
- Category: AI

> **Key takeaway:** A saved Claude Code hook fixture helps test the hook script with realistic input outside a live agent session. Capture the relevant fields for the configured event, replay the input locally and then check that the hook fires in the actual session. Separate trigger problems from script behaviour.

Which fields belong in a fixture?

Start with the event name and the fields the handler reads. Replace account identifiers or local paths with synthetic values. Keep a second fixture that intentionally omits one field so you can review the handler’s response to unexpected input.

How should the script be replayed?

Pass the JSON to the command hook on standard input with the same environment assumptions. Record stdout, stderr and the exit code separately. Compare those results with the Claude Code documentation for the specific hook event and response type.

Why might a passing script never run?

The event or matcher may differ from the operation that fired in the live session. Check the loaded hook configuration and run one known matching operation. Keep the operation harmless, such as touching a scratch text file in a disposable fixture repo.

What should the error path prove?

Run the invalid fixture and inspect how the handler reports it. For a blocking hook, check the live behaviour in a disposable repo before sharing the rule. A useful message names the expected field and leaves enough context to fix the configuration.

Where does path resolution matter?

Replay the fixture from the repository root and from a nested directory. Any path that depends on where the user started Claude Code can fail in an unfamiliar folder. Follow the hook reference for referencing a project script.

What belongs in the handoff?

Keep the fixture, replay command and expected exit behaviour beside the hook script. Document one live test operation. A maintainer can then confirm whether a later failure came from the script, matcher or environment.

## Sources and further reading

- Claude Code hooks reference
- Claude Code settings and precedence
- Claude Code permissions
- Claude Code extension points

## Source links

- https://code.claude.com/docs/en/hooks
- https://code.claude.com/docs/en/settings
- https://code.claude.com/docs/en/permissions
- https://code.claude.com/docs/en/features-overview

## FAQ

### Which fields belong in a fixture?

Start with the event name and the fields the handler reads. Replace account identifiers or local paths with synthetic values. Keep a second fixture that intentionally omits one field so you can review the handler’s response to unexpected input.

### How should the script be replayed?

Pass the JSON to the command hook on standard input with the same environment assumptions. Record stdout, stderr and the exit code separately. Compare those results with the Claude Code documentation for the specific hook event and response type.

### Why might a passing script never run?

The event or matcher may differ from the operation that fired in the live session. Check the loaded hook configuration and run one known matching operation. Keep the operation harmless, such as touching a scratch text file in a disposable fixture repo.

### What should the error path prove?

Run the invalid fixture and inspect how the handler reports it. For a blocking hook, check the live behaviour in a disposable repo before sharing the rule. A useful message names the expected field and leaves enough context to fix the configuration.

### Where does path resolution matter?

Replay the fixture from the repository root and from a nested directory. Any path that depends on where the user started Claude Code can fail in an unfamiliar folder. Follow the hook reference for referencing a project script.

---

- HTML version: https://www.matthewswong.com/en/blog/claude-code-hook-fixture-debugging/
- Bahasa Indonesia: https://www.matthewswong.com/id/blog/claude-code-hook-fixture-debugging/
- Site index for agents: https://www.matthewswong.com/llms.txt
- Sitemap: https://www.matthewswong.com/sitemap.xml
- API description (OpenAPI): https://www.matthewswong.com/openapi.json
