Commit c75c39d
chore(worktrees): auto-link .env files on git worktree add
* chore(worktrees): auto-link .env files on git worktree add
Add a shared .githooks/ directory with a post-checkout hook that
symlinks every .env* from the main worktree into each freshly created
worktree. Scoped via two layered checks — prev-HEAD is the null SHA
AND the current worktree isn't the main one — so it fires exclusively
inside `git worktree add`, never on regular branch/file checkouts or
fresh clones.
Enable with a one-time `git config core.hooksPath .githooks` per clone.
Since all worktrees share a single .git/, the config persists for all
current and future worktrees automatically.
The hook delegates to scripts/link-worktree-envs.sh so the same logic
backfills worktrees that existed before the hook was installed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(worktrees): run bun install + db:generate + build on new worktree
After the post-checkout hook symlinks .env files into a freshly created
worktree, it now also invokes scripts/setup-worktree.sh which runs
`bun install`, `bun run db:generate`, and `bun run build` so the
worktree is usable immediately.
Runs synchronously on purpose — callers (especially Claude Code) tend
to start executing in the worktree right after creation, and we don't
want them racing ahead of the install. Skippable via
`SKIP_WORKTREE_SETUP=1 git worktree add …` for a fast "just give me the
files" worktree.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(worktrees): make bun run build opt-in during auto-setup
`bun run build` adds several minutes per worktree and is unnecessary
for the common path (dev server, tests, typecheck). Default the
setup script to install + db:generate only, and gate the build step
behind SETUP_WORKTREE_WITH_BUILD=1 for the rare case it's needed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(worktrees): run prisma migrate before db:generate in setup
After `bun install` and before `bun run db:generate`, run
`cd packages/db && bun run db:migrate` so any new migrations on the
branch are applied to the local DB before the clients are regenerated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(worktrees): isolate DB per worktree to prevent cross-branch drift
Add scripts/setup-worktree-db.sh that creates compdev_<slug> for each
new worktree using the same Postgres host/credentials as main, and
have scripts/link-worktree-envs.sh copy-and-rewrite .env files
containing DATABASE_URL so each worktree's migrations hit its own DB.
Env files without DATABASE_URL stay as symlinks so API keys and such
still auto-propagate.
Uses the `pg` node module from the main worktree's node_modules (via a
small scripts/create-database.mjs helper) so psql/libpq isn't required
on the host.
Skip via SKIP_WORKTREE_DB=1 git worktree add … to opt back into the
shared DB (the previous behavior).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(skills): add stale-worktree-cleanup skill
Defines a safe process for reaping old worktrees together with their
isolated compdev_* databases. Since git has no pre-worktree-remove
hook, dead databases accumulate silently — this skill gives Claude
(or a human) a classify-then-confirm-then-remove workflow so nothing
in-flight gets lost.
Includes inventory via `gh pr list`, per-worktree dirty/unpushed
checks, and safety rules against --force without consent, dropping
non-compdev_* databases, or touching the main worktree.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(worktrees): add dev:no-trigger scripts + single-active-worktree rule
Trigger.dev's `trigger dev` CLI has no per-branch or per-session
isolation — env is hardcoded to the project's shared "dev"
(verified in node_modules/trigger.dev/dist/esm/commands/dev.js).
Running `bun run dev` in multiple worktrees causes last-writer-wins
task registration and zombie workers.
Add dev:no-trigger scripts to apps/app and apps/api (UI-only, no
trigger dev) so only one active worktree runs the full stack at a
time. Document the rule in .githooks/README.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* chore(skills): add new-feature-setup skill documenting the worktree-based workflow
When starting any new feature/ticket/branch, this skill points to the
existing hook-driven auto-setup (compdev_<slug> DB, env linking,
install+migrate+generate) and the single-active-trigger-dev rule so
new Claude sessions don't reinvent env copying, database bootstrapping,
or fight `bun install` by hand in every worktree.
Companion to stale-worktree-cleanup for the other end of the lifecycle.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Mariano <marfuen98@gmail.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 840374b commit c75c39d
10 files changed
Lines changed: 703 additions & 0 deletions
File tree
- .claude/skills
- new-feature-setup
- stale-worktree-cleanup
- .githooks
- apps
- api
- app
- scripts
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
0 commit comments