Skip to content

fix(repo): anchor .claude/worktrees/ ignore so knip passes in worktrees - #163

Open
julien-devatom wants to merge 1 commit into
mainfrom
claude/happy-cray-ncgru4
Open

fix(repo): anchor .claude/worktrees/ ignore so knip passes in worktrees#163
julien-devatom wants to merge 1 commit into
mainfrom
claude/happy-cray-ncgru4

Conversation

@julien-devatom

@julien-devatom julien-devatom commented Aug 14, 2026

Copy link
Copy Markdown
Collaborator

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.

Claude-Session: https://claude.ai/code/session_01U2Q549YrFLNj99noBuJyc9


Open in Devin Review

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
@julien-devatom julien-devatom self-assigned this Aug 14, 2026

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

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.

2 participants