chore: auto-set-up new worktrees with env copy, install, and build#443
Open
MarioCadenas wants to merge 2 commits into
Open
chore: auto-set-up new worktrees with env copy, install, and build#443MarioCadenas wants to merge 2 commits into
MarioCadenas wants to merge 2 commits into
Conversation
Translate the Cursor .cursor/worktrees.json setup into Claude Code worktrees: - .worktreeinclude (repo root): copies gitignored .env / .env.local into new worktrees at creation time, using .gitignore glob syntax. - .claude/settings.json: registers a SessionStart hook (startup/resume). - .claude/hooks/setup-worktree.sh: runs 'pnpm install' + 'pnpm run build' the first time a session opens in a fresh linked worktree (guarded on missing node_modules), and is a silent no-op in the primary checkout and in already-set-up worktrees. Co-authored-by: Isaac Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
Mirror .cursor/worktrees.json by naming the exact files to copy (apps/dev-playground/.env, apps/clean-app/.env) instead of a bare `.env` glob, so worktree creation copies precisely the dev env files and nothing picked up at unexpected depths. Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>
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.
Translates the Cursor
.cursor/worktrees.jsonsetup into the equivalent for Claude Code worktrees, so a freshly created worktree is ready to run without manual setup.What it does
setup-worktreestepcp .../apps/dev-playground/.env.worktreeinclude(native, copies at creation)cp .../apps/clean-app/.env.worktreeinclude(pattern.envmatches both)pnpm installSessionStarthook →.claude/hooks/setup-worktree.shpnpm run buildFiles
.worktreeinclude(repo root) — Claude Code copies gitignored files matching these.gitignore-syntax globs (.env,.env.local) into new worktrees at creation time. Tracked templates like.env.dist/.env.tmplare never duplicated..claude/settings.json— registers aSessionStarthook (startup/resume)..claude/hooks/setup-worktree.sh— runspnpm install+pnpm run buildthe first time a session opens in a fresh linked worktree (guarded on missingnode_modules). Silent no-op in the primary checkout and in already-set-up worktrees; build failures are reported on stderr but never block session startup.Why a
SessionStarthook (notWorktreeCreate)Claude Code has no post-create worktree hook. The only worktree hook,
WorktreeCreate, replaces git's worktree creation entirely (and disables.worktreeinclude), which would mean reimplementing git's default branch/baseRef/placement logic and risk disrupting subagent worktree creation. TheSessionStartapproach is additive and never touches how worktrees are created. Trade-off: install/build run at first session-start rather than at creation (moments later in practice).Notes
.worktreeincludeis read by Claude Code, not git, so it does not affect worktrees created by other tools..claude/worktrees/to.gitignoreso agent worktree copies stop appearing ingit status.This pull request and its description were written by Isaac.