Skip to content

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

Closed

Description

@admarble

Tier: mechanical Found: 2026-10-01, checking the plugin against Anthropic's directory pre-submission checklist.

Problem. The post-tool hook runs npx prettier --write "$FILE_PATH" after every Edit or Write of a .ts/.tsx/.js/.jsx/.json file (templates/hooks/post-tool.sh:221,228; plugin copy hooks/post-tool.sh:210,217). It has been there since the first commit (49bf820) and nothing gates it except CLAUDE_HOOKS_DISABLED and IS_PARALLEL_AGENT. Checked 2026-10-01 in a scratch project (npm 10.9.8):

  • No local prettier, cold npx cache, non-TTY stdin: npm auto-confirms, downloads the latest prettier ([email protected]), formats the file and exits 0. So every sequant-installed project without prettier fetches and runs an unpinned package from the registry, Python and Go projects included (any .json edit).
  • Offline: ENOTCACHED, exit 1, swallowed by 2>/dev/null. On the JSON branch (:228) the failure isn't logged either.
  • Local prettier installed: npx runs node_modules/.bin/prettier, so projects that do use prettier are unaffected by the fix below.
  • The directory checklist classes an unpinned launcher as Blocks ("Unpinned npx launcher"), and launchers in scripts a hook runs as held for review.

Using the project's configured formatter instead isn't available: StackConfig (src/lib/stacks.ts:620-635) has no format command, and stacks/*.yaml format: is never read. That would be a separate feature.

Scope: every installed project, not only the plugin. templates/hooks/post-tool.sh is what sequant init/sync/update install into .claude/hooks/ (src/lib/templates.ts:560,1317), and npm run sync:hooks regenerates this repo's .claude/hooks/ from it.

AC

  • AC-1: templates/hooks/post-tool.sh runs no package launcher. It finds the edited file's repo root (git -C "$(dirname "$FILE_PATH")" rev-parse --show-toplevel) and runs "$ROOT/node_modules/.bin/prettier" only when that file is executable. Otherwise it skips and logs SKIP_FORMAT (no local prettier) to the hook log. Evidence: grep -nE '\b(npx|bunx|pnpm dlx|yarn dlx|uvx)\b' templates/hooks/post-tool.sh matches 0 lines
  • AC-2: A behaviour gate test runs the hook against a temp project with no prettier and a .ts edit: no download happens (npm cache dir set to an empty temp dir stays empty), and the skip line is logged. A second case with a stub node_modules/.bin/prettier shows the stub ran, including for a file in a subdirectory or worktree. Evidence: a hook test file, mutation-verified by restoring npx prettier
  • AC-3: .claude/hooks/post-tool.sh is regenerated with npm run sync:hooks and stays byte-identical to the template. Evidence: npx vitest run src/lib/relay/__tests__/hook-sync.test.ts
  • AC-4: The CHANGELOG records the behaviour change: projects without a local prettier are no longer auto-formatted. Evidence: grep -n 'prettier' CHANGELOG.md in the Unreleased section

Non-Goals

  • Editing the plugin's root hooks/ copy by hand (the slim-folder issue regenerates it).
  • A per-stack formatter setting.

May touch

  • templates/hooks/post-tool.sh, .claude/hooks/post-tool.sh (regenerated), a new hook test, CHANGELOG.md

Activity

  1. added
    bug
    on Oct 1, 2026
  2. added a commit that references this issue on Oct 1, 2026
  3. admarble commented on Oct 1, 2026

    @admarble
    ContributorAuthor

    Reopened: #1267 fixed templates/hooks/post-tool.sh and .claude/hooks/post-tool.sh, but the plugin ships hooks/post-tool.sh (hooks/hooks.json → ${CLAUDE_PLUGIN_ROOT}/hooks/post-tool.sh). That copy still runs npx prettier --write (lines 210 and 217 on main @ e35f43a), so plugin installs, the main install path, don't get the fix. A follow-up PR ports the block and extends the integration test to every shipped copy. It lands before 2.19.0.

  4. admarble commented on Oct 2, 2026

    @admarble
    ContributorAuthor

    Fixed in v2.19.0. #1267 fixed templates/hooks/post-tool.sh, and since #1265 (PR #1275) the shipped plugin hook plugin/hooks/post-tool.sh is generated from that template and drift-tested. I verified it in the v2.19.0 tag: it runs only node_modules/.bin/prettier. The root hooks/post-tool.sh still contains npx prettier, but it is no longer shipped (marketplace source: ./plugin) and goes away when root hooks/ is retired. PR #1274 closed as redundant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions