Skip to content

Plugin hooks can't invoke relative bundled scripts #307478

Open

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:

  1. 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/*.ts scripts. 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
      }
    ],
  }
}
  1. Publish plugin via marketplace.
  2. Install plugin in VSCode (works differently if installed using Copilot CLI.
  3. 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 cwd property but that is also relative to current VSCode directory
  • An absolute path but it gets inconsistent with the plugin installation path

Activity

  1. added
    chat-ext-issue
    on Apr 2, 2026
  2. added and removed
    chat-ext-issue
    on Apr 2, 2026
  3. added
    bug
    on Apr 2, 2026
  4. tspascoal commented on May 14, 2026

    @tspascoal

    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:

    Image

    The hooks are correctly discovered

    Image

    But when they are executed the cwd is the workspace (from the logs) which works fine for workspace hooks, but not plugins.

    2026-05-14 12:57:34.958 [info] [#3] [UserPromptSubmit] Input: {"timestamp":"2026-05-14T11:57:34.949Z","hook_event_name":"UserPromptSubmit","session_id":"69ca5628-0d08-4d8c-b9be-f3d08242b31a","transcript_path":"/home/tspascoal/.vscode-server-insiders/data/User/workspaceStorage/69e455d2be94d33a9623ea8e95491ac6/GitHub.copilot-chat/transcripts/69ca5628-0d08-4d8c-b9be-f3d08242b31a.jsonl","prompt":"let's see if you run the hook from the installed plugin","cwd":"/home/tspascoal/tests/test-hook"}
    2026-05-14 12:57:34.960 [info] [#3] [UserPromptSubmit] Completed (NonBlockingError) in 10ms
    2026-05-14 12:57:34.960 [info] [#3] [UserPromptSubmit] Output: /bin/sh: 1: scripts/on-user-prompt.sh: not found

    Note: the plugin works correctly in CLI

  5. samcarrington commented on Aug 11, 2026

    @samcarrington

    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)

  6. Thetanner commented on Aug 14, 2026

    @Thetanner

    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 standalone hooks.json file 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:

    bash: /hooks/skill-reminder: No such file or directory
    

    i.e. the token collapses to an empty string either way, for this standalone-file hook path.

    Sam Carrington (@samcarrington)'s linked source at b85394774d09f3ff383404c08343ce116cc23ba7 seems consistent with what we're seeing: pluginParsers.ts's parseHooks for the Agent-v1 format (AGENT_PLUGIN_FORMAT, L152-161 shape) calls parseHooksJson directly and discards pluginUri, 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, unlike CLAUDE_FORMAT/OPEN_PLUGIN_FORMAT which route through interpolateHookPluginRoot.

    As a workaround we've moved our hook definitions into the root plugin.json (under extensions["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 but cwd might 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. cwd being set to the plugin directory for manifest-embedded hooks without token substitution) is actually correct — happy to provide more repro detail if useful.

  7. connor4312 commented on Aug 14, 2026

    @connor4312
    Member

    PLUGIN_ROOT is interpolated since e8abd58#diff-71ac1e3fba1549103edd377447501acfc2e58a28fb4957a7c56ee0628f4a7540R148-R152, I would double check you're on the latest version

  8. lanbaoshen commented on Sep 16, 2026

    @lanbaoshen

    I found a solution that works with both VS Code GitHub Copilot Chat, and the GitHub Copilot CLI.

    Structure

    Root/
    ├── .github/
    │   └── plugin/
    │       └── marketplace.json
    └── plugins/
        └── my-plugin/
            ├── .claude-plugin/
            │   └── plugin.json
            ├── hooks/
            │   └── hooks.json
            └── scripts/
                └── format.sh
    

    hooks.json

    {
      "hooks": {
        "sessionStart": [
          {
            "type": "command",
            "bash": "bash \"${CLAUDE_PLUGIN_ROOT}/scripts/format.sh\"",
            "cwd": "."
          }
        ]
      }
    }
    
    

    The most important thing is to add a .claude-plugin directory under the plugin directory so that CLAUDE_PLUGIN_ROOT takes effect correctly. (Even if .claude-plugin/plugin.json is 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.

  9. removed their assignment
    on Oct 14, 2026
  10. diegoPlain commented on Nov 6, 2026

    @diegoPlain

    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: 15

    I 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agent-host-mitigatedagent-pluginsbug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions