chore(worktree): auto-run yarn install on new worktrees

Add a Claude Code SessionStart hook (matcher: startup) that runs
`corepack yarn install` when node_modules is missing, so worktrees Claude
creates internally are immediately usable. Also extend create-task-worktree.sh
to install deps after the worktree is created, covering Codex/Cursor/manual
flows that share that script.
This commit is contained in:
Tommaso Casaburi
2026-04-17 14:30:41 +07:00
parent 2b79432f16
commit d07f5b3962
3 changed files with 44 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
#!/bin/bash
# SessionStart hook: ensure dependencies are installed for the current worktree.
# Runs `corepack yarn install` when node_modules is missing, so new Claude-created
# worktrees are usable immediately without a manual install step.
set -u
repo_root="${CLAUDE_PROJECT_DIR:-$(git rev-parse --show-toplevel 2>/dev/null || pwd)}"
cd "$repo_root" 2>/dev/null || exit 0
# No yarn.lock → not a yarn project or fresh clone; nothing to do.
[ -f "yarn.lock" ] || exit 0
# node_modules already populated → nothing to do (fast path).
if [ -d "node_modules" ] && [ -n "$(ls -A node_modules 2>/dev/null | head -1)" ]; then
exit 0
fi
echo "[claude hook] node_modules missing in $repo_root — running corepack yarn install..."
corepack yarn install
exit 0
+16
View File
@@ -0,0 +1,16 @@
{
"hooks": {
"SessionStart": [
{
"matcher": "startup",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/session-start.sh",
"timeout": 600
}
]
}
]
}
}