Skip to content

Commit f66a601

Browse files
committed
docs: add shared build cache example
Show how to symlink node_modules, .venv, or target/ from a central per-repo cache to avoid redundant installs across worktrees.
1 parent df88a43 commit f66a601

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

docs/examples.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,32 @@ Or source it in a shell script:
119119
source .env.port 2>/dev/null || PORT=3000
120120
echo "Starting dev server on port $PORT"
121121
```
122+
123+
## Shared build cache across worktrees
124+
125+
Each worktree normally gets its own `node_modules`, `.venv`, or build output directory. This wastes disk space and install time. Use a hook to symlink these from a shared per-repo cache:
126+
127+
```toml
128+
[hooks]
129+
# Node.js — share node_modules via a central cache per repo
130+
post_create = [
131+
"mkdir -p $HOME/.cache/wt/$WT_REPO_NAME/node_modules && ln -sf $HOME/.cache/wt/$WT_REPO_NAME/node_modules $WT_PATH/node_modules && cd $WT_PATH && npm install"
132+
]
133+
134+
# Python — share a single venv per repo
135+
# post_create = [
136+
# "mkdir -p $HOME/.cache/wt/$WT_REPO_NAME/venv && ln -sf $HOME/.cache/wt/$WT_REPO_NAME/venv $WT_PATH/.venv && cd $WT_PATH && uv sync"
137+
# ]
138+
139+
# Rust — share the target directory
140+
# post_create = [
141+
# "mkdir -p $HOME/.cache/wt/$WT_REPO_NAME/target && ln -sf $HOME/.cache/wt/$WT_REPO_NAME/target $WT_PATH/target"
142+
# ]
143+
```
144+
145+
All worktrees for the same repo point to one `node_modules` (or `.venv`, or `target/`). The first `npm install` populates the cache; subsequent worktrees reuse it instantly.
146+
147+
> **Note:** Shared mutable caches work well for dependencies that are branch-independent. If branches use different dependency versions, consider per-branch cache keys instead:
148+
> ```bash
149+
> mkdir -p $HOME/.cache/wt/$WT_REPO_NAME/$WT_BRANCH/node_modules
150+
> ```

0 commit comments

Comments
 (0)