@devries-cameron20 / t3code-1 / commits / f8a308fbc9
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(dev): worktree setup never deletes a real env file (#15845)

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

Julius Marminge committed Oct 4, 2026 at 19:18 UTC f8a308fbc90e89cd5f8d41b7fb169a03343bd9b5
1 file changed +15 -8
scripts/setup-worktree.ts
+15 -8
@@ -26,15 +26,22 @@ const install = NodeChildProcess.spawnSync("vp i", {
26 });
27 if (install.status !== 0) process.exit(install.status ?? 1);
28
29 -// In the main checkout itself, relinking would replace the real env files.
30 -if (NodeFS.realpathSync(projectRoot) !== NodeFS.realpathSync(worktree)) {
31 - for (const file of ENV_FILES) {
32 - const source = NodePath.join(projectRoot, file);
33 - if (!NodeFS.existsSync(source)) continue;
34 - const target = NodePath.join(worktree, file);
35 - NodeFS.rmSync(target, { force: true });
36 - NodeFS.symlinkSync(source, target);
29 +// Env files live as real files in the main checkout; worktrees only get
30 +// symlinks to them. Only a symlink is ever replaced, so a real env file is
31 +// never deleted, including when this runs in the main checkout itself.
32 +for (const file of ENV_FILES) {
33 + const source = NodePath.join(projectRoot, file);
34 + const sourceStat = NodeFS.lstatSync(source, { throwIfNoEntry: false });
35 + if (!sourceStat) continue;
36 + if (!sourceStat.isFile()) {
37 + console.warn(`Skipping ${file}: ${source} is not a regular file.`);
38 + continue;
39 }
40 + const target = NodePath.join(worktree, file);
41 + const existing = NodeFS.lstatSync(target, { throwIfNoEntry: false });
42 + if (existing && !existing.isSymbolicLink()) continue;
43 + if (existing) NodeFS.rmSync(target);
44 + NodeFS.symlinkSync(source, target);
45 }
46
47 const warm = NodeChildProcess.spawnSync(