fix(repo): anchor .claude/worktrees/ ignore so knip passes in worktrees - #163
Open
julien-devatom wants to merge 1 commit into
Open
fix(repo): anchor .claude/worktrees/ ignore so knip passes in worktrees#163julien-devatom wants to merge 1 commit into
julien-devatom wants to merge 1 commit into
Conversation
Running `pnpm knip` from an agent worktree nested under .claude/worktrees/ reported 18 false-positive unused files (bots/*/scripts/*.ts, packages/contracts/scripts/*.ts) plus their esbuild/execa devDependencies and several script exports, breaking the pre-commit hook and forcing `git commit --no-verify` in every agent session. Root cause (verified against knip 5.88.1 with --debug and a probe of its glob internals): knip converts the unanchored gitignore line `.claude/worktrees/` into the picomatch pattern `**/.claude/worktrees/**` and passes it as a fast-glob `ignore` to glob() calls whose patterns are absolute paths (deferred package.json script entries, "entry paths from plugins"). fast-glob applies that ignore to the absolute path string, which matches any checkout living under .claude/worktrees/, so the script entries are dropped and everything they reference appears unused. Knip's ancestor-gitignore walk-up is NOT involved — it stops correctly at the worktree's `.git` file; the worktree's own checked-out .gitignore is what feeds the pattern. Anchoring the line with a leading slash is a no-op for git — patterns containing a non-trailing slash are already root-relative per gitignore(5) — but knip then emits `.claude/worktrees/**` without the `**/` prefix, which cannot match an absolute path prefix, so entries in nested worktrees survive. Verified: `pnpm knip` and `sh .husky/pre-commit` exit 0 inside a worktree at .claude/worktrees/knip-repro; `pnpm knip` stays clean in the main checkout with that worktree present; `git check-ignore` confirms the worktree directory is still ignored by the anchored line. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01U2Q549YrFLNj99noBuJyc9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running
pnpm knipfrom an agent worktree nested under .claude/worktrees/ reported 18 false-positive unused files (bots//scripts/.ts, packages/contracts/scripts/*.ts) plus their esbuild/execa devDependencies and several script exports, breaking the pre-commit hook and forcinggit commit --no-verifyin every agent session.Root cause (verified against knip 5.88.1 with --debug and a probe of its glob internals): knip converts the unanchored gitignore line
.claude/worktrees/into the picomatch pattern**/.claude/worktrees/**and passes it as a fast-globignoreto glob() calls whose patterns are absolute paths (deferred package.json script entries, "entry paths from plugins"). fast-glob applies that ignore to the absolute path string, which matches any checkout living under .claude/worktrees/, so the script entries are dropped and everything they reference appears unused. Knip's ancestor-gitignore walk-up is NOT involved — it stops correctly at the worktree's.gitfile; the worktree's own checked-out .gitignore is what feeds the pattern.Anchoring the line with a leading slash is a no-op for git — patterns containing a non-trailing slash are already root-relative per gitignore(5) — but knip then emits
.claude/worktrees/**without the**/prefix, which cannot match an absolute path prefix, so entries in nested worktrees survive.Verified:
pnpm knipandsh .husky/pre-commitexit 0 inside a worktree at .claude/worktrees/knip-repro;pnpm knipstays clean in the main checkout with that worktree present;git check-ignoreconfirms the worktree directory is still ignored by the anchored line.Claude-Session: https://claude.ai/code/session_01U2Q549YrFLNj99noBuJyc9