Skip to content

fix(#1264): post-tool hook runs only the project's local prettier, never npx - #1267

Merged
admarble merged 3 commits into
mainfrom
feature/1264-fix-hooks-post-tool-hook-downloads-and-runs-the-la
Oct 1, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/1264-fix-hooks-post-tool-hook-downloads-and-runs-the-la

Conversation

@admarble

@admarble admarble commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1264.

What changed

  • templates/hooks/post-tool.sh no longer runs npx prettier. For a .ts/.tsx/.js/.jsx/.json edit, it resolves the edited file's repo root (git -C "$(dirname "$FILE_PATH")" rev-parse --show-toplevel). It runs $ROOT/node_modules/.bin/prettier only when that file is executable; otherwise it logs SKIP_FORMAT (no local prettier): <file>.
  • The two formatting branches (TS/JS and JSON) are merged into one, so a JSON format failure is no longer silent.
  • .claude/hooks/post-tool.sh was regenerated with npm run sync:hooks.
  • New __tests__/post-tool-format.integration.test.ts runs the real hook against temp git repos with npm_config_cache pointed at an empty dir:
    • No local prettier: no download, the skip is logged, and the file is unchanged.
    • A stub node_modules/.bin/prettier: the stub runs, including for a nested file.
  • CHANGELOG records the behaviour change: projects without a local prettier are no longer auto-formatted.

AC

  • AC-1: grep -nE '\b(npx|bunx|pnpm dlx|yarn dlx|uvx)\b' templates/hooks/post-tool.sh matches 0 lines.
  • AC-2: the new integration test passes. It is mutation-verified below.
  • AC-3: hook-sync.test.ts passes; .claude/hooks/post-tool.sh is byte-identical to the template.
  • AC-4: CHANGELOG entry under Unreleased.

Mutation-verified: AC-2 — restored npx prettier --write as the formatter in templates/hooks/post-tool.sh; tests/post-tool-format.integration.test.ts > post-tool.sh auto-format (#1264) > skips formatting and logs the reason when no local prettier exists failed; restored.

Both cases failed under the mutant: the no-prettier case because npm's cache was no longer empty, and the stub case because the stub never ran.

Verification

  • npx vitest run __tests__/post-tool-format.integration.test.ts src/lib/relay/__tests__/hook-sync.test.ts: 5/5 pass.
  • Every other test file naming the hook or its log strings: init.codex.integration, hook-sync, pre-tool-hook.integration, relay-hook-env, integration/relay-hook.integration. 452/452 pass.
  • The full suite was not run locally. The sequant run exec phase hit the 30-minute no-progress watchdog while running it, so QA never ran. CI runs it.

Known trade-offs

🤖 Generated with Claude Code

…d reason

templates/hooks/post-tool.sh no longer runs npx prettier. It resolves the edited file's repo root and only runs node_modules/.bin/prettier when that binary exists; otherwise it logs SKIP_FORMAT (no local prettier) instead of downloading an unpinned package from the registry.

Entire-Checkpoint: 6a2a1a847502
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.

fix(hooks): post-tool hook downloads and runs the latest prettier via npx in every project that doesn't have it

1 participant