forked from bchanot/claude
The "unknown -> exit 11" path triggers when `command -v claude` fails. Root cause is NOT the interactive alias (claude->dtach_claude) not surviving the subshell — that's true but harmless: the real binary is on the inherited PATH, so `command -v` finds it in a normal `bash script.sh` (proven: toggle-external and the gate both resolve claude). The actual lever is PATH carrying the nvm node bin. A skill/hook that shells the gate out with a sanitized PATH, or a node upgrade moving the version-pinned nvm path, loses it. ensure_claude_on_path(): if `command -v claude` already resolves, do nothing; else probe known install dirs (~/.claude/local, ~/.local/bin, /usr/local/bin) and the nvm glob, prepending the bin dir — which carries BOTH claude and its node runtime (claude's shebang needs node, same dir). nvm keeps old versions after an upgrade, so pick the newest that ships claude via sort -V, not the first glob match. If nothing resolves, command -v still fails -> unknown -> exit 11 (fail-visible net stays). Verified: shellcheck clean; normal PATH -> READY exit 0 (function returns early, no regression); PATH=/usr/bin:/bin (sanitized hook) -> now resolves claude via the nvm glob and reports REAL magic state (READY exit 0), where before the fix it was exit 11 unknown. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>