Skip to content
wynneyinPublic

About

Claude Code hooks 本地诊断工具:检查配置、测试脚本,探测真实会话中的 hook 回调。

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

5 Commits

Folders and files

Repository files navigation

HookProbe

Did your hook actually run?

A small, local CLI for diagnosing Claude Code command hooks. Separate readable configuration, executable handlers, and observed runtime behavior.

简体中文 · Evidence boundaries · Examples

HookProbe v0.2 is implemented and tested on macOS. Linux is a build/CI target. On 2026-11-15 a real Claude Code 2.1.323 session accepted the probe's flags and delivered an injected SessionStart callback. The same run reached an API gateway that answered 429, so no tool call happened and the PreToolUse/PostToolUse canaries remain unverified. Details are in validation.

Try it

Requires Go 1.22+ to build. The resulting binary has no third-party runtime dependencies.

go build -o dist/hookprobe ./cmd/hookprobe
./dist/hookprobe events
./dist/hookprobe demo

events prints the supported hook events, the input field each matcher filters on, and what exit code 2 does for that event. demo runs a harmless built-in hook with simulated input. Neither starts Claude, uses model quota, or changes your settings.

Inspect configuration

./dist/hookprobe check --project /path/to/project
./dist/hookprobe check --settings examples/settings.json
./dist/hookprobe check --settings examples/settings.json --json

Default discovery inventories:

  • ${CLAUDE_CONFIG_DIR}/settings.json, or ~/.claude/settings.json when the variable is unset
  • PROJECT/.claude/settings.json
  • PROJECT/.claude/settings.local.json

--project defaults to the current directory; ancestor directories are not walked. Explicit --settings files replace discovery and may be repeated. IDs are stable for the same ordered source files, event, group and handler: s1/PreToolUse/1/1.

Group matchers are validated. A matcher that is a regular expression is compiled before anything else is claimed about the handler, so a typo such as Bash( fails the check instead of silently never firing. Matchers made only of letters, digits, _, -, spaces, , and | are compared as exact strings or as |/,-separated lists, which is how Claude Code reads them. A matcher on an event without matcher support is reported as ignored, not as an error.

This is an inventory of those files. It does not resolve effective settings precedence or discover managed policies, plugins, skill hooks or command-line settings from an existing Claude session. Commands and unrelated settings are omitted from reports.

Test one handler

Run this example from the repository root:

./dist/hookprobe test \
  --settings examples/settings.json \
  --hook s1/PreToolUse/1/1

The example denies every simulated Bash call. It is a diagnostic fixture, not a recommended hook to install into your normal settings.

The report starts with a matcher check: with the default Bash fixture, a Write-only hook is reported as "would not fire" and stays inconclusive even if the handler itself behaves. This is the case where a hook is correct but never selected.

Test an existing, trusted hook using its ID from check:

./dist/hookprobe test \
  --settings /path/to/project/.claude/settings.json \
  --project /path/to/project \
  --hook s1/PreToolUse/1/1 \
  --payload examples/pre-tool-use.json \
  --timeout 5s --json

test executes exactly one selected hook as your current user, with the current environment and project working directory. It is not a security sandbox. Matchers are evaluated only against the supplied payload, and native registration is not evaluated at all. --payload - reads the event JSON from stdin, so a payload copied out of a debug log can be replayed without writing a file. Settings env, if conditions, plugin context and session-specific variables are not synthesized. Supply a custom event payload when the default Bash fixture is not representative.

Shell-form commands use /bin/sh -c by default, or /bin/bash -c for shell: "bash". Exec-form hooks with an args array preserve argument boundaries and substitute ${CLAUDE_PROJECT_DIR} without shell evaluation. Captured stdout and stderr are limited to 64 KiB each. Timeouts terminate the owned process group; truncated output is inconclusive.

Protocol interpretation distinguishes a PreToolUse deny from non-blocking feedback after a tool has already run. A valid handler response alone does not demonstrate that Claude applied it.

Probe the runtime

./dist/hookprobe probe
./dist/hookprobe probe --claude /path/to/claude --timeout 60s --json

This starts a real Claude CLI session using existing authentication and quota, capped at $0.25 and four turns. It may fail to complete within the cap. No CLI is installed or login started automatically.

HookProbe creates a private temporary project and its own synchronous canary hooks. It asks Claude to attempt two exact harmless commands. One creates a marker; the second is denied by a PreToolUse hook. Callback metadata and marker files are the evidence. The model's response text is never treated as proof.

The session uses Bash only, non-interactive permissions, explicit temporary settings, disabled user/project settings sources, empty strict MCP configuration, no persisted session, and a deadline. HookProbe does not use permission-bypass flags. This temporary directory is not an OS sandbox: Claude still runs as your user, authentication remains available, and managed policy can still affect the session. All temporary canary artifacts are removed after the report.

A passing canary verifies HookProbe's injected hooks in that invocation. It does not prove your existing hooks were discovered, matched, or registered in their original settings location. Use check and test to narrow a user-hook problem; arbitrary existing-hook registration tracing is outside the current scope.

The report also records the CLI's own result envelope: result subtype, turn count, API error status, terminal reason and the number of permission denials. That is how a rate-limited gateway, an expired login or a rejected flag is distinguished from "hooks did not fire". The conversation, prompt, model text and auth diagnostics are never copied into the report.

If Claude is absent, events are missing, authentication fails, or execution is inconclusive, the result is UNKNOWN. A denied command that actually creates its marker is FAIL.

What PASS means

Command PASS establishes Still unverified
check Supported entries in the selected files are readable Execution, effective policy, runtime registration
test Selected handler completed with an interpretable response to the fixture, and its group matcher selects that fixture Native registration, actual session environment, Claude enforcement
probe Injected canary callbacks and allow/deny side effects were observed Existing-user-hook registration
demo Built-in handler works against a local fixture All live Claude behavior

Every JSON report includes schema_version, mode, evidence_scope, verdict and individual checks. Live reports include command hashes and callback metadata, never the CLI conversation.

Exit codes:

Code Meaning
0 PASS within the report's explicit scope
1 FAIL: a definite problem was observed
2 Invalid invocation or internal/reporting error
3 UNKNOWN: unsupported, missing or inconclusive evidence

Supported scope

  • macOS/Linux command execution; Go 1.22+
  • Synchronous command handlers
  • 13 events with their documented exit-code and JSON semantics: SessionStart, Setup, UserPromptSubmit, PreToolUse, PostToolUse, PostToolUseFailure, Notification, SubagentStart, SubagentStop, Stop, PreCompact, PostCompact, SessionEnd
  • Per-event decision validation: permissionDecision on PreToolUse, top-level decision only where the event honors it, additionalContext only where it is injected, and continue only where it is read
  • Matcher evaluation for the events that support matchers, with JavaScript-only patterns (lookahead, backreferences) reported as inconclusive
  • Shell and exec forms, custom event JSON or stdin payloads, bounded execution, JSON reports

Other hook types, events and shells are reported as unsupported. Conditional if hooks and native plugin placeholders also return UNKNOWN. Known configuration/output field types are checked; complex unimplemented output fields and deferred decisions remain inconclusive. Windows execution, installed-plugin discovery, full schema validation, automatic fixes, and testing arbitrary existing hooks in their native registration context are outside this release.

A decision field on the wrong event is silent in a real session. HookProbe reports it as UNKNOWN with the field named, rather than as a working decision.

Privacy

No telemetry, server or account is built into HookProbe. check, test and demo do not themselves make network requests; selected hook commands may do anything the current user can do. probe starts Claude, which makes its own service requests.

Reports exclude raw commands and environment settings. Captured handler output is bounded and common credential patterns are redacted on a best-effort basis. This is not a guarantee that arbitrary sensitive output is removed; review reports before sharing them. JSON reports are written to stdout, not uploaded or saved automatically.

Development

go test -race ./...
go vet ./...
go build -o dist/hookprobe ./cmd/hookprobe

Tests cover real handler subprocesses, shell/exec argument boundaries, process cleanup, malformed configuration, per-event exit-code and JSON semantics, matcher evaluation, report exits and a scripted Claude transport. The transport double explicitly checks invocation flags, runs the real recorder as subprocesses and attempts marker commands. It does not substitute for a real-Claude compatibility check.

See design, implementation plan, and validation.

Protocol references checked 2026-11-15: hooks, settings, CLI. Runtime support can vary by Claude version; an unsupported CLI invocation remains inconclusive. The probe was exercised against Claude Code 2.1.323 on 2026-11-15.

MIT licensed. No repository has been published by this local build.

hookprobe

About

Claude Code hooks 本地诊断工具:检查配置、测试脚本,探测真实会话中的 hook 回调。

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages