Skip to content

feat(checker): run as a Claude Code hook with --claude-code-hook - #60

Merged
afterimaginary merged 4 commits into
mainfrom
feat/claude-code-hook
Oct 26, 2026
Merged

afterimaginary merged 4 commits into
mainfrom
feat/claude-code-hook

Conversation

@afterimaginary

@afterimaginary afterimaginary commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

The README's Claude Code hook was a long shell pipeline squeezed into one JSON string. It needed jq and couldn't work on Windows. The checker now does that work itself:

"command": "\"$CLAUDE_PROJECT_DIR\"/node_modules/.bin/complexity-hints --claude-code-hook"

With --claude-code-hook, the checker:

  • reads the hook's JSON from stdin;
  • checks the project files the tool call changed: tool_input.file_path, or tool_response.bashEditDiff.changedFiles for Bash;
  • prints to stderr, and exits 2 when something blocks so Claude Code shows the agent;
  • exits 1 when the check can't run, which shows the user an error without blocking the agent.

A call that changed no project file exits 0 without running Git or Oxlint.

It also adds a root install.md, in the install.md format (OBJECTIVE, DONE WHEN, a TODO list, the steps, EXECUTE NOW). A user pipes it into Claude Code (curl -fsSL …/install.md | claude), or points their agent at it, to set everything up in their project:

  • check prerequisites;
  • install the package;
  • turn on the preset;
  • add the hook, asking whether it goes in shared or personal settings;
  • tell the user about bashEditDiffEnabled;
  • add the guidance to CLAUDE.md;
  • offer a commit or CI gate;
  • check that it works, and report back.

The README links it from the top, with the one-liner. The format says to execute autonomously, but the guide keeps the steps where it asks the user first.

Changes

  • The hook's input parsing lives in src/checker/claude-code.ts. cli.ts gained a hook path that filters files to the project, checks from the project's directory, and remaps exit codes. The plain CLI is unchanged.

  • install.md's hook block must match the README's; a test enforces it.

  • The guide tells the agent to ask before editing user settings or adding CI tooling, and not to fix existing over-max functions.

  • The guide says the package isn't on npm yet, so it stops at the install step until the first release.

  • Vitest now runs only tests/**/*.test.ts. A Claude Code worktree under .claude/worktrees/ holds its own copy of tests/, which Vitest otherwise picked up and failed on, blocking the pre-push hook.

Verification

  • vp run ready: format, lint, typecheck and 107 tests pass. smoke-dist also runs the built bin in hook mode.

  • The hook tests run the README's command with /bin/sh from outside the project, against a stand-in install. They cover:

    • blocks → 2 with diagnostics on stderr;
    • notes only → 0;
    • Bash with changed, unrelated or no files;
    • a file outside the project, and the project directory itself, → 0;
    • no CLAUDE_PROJECT_DIR → the current directory is the project;
    • no default branch, input that isn't JSON or isn't an object, or arguments given → 1;
    • not installed → 127.
  • One /refine round with two reviewers. Findings applied:

    • one source of truth for hook mode;
    • a clear error for null input;
    • the project directory no longer counting as a file;
    • relative paths resolved against the project;
    • guide fixes: the Vite+ Oxlint version, the install command, the alias case, bun.lockb, where --base goes, and running the hook once to check it.
  • Live run, Claude Code 2.1.302, headless sessions on a scratch project with the packed build: every hook scenario behaved as documented:

    • an Edit that pushes a function over the max: exit 2, and the agent acted on the hint;
    • an edit made through Bash (with CLAUDE_CODE_BASH_EDIT_DIFF=1): exit 2, and the agent fixed it;
    • an edit to a simple file: exit 0, silent;
    • notes only: exit 0, not shown to the agent;
    • a file outside the project: exit 0 in 46 ms, without running Git or Oxlint;
    • no default branch: exit 1, and the agent wasn't blocked;
    • a new untracked file: checked, exit 2.

    No EAGAIN appeared. A fresh agent followed the setup guide and got everything in place except the hook, because Claude Code protects its settings files. The fixes from that run are in the last commit:

    • the guide now says Claude Code asks before writing its settings, and what to do if it can't write them;
    • the step-7 check now uses a command without quoting, since Claude Code refused the old one;
    • the Bash-diff wording now matches how Claude Code behaves: on by default in auto and bypass modes, or CLAUDE_CODE_BASH_EDIT_DIFF=1 for a session.

Observations

afterimaginary and others added 4 commits October 26, 2026 09:30
The checker reads a PostToolUse hook's input itself, so the hook in the
README is one command instead of a shell pipeline that needed jq. A new
docs/agent-setup.md walks a coding agent through installing and
configuring the plugin, the checker and the hook, linked from the top of
the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The guide follows the install.md format (installmd.org), at the repository
root, so it can be piped into Claude Code from the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Worktrees under .claude/worktrees/ hold their own copies of tests/, which
Vitest otherwise picks up and fails to run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude Code asks before writing its settings files and refuses the old
step-7 command's quoting, and records Bash diffs in more cases than the
docs said.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@afterimaginary
afterimaginary marked this pull request as ready for review October 26, 2026 17:25
@afterimaginary
afterimaginary merged commit 4beea3d into main Oct 26, 2026
1 check passed
@afterimaginary
afterimaginary deleted the feat/claude-code-hook branch October 26, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant