microsoft / microsoft/vscode

PowerShell hook crashes with empty $PLUGIN_ROOT when a non-primary workspace folder's .github/hooks/*.json is invoked in a multi-root workspace

Open
#332,327 0 comments 0 reactions 1 assignee Claimed by @pwang347 View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

### Summary
In a multi-root workspace (Editor Window), when an Agent Host session is anchored to folder B's working directory but folder A also defines a repository-level hook (`A/.github/hooks/*.json`), VS Code still tries to invoke A's hook — consistent with the aggregation-across-all-folders behavior described in #328021 / verified in #331413. On Windows, invoking that hook fails outright rather than silently no-op'ing, because the generated PowerShell wrapper resolves the hook script path via `Join-Path "${PLUGIN_ROOT}" 'hooks/...'`, and `PLUGIN_ROOT` is empty for a hook config that doesn't belong to the session's own working directory:

```
Join-Path : Cannot bind argument to parameter 'Path' because it is an empty string.
At line:1 char:62
+ ... issionDecision":"allow"}'; $hook = Join-Path "${PLUGIN_ROOT}" 'hooks/ ...
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Join-Path], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Microsoft.PowerShell.Commands.JoinPathCommand
```

### Steps to reproduce
1. Open a multi-root workspace containing folder A (with a `A/.github/hooks/*.json` repository-level `postToolUse` command hook using the `powershell` field) and folder B (no hooks of its own).
2. Start/resume an Agent Host session anchored to folder B's working directory.
3. Trigger a tool call that would match A's hook (e.g. an `edit`/`create` tool use).
4. Observe the PowerShell `Join-Path` exception surfaced in the session instead of the hook being skipped or resolved correctly.

### Expected
Either: the session should not receive A's hook at all (per the scoping fix in #328021), or if cross-folder hooks are intentionally still invoked, `PLUGIN_ROOT` should resolve to A's folder path rather than being empty, so the hook runs (or fails) the same way it would from A's own session.

### Environment
- Windows, VS Code multi-root workspace (`.code-workspace` with 3 folders)
- Repository-level hook defined via `.github/hooks/*.json` with a `powershell` command entry
- Related: #328021, #331413

### Impact
Every agent task run against folder B/C fails/logs spurious errors due to a hook that was only ever meant to apply to folder A.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.