Repository navigation
fix(hooks): avoid shell globs in root fallback - #90
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the hook manifest command strings to avoid zsh-failing glob expansion and to resolve plugin roots in a more host-agnostic way, then tightens the contract tests to exercise hook manifest commands under both sh and zsh.
Changes:
- Reworked
hooks/hooks.jsoncommand hooks to avoid wildcard-based fallback paths and use afind-based Codex cache lookup. - Adjusted plugin-root env var precedence when resolving the Autodev root (favoring
CODEX_PLUGIN_ROOTearlier). - Extended
tests/hook-contracts.shto execute each manifest command under bothshandzsh(when available).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| tests/hook-contracts.sh | Runs each manifest command under sh/zsh with plugin-root env vars unset and validates JSON stdout. |
| hooks/hooks.json | Removes glob-based fallback expansion and adds a zsh-safe Codex cache directory selection before invoking hooks/run-hook.cmd. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| test_hooks_manifest_commands_do_not_require_claude_plugin_root() { | ||
| local tmp payload cmd count stdout_file stderr_file stdout_text status | ||
| test_hooks_manifest_commands_do_not_require_root_env_vars() { | ||
| local tmp payload cmd count stdout_file stderr_file stdout_text status shell_name shell_bin |
Comment on lines
+55
to
+58
| for shell_name in sh zsh; do | ||
| if ! shell_bin="$(command -v "$shell_name" 2>/dev/null)"; then | ||
| continue | ||
| fi |
| return | ||
| fi | ||
| pass "hooks.json commands: run without CLAUDE_PLUGIN_ROOT and emit JSON" | ||
| pass "hooks.json commands: run without plugin-root env vars and emit JSON under sh/zsh" |
| { | ||
| "type": "command", | ||
| "command": "AUTODEV_HOOK=session-start; AUTODEV_ROOT=\"${AUTODEV_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}}}\"; for AUTODEV_ROOT_CAND in \"$AUTODEV_ROOT\" . \"$HOME/.codex/plugins/cache/autodev-marketplace/autodev\"/* \"$HOME/.claude/plugins/marketplace/autodev\"/*; do [ -n \"$AUTODEV_ROOT_CAND\" ] || continue; if [ -x \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" ]; then exec \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" \"$AUTODEV_HOOK\"; fi; done; printf '{}\\n'", | ||
| "command": "AUTODEV_HOOK=session-start; AUTODEV_ROOT=\"${AUTODEV_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}}}\"; run_autodev_hook() { AUTODEV_ROOT_CAND=\"$1\"; [ -n \"$AUTODEV_ROOT_CAND\" ] || return 1; if [ -x \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" ]; then exec \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" \"$AUTODEV_HOOK\"; fi; return 1; }; run_autodev_hook \"$AUTODEV_ROOT\"; run_autodev_hook .; AUTODEV_BASE=\"$HOME/.codex/plugins/cache/autodev-marketplace/autodev\"; if [ -d \"$AUTODEV_BASE\" ]; then AUTODEV_ROOT_CAND=$(find \"$AUTODEV_BASE\" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort | tail -1); run_autodev_hook \"$AUTODEV_ROOT_CAND\"; fi; printf '{}\\n'", |
| { | ||
| "type": "command", | ||
| "command": "AUTODEV_HOOK=session-start; AUTODEV_ROOT=\"${AUTODEV_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-}}}}\"; for AUTODEV_ROOT_CAND in \"$AUTODEV_ROOT\" . \"$HOME/.codex/plugins/cache/autodev-marketplace/autodev\"/* \"$HOME/.claude/plugins/marketplace/autodev\"/*; do [ -n \"$AUTODEV_ROOT_CAND\" ] || continue; if [ -x \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" ]; then exec \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" \"$AUTODEV_HOOK\"; fi; done; printf '{}\\n'", | ||
| "command": "AUTODEV_HOOK=session-start; AUTODEV_ROOT=\"${AUTODEV_PLUGIN_ROOT:-${CODEX_PLUGIN_ROOT:-${CURSOR_PLUGIN_ROOT:-${CLAUDE_PLUGIN_ROOT:-}}}}\"; run_autodev_hook() { AUTODEV_ROOT_CAND=\"$1\"; [ -n \"$AUTODEV_ROOT_CAND\" ] || return 1; if [ -x \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" ]; then exec \"$AUTODEV_ROOT_CAND/hooks/run-hook.cmd\" \"$AUTODEV_HOOK\"; fi; return 1; }; run_autodev_hook \"$AUTODEV_ROOT\"; run_autodev_hook .; AUTODEV_BASE=\"$HOME/.codex/plugins/cache/autodev-marketplace/autodev\"; if [ -d \"$AUTODEV_BASE\" ]; then AUTODEV_ROOT_CAND=$(find \"$AUTODEV_BASE\" -mindepth 1 -maxdepth 1 -type d 2>/dev/null | sort | tail -1); run_autodev_hook \"$AUTODEV_ROOT_CAND\"; fi; printf '{}\\n'", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause
Codex executes hook commands through the user shell. On zsh, unmatched fallback globs such as ~/.claude/plugins/marketplace/autodev/* fail during shell expansion with exit code 1 before the hook wrapper runs.
Verification