Skip to content

Fix preToolUse hook cwd to use ${PLUGIN_ROOT}#584

Open
solvaholic wants to merge 1 commit into
gm3dmo:mainfrom
solvaholic:fix-hooks-cwd-plugin-root
Open

Fix preToolUse hook cwd to use ${PLUGIN_ROOT}#584
solvaholic wants to merge 1 commit into
gm3dmo:mainfrom
solvaholic:fix-hooks-cwd-plugin-root

Conversation

@solvaholic

Copy link
Copy Markdown
Contributor

Fixes #583.

What

The three preToolUse guardrail hooks in copilot-plugin/hooks.json set "cwd": ".", which Copilot CLI resolves against the project cwd rather than the plugin root. Once the plugin is installed outside the repo checkout (e.g. under $COPILOT_HOME/cache/marketplaces/...), the relative script paths (./hooks/guard-*.sh) are not found, the hook errors, and - since CLI 1.0.57 fail-closed - the tool call is denied with Denied by preToolUse hook from "the-power" (hook errored).

Fix

Anchor each hook to "cwd": "${PLUGIN_ROOT}" so the scripts resolve regardless of the project cwd. PLUGIN_ROOT has been injected since CLI 1.0.26, and cwd expansion of plugin vars landed in 1.0.60, so this works on 1.0.60+.

Verified workaround per github/copilot-cli#2540 (comment).

Notes

The three preToolUse guardrail hooks set cwd ".", which Copilot CLI
resolves against the project cwd rather than the plugin root. Once the
plugin is installed outside the repo checkout, the relative script paths
aren't found, the hook errors, and (since CLI 1.0.57 fail-closed) the
tool call is denied.

Anchor cwd to ${PLUGIN_ROOT} so the scripts resolve regardless of the
project cwd. Works on CLI 1.0.60+.

Fixes gm3dmo#583

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

preToolUse hooks fail because hooks.json uses cwd "." instead of ${PLUGIN_ROOT}

1 participant