feat: copy .worktreeinclude files into new worktrees - #330
Merged
Conversation
Adopt the .worktreeinclude convention shared by Claude Code, Conductor, OpenAI Codex, and git-worktreeinclude: a gitignore-syntax file at the repository root listing gitignored files (e.g. .env) to carry into every new worktree, so an existing .worktreeinclude a user already has for those tools works with ccmanager unchanged. A file is copied only when it both matches a .worktreeinclude pattern and is actually gitignored (git ls-files --others --ignored --exclude-from resolves the pattern match; git check-ignore --stdin confirms real ignore status), so a tracked file is never duplicated even if it happens to match a pattern. No config flag gates this: it runs whenever a .worktreeinclude file exists, matching the other tools' behavior, and non-fatally logs a warning on failure like the existing .claude directory copy step. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The feature had no user-facing documentation. Add docs/worktree-include.md covering why a worktree needs gitignored files copied, the shared .worktreeinclude convention, pattern syntax, the match-and-actually-ignored selection rule, when the copy runs relative to the post-creation hook, and how it relates to the existing session-data / .claude copy options. Link it from README.md with a short overview section next to the other worktree-creation features, plus a Features bullet. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DgkE2WS9WzDF3sQrLBFKCA
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.
Problem
A new git worktree only gets tracked files, so gitignored files a project needs to actually run —
.env, local certs, etc. — don't carry over. ccmanager had no way to copy them automatically; the closest existing feature (copySessionData/copyClaudeDirectory) only copies Claude Code's own session data or.claude/, not arbitrary project files..worktreeincludehas emerged as a shared convention for this across worktree-aware tools — Claude Code, Codex, Conductor, and the standalonegit-worktreeincludeCLI all read a gitignore-syntax.worktreeincludefile at the repository root and copy the gitignored files it selects into each new worktree. Adopting the same file name and semantics means a.worktreeincludea user already maintains for those tools works with ccmanager unchanged, instead of requiring a second, ccmanager-specific config for the same thing.Out of scope: no new config toggle was added — the copy step runs whenever a
.worktreeincludefile exists, matching how the other tools behave, so there's nothing to configure.Verification
Prerequisites:
bun run testcan be run from the repo root)Steps:
bun run typecheck— confirmed it exits with no errorsbun run lint— confirmed it exits with no errorsbun run test— confirmed all tests pass (1848 passed / 10 skipped), including the newsrc/utils/worktreeInclude.test.tsintegration tests (real git repos: selects a matching+gitignored file, excludes a matching-but-not-ignored file, excludes a tracked file even if it matches, resolves a directory glob pattern, doesn't overwrite an existing destination file).worktreeincludelisting.env, added.envto.gitignore, created a.envfile withSECRET=verify-me, then calledWorktreeService.createWorktreeEffect(the same code path the TUI's "create worktree" flow uses) — confirmed the new worktree's.envexists with contentSECRET=verify-me