Skip to content

docs(readme): run complexity-hints from the agent hook and as a gate - #58

Merged
afterimaginary merged 3 commits into
mainfrom
feat/agent-hook
Oct 26, 2026
Merged

afterimaginary merged 3 commits into
mainfrom
feat/agent-hook

Conversation

@afterimaginary

@afterimaginary afterimaginary commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Closes #45

Summary

Rewrites the README's "For agents" section around complexity-hints (#44), so an agent is held only to what its change is responsible for:

  • Per-edit hook. A Claude Code PostToolUse hook on Edit|Write|Bash runs the checker on the files the call changed: tool_input.file_path, or tool_response.bashEditDiff.changedFiles for Bash. A block exits 2, which shows the diagnostics to the agent. A check that can't run (no jq, no install, no base branch) exits 1, which the user sees and which doesn't block the agent. A call that changed no project file passes without running the checker.
  • Commit and CI gate. npx --no complexity-hints before each commit, and a pull_request workflow step with fetch-depth: 0, an install, and --base origin/${{ github.base_ref }}.
  • Guidance for agent instructions. Keep refactoring within the change. Restructure an over-max function the change touches in its own behavior-preserving commit first. Don't raise max or add disable comments. Also covers notes versus --strict, and one worktree per parallel agent.

Changes

  • The section opens by saying the agent setup is written for and tested with Claude Code only, and Limits says so too; other agents are untested for now.
  • Bash edits are covered through bashEditDiff (Claude Code 2.1.269+). The README says it records in every permission mode only with bashEditDiffEnabled: true in user settings, since a project's settings can't turn it on.
  • The hook stays a copy-paste shell command using jq, as before. Files are collected with set -- rather than xargs, which would turn the checker's exit 1 into 123 and break the exit mapping.
  • npx --no avoids fetching an unrelated registry package named complexity-hints when the project's own isn't installed.

Verification

  • vp run ready: format, lint, typecheck and 105 tests pass.
  • tests/checker.test.ts extracts the README's hook command and runs it with /bin/sh from outside the project, with CLAUDE_PROJECT_DIR pointing at a temporary repository whose node_modules/.bin/complexity-hints runs the checker from source. It covers:
    • a block exits 2, with the diagnostics on stderr;
    • notes only exit 0;
    • Bash with changed files, unrelated files, and none;
    • a file outside the project;
    • no default branch, no jq, and no install, each exiting 1.
  • I removed the no-files guard, the exit-1 mapping and the project filter from the command one at a time, and each removal fails a test.
  • One /refine round; findings applied: the CI install and --no, the jq guard, pull_request scope, guidance wording, a stronger notes assertion, and running the hook from outside the project.
  • Not verified: Claude Code's live hook runtime. The bashEditDiff fields, scope and version come from the hooks and settings references.

Observations

  • On a block, the agent also receives the checker's non-blocking notes, since all output is redirected to stderr. That's harmless, and arguably useful context.
  • If CLAUDE_PROJECT_DIR and the tool's file paths ever differ in spelling (symlinks), the project filter would skip files without saying so. The reference documents both as absolute paths.

afterimaginary and others added 3 commits October 26, 2026 08:53
The Claude Code hook now runs on Edit, Write and Bash, checks only the
files each call changed in the project, and passes what blocks back to
the agent. The README also shows the checker as a commit and CI gate,
and gives guidance for agent instructions. Tests run the README's hook
command against a stand-in install.

Closes #45

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@afterimaginary
afterimaginary marked this pull request as ready for review October 26, 2026 16:00
@afterimaginary
afterimaginary merged commit af4de27 into main Oct 26, 2026
1 check passed
@afterimaginary
afterimaginary deleted the feat/agent-hook branch October 26, 2026 16:02
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.

Agent setup: a scoped lint hook and in-scope refactoring

1 participant