Skip to content

Inside The worktree

Ilia edited this page Nov 11, 2026 · 2 revisions

The script creates the worktree, not claude --worktree. The built-in flag does not carry untracked files across, and without them the worktree does not work: .env.local and node_modules are both in .gitignore. sclaude branches from a fresh origin/main, names the branch feat/<slug> (as the pr skill requires) and lays out the environment as symlinks to the main repository — editing a key reaches every feature at once. node_modules is not a symlink but hard links (cp -al): Turbopack refuses to work with a symlink that leads outside the project, and next dev dies at start-up. Links to the same inodes do not duplicate the data — some ten seconds and almost no space. The directory is correct while the branch has not touched the dependencies; the script notices a lockfile that differs from the main repository's and offers the product's install. The folder, the lockfile and the two installs are the product's (deps in its config: node_modules, package-lock.json, npm install and npm ci when it names none). A finished install leaves the hash of the lockfile it installed in <dir>/.sclaude-lock (check_deps in worktree.sh), and a tree whose lockfile still has that hash is not asked again — the main checkout lagging behind origin is enough to make the two differ.

The main checkout is the source of those links, so it is brought up to date first (refresh_main in worktree.sh, called before the worktree is added): on main it is fast-forwarded to origin/main (never over an edit, never with a stash), and a lockfile that moved since its last install gets the clean install there (deps.ci, npm ci by default, which removes the folder first, so the files other trees link stay as they were) — unasked for npm's folder unless a Node process works in the checkout. Another tool's folder cannot be told in use, so its reinstall is asked about, after the lock is let go; a yes takes the lock again and installs unless another start already did. Both run under a lock that linking a tree from that folder takes too. A lockfile comparison alone could not see a main checkout whose lockfile had moved without an install: the tree's lockfile and the main one agreed, and every new feature started on the old packages.

Logs

Every run writes a log of its own, and nothing prunes them: they go with the worktree. The regression, the merge build check, the server the e2e suite runs against and the dev server each keep a folder in .sclaude/local/feature/logs/ — regression/, merge-check/, e2e-server/, dev/ — of files named <kind>_<date>_<time>.log (the regression's kind is its stage: local, preview, prod, rollback), so a listing reads in the order they ran. The old name in .sclaude/local/feature/ (regression.log, dev.log…) is a link to the latest, so whatever read or appended to it meets the current run alone (log_new in worktree.sh). One file rewritten by every run used to lose the run a fixing session needed most: the gate reruns a red stage before opening one, and the dev server is restarted before every local run.

Where a run has an outcome — the regression and the merge build check — its folder also keeps runs.tsv, a line per run: the file, passed or what else it ended as, and the set it ran (a stage and its parts). The file a failure began with is read from it, not stored: the first run after the last that passed on the same set (log_red_since), so a green run on that set closes the failure by being entered, and a run of another set leaves it open.


Generated from docs/sclaude.md; edit it there, then rebuild with wiki/build.py.

Clone this wiki locally