fix: use ${COPILOT_PLUGIN_ROOT} in hooks.json to fix cwd crash#587
Open
kwacky1 wants to merge 1 commit into
Open
fix: use ${COPILOT_PLUGIN_ROOT} in hooks.json to fix cwd crash#587kwacky1 wants to merge 1 commit into
kwacky1 wants to merge 1 commit into
Conversation
preToolUse hooks crashed with 'preToolUse hook errored' whenever the
session cwd was anywhere other than the plugin directory. Root cause:
hooks.json used `cwd: "."` (later partially fixed to `cwd: "${PLUGIN_ROOT}"`
in the previous commit) plus relative paths in the `bash` field. The
runtime resolved `.` against session cwd, so `./hooks/guard-*.sh` was
not found.
Fix: move the absolute path into the `bash` field using
`${COPILOT_PLUGIN_ROOT}` — the token the Copilot CLI runtime injects
for the plugin install directory. Remove the `cwd` field entirely since
it is no longer needed. This matches the pattern used by si-clops and
other plugins that work correctly from any session directory.
Evidence of runtime support: `config_loader_expand_plugin_hook_config`,
`config_loader_expand_plugin_root_in_object`, and the literal
`${COPILOT_PLUGIN_ROOT}`/`${PLUGIN_ROOT}` strings are all present in
the Copilot CLI runtime.node native module (v1.0.69-1).
Test suite updated to run from a temporary cwd (not the plugin dir) to
catch future regressions. README documents the fix and adds a 'Testing
hooks locally' section.
Verified: repro confirmed (exit 127 from wrong cwd with old config);
39/39 tests pass with new config including 4 new cwd-independence tests.
Fixes gm3dmo#579
Related: PR gm3dmo#580 (fail-open behaviour)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.
Problem
preToolUse hooks crash with
preToolUse hook erroredwhenever the session cwd is anywhere other than the plugin directory. This blocks every tool call in sessions launched with--ticketsor any other flag that bundles the-power.Repro (verified 2026-07-05): Launch any Copilot CLI session from an unrelated repo (e.g. si-clops) with the plugin active. Every tool call returns
preToolUse hook errored.Root cause:
hooks.jsonused"cwd": "."(commit 538bcac) then"cwd": "${PLUGIN_ROOT}"(commit 1f7a3d7 — partial fix), plus a relative"bash": "./hooks/guard-*.sh". The runtime resolves.against session cwd, not the plugin dir. With a relativebashpath, the script is never found.Fix
Move the absolute path into the
bashfield using${COPILOT_PLUGIN_ROOT}— the token the Copilot CLI runtime injects for the plugin install directory. Remove thecwdfield entirely (no longer needed).Evidence of runtime support:
config_loader_expand_plugin_hook_config,config_loader_expand_plugin_root_in_object, and the literal${COPILOT_PLUGIN_ROOT}/${PLUGIN_ROOT}strings are all present in the Copilot CLI runtime.node native module (v1.0.69-1). The si-clops plugin uses the same pattern and works correctly.{ "type": "command", "bash": "${COPILOT_PLUGIN_ROOT}/hooks/guard-destructive-ops.sh", "timeoutSec": 10 }Changes
copilot-plugin/hooks.json— use${COPILOT_PLUGIN_ROOT}/hooks/...inbashfield; removecwdfieldcopilot-plugin/tests/test-guardrails.sh— run test suite from a temporary directory (not the plugin dir) to catch future regressions; 4 new cwd-independence test casescopilot-plugin/README.md— document the fix and add 'Testing hooks locally' sectionTesting
The test suite now cd's to a temp dir before running, so all 39 tests exercise hooks from a foreign cwd.
Related
Fixes #579 (part of the same safety hook neighbourhood)
Related: PR #580 (fail-open behaviour)