-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix: verify zsh exists before using it for hook execution #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: verify zsh exists before using it for hook execution #544
Conversation
|
All contributors have signed the CLA. Thank you! ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
0105a06 to
c41a4d7
Compare
|
recheck |
c41a4d7 to
09c0122
Compare
|
recheck |
The `forceZsh` option on Linux/macOS would use a hardcoded zshPath without checking if zsh actually exists on the system. This caused hook commands to fail silently with exit code 127 on systems without zsh installed. Changes: - Always verify zsh exists via findZshPath() before using it - Fall back to bash -lc if zsh not found (preserves login shell PATH) - Fall through to spawn with shell:true if neither found The bash fallback ensures user PATH from .profile/.bashrc is available, which is important for hooks that depend on custom tool locations. Tested with opencode v1.1.3 - PreToolUse hooks now execute correctly on systems without zsh.
09c0122 to
53deb91
Compare
|
recheck |
Greptile SummaryFixed silent hook execution failures on systems without zsh by verifying shell existence before use. Refactored Key changes:
Impact: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Hook as Hook Caller
participant EHC as executeHookCommand()
participant FZP as findZshPath()
participant FBP as findBashPath()
participant FSP as findShellPath()
participant Spawn as spawn()
Hook->>EHC: executeHookCommand(cmd, stdin, cwd, {forceZsh: true, zshPath})
EHC->>EHC: Expand ~ and $CLAUDE_PROJECT_DIR
alt forceZsh enabled
EHC->>FZP: findZshPath(options.zshPath)
FZP->>FSP: findShellPath(DEFAULT_ZSH_PATHS, customPath)
FSP->>FSP: Check customPath exists
alt customPath exists
FSP-->>FZP: return customPath
FZP-->>EHC: return zshPath
EHC->>EHC: finalCommand = zshPath -lc 'escapedCommand'
else customPath not found
FSP->>FSP: Check DEFAULT_ZSH_PATHS
alt zsh found in defaults
FSP-->>FZP: return path
FZP-->>EHC: return zshPath
EHC->>EHC: finalCommand = zshPath -lc 'escapedCommand'
else zsh not found
FSP-->>FZP: return null
FZP-->>EHC: return null
EHC->>FBP: findBashPath() [FALLBACK]
FBP->>FSP: findShellPath(DEFAULT_BASH_PATHS)
FSP->>FSP: Check DEFAULT_BASH_PATHS
alt bash found
FSP-->>FBP: return bashPath
FBP-->>EHC: return bashPath
EHC->>EHC: finalCommand = bashPath -lc 'escapedCommand'
else bash not found
FSP-->>FBP: return null
FBP-->>EHC: return null
EHC->>EHC: finalCommand = expandedCommand [spawn with shell:true]
end
end
end
else forceZsh disabled
EHC->>EHC: finalCommand = expandedCommand
end
EHC->>Spawn: spawn(finalCommand, {shell: true, cwd, env})
Spawn->>Spawn: Execute hook command
Spawn-->>EHC: {exitCode, stdout, stderr}
EHC-->>Hook: return CommandResult
|
Greptile found no issues!From now on, if a review finishes and we haven't found any issues, we will not post anything, but you can confirm that we reviewed your changes in the status check section. This feature can be toggled off in your Code Review Settings by deselecting "Create a status check for each PR". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No issues found across 1 file
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
|
@junhoyeo @code-yeongyu For your attention, would appreciate if you can review. |
Summary
Changes
findZshPathinto genericfindShellPathhelper functionDEFAULT_BASH_PATHSconstant andfindBashPath()functionexecuteHookCommandto cascade: zsh -lc → bash -lc → spawn shell:trueBefore:
After:
Testing
Tested on Ubuntu Linux without zsh installed:
PATH comparison (why bash -lc matters):
/bin/sh(spawn default)bash -lczsh -lcThe login shell flag (
-l) sources user profile files, ensuring custom PATH additions are available for hooks.Related Issues
No existing issue - discovered during opencode plugin testing.