Skip to content

chore(worktree): keep Claude Code worktrees out of the working tree - #52

Merged
anilcancakir merged 3 commits into
masterfrom
chore/worktree-layout
Sep 3, 2026
Merged

chore(worktree): keep Claude Code worktrees out of the working tree#52
anilcancakir merged 3 commits into
masterfrom
chore/worktree-layout

Conversation

@anilcancakir

Copy link
Copy Markdown
Contributor

What

.gitignore: ignore .claude/worktrees/ (only that subdirectory; the rules under .claude/ stay tracked).

Why

Worktrees were opened beside the checkout as <repo>-<slug>, so they landed in the workspace directory next to the real repositories, and Claude Code's EnterWorktree could not be used at all: it writes to a fixed .claude/worktrees/<slug>. With them inside the repository, git has to be told to ignore them.

No .worktreeinclude here, because this repository keeps no pubspec_overrides.yaml; there is nothing gitignored that a worktree would need. Sibling repositories that do carry one get that file too, see fluttersdk/magic_starter#124.

Testing

Config only. No Dart, YAML or lib/ file is touched, so analyze, format and test have nothing to say about this diff.

Worktrees used to sit beside the checkout as <repo>-<slug>, which put them in the workspace directory next to the real repositories and left EnterWorktree unusable, since that tool writes to a fixed .claude/worktrees/<slug>. Pattern proven on fluttersdk/magic_starter#124.
@kodizm

kodizm Bot commented Sep 3, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

Correct as-is: a single scoped .gitignore entry that ignores .claude/worktrees/ without touching the tracked rules under .claude/.

I verified the pattern does what the description claims, and that a worktree placed there cannot leak into the pub.dev archive:

  • git check-ignore -v .claude/worktrees/foo/x.dart.gitignore:48:.claude/worktrees/ (matched), while .claude/rules/ stays tracked (git ls-files .claude/ still lists the rule files).
  • .pubignore already carries .claude/ at line 91, so an untracked worktree under it is excluded from the publish archive too (.pubignore replaces .gitignore for dart pub publish, so this mattered).

The comment style matches the surrounding file (grouped section with a # header), and no dashes or forbidden keywords per CLAUDE.md.

Tests

None, and none needed: the diff is five lines of .gitignore, no Dart, YAML or lib/ file is touched. CHANGELOG.md under ## [Unreleased] is not required here either, since Golden Rule 5 covers behavioral or interface changes and this alters neither.

Checks I ran

  • git check-ignore -v .claude/worktrees/foo/x.dart → matched at .gitignore:48.
  • grep -n "claude" .pubignore91:.claude/, publish archive unaffected.
  • Skipped dart analyze / dart format / dart test: no Dart source in the diff, so they cannot change verdict.

@kodizm

kodizm Bot commented Sep 3, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

Since my last review the only change is four extra comment lines in .gitignore; the ignore rule itself is untouched and still correct, with one stray character to tidy.

Minor

.gitignore:46# under it are part of the repository.# has a trailing # glued onto the sentence, which looks like a blank comment separator (#) that lost its newline before the new paragraph. Cosmetic only, git parses the whole line as a comment either way. (maintainability)

Tests

None, and none needed: comment-only change to .gitignore, no Dart, YAML or lib/ file touched. Golden Rule 5 covers behavioral or interface changes, so no ## [Unreleased] entry is required.

Checks I ran

  • git check-ignore -v .claude/worktrees/foo/x.dart.gitignore:52:.claude/worktrees/, still matching after the comment shift.
  • tail -12 .gitignore | cat -A → confirms the stray # at end of the repository. line and that .claude/worktrees/ is the only pattern added.
  • Skipped dart analyze / dart format / dart test: no Dart source in the incremental diff, so they cannot change the verdict.

The comment claimed plain -xdf wipes a live worktree because its .git is a file rather than a directory. Measured on a scratch repo: the dry run prints "Skipping repository .claude/worktrees/slug", the worktree survives -xdf with its untracked files intact, and only -xdff removes it and leaves the registration prunable. The guard keys on the gitlink, not on the form of .git. Also splits the stray # that joined the two comment blocks.
@kodizm

kodizm Bot commented Sep 3, 2026

Copy link
Copy Markdown

Note

Kodizm (AI-generated). May contain mistakes; verify before acting.

Since my last review the stray # is gone and the comment now describes git clean correctly; I reproduced both claims, and the ignore rule itself is unchanged and still right.

The new paragraph is a factual claim, so I tested it in a scratch repo with a worktree at .claude/worktrees/slug:

  • git clean -xdfSkipping repository .claude/worktrees/slug, and scratch.txt inside it survived. The gitfile-resolving nested-repo guard behaves as the comment says.
  • git clean -xdffRemoving .claude/, the worktree contents gone while .git/worktrees/slug remained and git worktree list showed it as prunable. That matches the second half of the comment, including the git worktree prune follow-up.

No findings. Nothing else in the incremental diff.

Tests

None, and none needed: comment-only change to .gitignore, no Dart, YAML or lib/ file touched. Golden Rule 5 covers behavioral or interface changes, so no ## [Unreleased] entry is required.

Checks I ran

  • Scratch-repo reproduction of both git clean -xdf and -xdff against a nested worktree: output matched the comment in both cases (quoted above).
  • git check-ignore -v .claude/worktrees/foo/x.dart.gitignore:54:.claude/worktrees/, still matching after the comment shift.
  • git ls-files .claude/.claude/rules/installer.md, .claude/rules/tests.md still tracked; the entry stays scoped to the subdirectory.
  • grep -n '[em/en dash]' .gitignore → no matches, so the new lines respect the CLAUDE.md dash ban.
  • Skipped dart analyze / dart format / dart test: no Dart source in the incremental diff, so they cannot change the verdict.

@anilcancakir
anilcancakir merged commit 263cd7c into master Sep 3, 2026
4 checks passed
@anilcancakir
anilcancakir deleted the chore/worktree-layout branch September 3, 2026 18:04
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.

1 participant