Skip to content

Commit f043736

Browse files
authored
Added Claude Code Bash hook to align Node version with .nvmrc (#28831)
Adds a `PreToolUse[Bash]` hook so commands inherit the Node version pinned in `.nvmrc`. Works around [anthropics/claude-code#54135](anthropics/claude-code#54135): the Claude Code Desktop launcher enumerates every `~/.nvm/versions/node/v*/bin` directory into PATH in lexical order, so the lowest-installed Node wins regardless of `nvm alias default` or `.nvmrc`. In practice this means agents land on Node 16 (or whatever's lexically first), which crashes corepack at the husky pre-commit hook. The hook sources nvm and runs `nvm use` before each Bash command. Silent no-op on machines without nvm.
1 parent 1ed2aac commit f043736

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

.claude/settings.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"hooks": {
3+
"PreToolUse": [
4+
{
5+
"matcher": "Bash",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "jq -c '{hookSpecificOutput:{hookEventName:\"PreToolUse\",updatedInput:{command:(\"[ -s ~/.nvm/nvm.sh ] && . ~/.nvm/nvm.sh >/dev/null 2>&1 && nvm use >/dev/null 2>&1; \" + .tool_input.command)}}}'"
10+
}
11+
]
12+
}
13+
]
14+
}
15+
}

0 commit comments

Comments
 (0)