Repository navigation
Open
Labels
Description
- Copilot Chat Extension Version: 0.42.3
- VS Code Version: 1.114.0
- OS Version: Windows 11 23H2 22631.6199
- Feature (e.g. agent/edit/ask mode): Agent via Copilot Plugin
- Selected model (e.g. GPT 4.1, Claude 3.7 Sonnet): Any
Steps to Reproduce:
- Create a basic plugin following the official documentation.
This plugin must include:
1.1. Any custom agent, just to trigger the hooks.
1.2./hooks/*.tsscripts. Can also be any language, even powershell.
1.3./hooks.json
{
"version": 1,
"hooks": {
"HOOK NAME HERE, USE ALL FOR MORE DEBUG INFO": [
{
"type": "command",
"bash": "bun ./.github/hooks/scripts/session-start.ts",
"powershell": "bun ./.github/hooks/scripts/session-start.ts",
// OR
"windows": "powershell.exe -NoLogo -NoProfile -Command \"bun ./.github/hooks/scripts/session-start.ts\"",
"cwd": ".",
"timeoutSec": 10
}
],
}
}- Publish plugin via marketplace.
- Install plugin in VSCode (works differently if installed using Copilot CLI.
- Any hook invocation (sessionStart, preToolUse, userPromptSubmitted...) will now generate an warning | execution error.
Warning output:
. : O arquivo %USERPROFILE%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 não pode ser
carregado porque a execução de scripts foi desabilitada neste sistema. Para obter mais informações, consulte
about_Execution_Policies em https://go.microsoft.com/fwlink/?LinkID=135170.
No linha:1 caractere:3
+ . '%USERPROFILE%\Documents\WindowsPowerShell\Microsoft.Powe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ErrodeSegurança: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess
error: Module not found "./.github/hooks/scripts/pre-tool-guard.ts"
this include another unrelated issue with powershell execution policies in my company, can be circumvented by using
"windows": "powershell.exe -NoLogo -NoProfile
I have also tried:
- Utilizing the
cwdproperty but that is also relative to current VSCode directory - An absolute path but it gets inconsistent with the plugin installation path
Reacted by Mykhailo Soroka, JeffreyCA, nk-aramark, Lanbao and Diego Rodríguez
Activity
tspascoal commentedon May 14, 2026
I've create a repro repo. The repro also works as a workspace hooks. cloning the repo and watch the hooks work correctly as workspace hooks
To repro the install the plugin from source directly from the repo and see hooks execution failure as a warning in the chat window:
The hooks are correctly discovered
But when they are executed the
cwdis the workspace (from the logs) which works fine for workspace hooks, but not plugins.Note: the plugin works correctly in CLI
samcarrington commentedon Aug 11, 2026
Encountering similar issues here - hooks declared in a Copilot format plugin via the hooks.json file don't receive an expanded ${PLUGIN_ROOT} at execution time so script resolution fails. Configuring the hooks in the plugin.json manifest does allow VS Code to find the hooks. There's a different execution path in each case:
Hooks in plugin.json
https://github.com/microsoft/vscode/blob/b85394774d09f3ff383404c08343ce116cc23ba7/src/vs/platform/agentPlugins/common/pluginParsers.ts#L1296
vs
Hooks in a file
https://github.com/microsoft/vscode/blob/b85394774d09f3ff383404c08343ce116cc23ba7/src/vs/platform/agentPlugins/common/pluginParsers.ts#L152-L161
Connor Peet (@connor4312)
Declare hooks inline in plugin.json using ${PLUGIN_ROOT}
Thetanner commentedon Aug 14, 2026
Also hitting this on a published Copilot plugin (Agent Plugins 1.0 schema-bearing root
plugin.json), confirming the${PLUGIN_ROOT}non-substitution for a standalonehooks.jsonfile that Sam Carrington (@samcarrington) described above.Environment: VS Code 1.133.0,
@github/copilot(Copilot Chat) 1.0.79-6, macOS.Repro: the plugin declares hooks in
com.github.copilot/hooks/hooks.json, per the Agent-v1 adapter's discovery path. Our commands originally used${CLAUDE_PLUGIN_ROOT}(wrong token for this adapter per the docs), which we fixed to${PLUGIN_ROOT}— but the failure persisted identically after that change:i.e. the token collapses to an empty string either way, for this standalone-file hook path.
Sam Carrington (@samcarrington)'s linked source at
b85394774d09f3ff383404c08343ce116cc23ba7seems consistent with what we're seeing:pluginParsers.ts'sparseHooksfor the Agent-v1 format (AGENT_PLUGIN_FORMAT, L152-161 shape) callsparseHooksJsondirectly and discardspluginUri, with no token/env interpolation, for both the standalone-file and manifest-embedded branches — which doesn't fully explain the reported difference (embedded-in-manifest working, standalone-file not), but does confirm neither case gets${PLUGIN_ROOT}/${CLAUDE_PLUGIN_ROOT}interpolation from that code path, unlikeCLAUDE_FORMAT/OPEN_PLUGIN_FORMATwhich route throughinterpolateHookPluginRoot.As a workaround we've moved our hook definitions into the root
plugin.json(underextensions["com.github.copilot"].hooks) per Sam Carrington (@samcarrington)'s finding, plus a defensive relative-path fallback in the command strings for the case where the token still isn't substituted butcwdmight be set correctly for the embedded path.Would appreciate any insight into which of the two theories (token substitution happening for manifest-embedded hooks vs.
cwdbeing set to the plugin directory for manifest-embedded hooks without token substitution) is actually correct — happy to provide more repro detail if useful.connor4312 commentedon Aug 14, 2026
PLUGIN_ROOT is interpolated since e8abd58#diff-71ac1e3fba1549103edd377447501acfc2e58a28fb4957a7c56ee0628f4a7540R148-R152, I would double check you're on the latest version
lanbaoshen commentedon Sep 16, 2026
I found a solution that works with both VS Code GitHub Copilot Chat, and the GitHub Copilot CLI.
Structure
hooks.json
The most important thing is to add a
.claude-plugindirectory under the plugin directory so thatCLAUDE_PLUGIN_ROOTtakes effect correctly. (Even if.claude-plugin/plugin.jsonis an empty file)In the CLI, the current working directory (CWD) is by default the plugin installation directory, but in VS Code, it is the normal project root directory. Therefore, to ensure compatibility with both scenarios, you must declare it.
diegoPlain commentedon Nov 6, 2026
I am encountering the same problem with agent-scoped hooks. Truth be told, the documentation says that they only work for the Copilot SDK from the CLI.
I am going to explain now several options I have tried to find a suitable candidate to have the expected behaviour.
Agent-scoped hooks in Copilot CLI SDK and Local VSCode chat
First, the agent-scoped hooks work when you either use the Copilot SDK CLI, or the old "Local" chat harness from VSCode. For both of them, the variables ($CLAUDE_PLUGIN_ROOT, or $PLUGIN_ROOT) are present and resolve fine. They allow you to attach hooks to specific agents. This is the expected behaviour I was looking for.
But what happens with Copilot SDK from the chat in VSCode? They do NOT expose these variables, and you end up having the problem this issue stated, and blocking agents execution for an errored hook.
Next, you try to move one step above: plugin-wide hooks.
Plugin-wide hooks
If you try to go for plugin-wide hooks, you would need to identify which agent is triggering the multiple hooks you may have installed in that plugin. According to the documentation this can NOT be done reliably, as only in specific hook events the agent name is available. So this is not an option, and it is not intended to be used like this, but rather generic scripts that check for linting, formatting, security and many others.
Compatibility
In addition, and stating that none of the previous opotions work for the three environments (Copilot SDK cli + Copilot SDK VScode Chat + Local VScode chat), the next option I tried is to solve the relative path dynamically, which is definitely not elegant, and ends up having an agent with this frontmatter in Windows:
PreToolUse: - type: command command: >- if ($env:CLAUDE_PLUGIN_ROOT) { $root = $env:CLAUDE_PLUGIN_ROOT } elseif ($env:COPILOT_HOME) { $root = "$env:COPILOT_HOME/installed-plugins/your-marketplace/your-plugin" } else { throw 'Neither CLAUDE_PLUGIN_ROOT nor COPILOT_HOME is available' }; node "$root/scripts/your-script.js" timeout: 15I can not afford to have that because it is bad, hardcoded, and a problem in maintainability. I do not have either the guarantee that it will work in the future, as it turns out to be a hack rather than a good approach.
What can we do? Or what advice do you have for this scenario?