Skip to content

agentHost: list custom agent hooks and skip them in untrusted folders - #349332

Merged
Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
dev/vritant24/hooks-custom-agents
Nov 20, 2026
Merged

Vritant Bhardwaj (vritant24) merged 2 commits into
mainfrom
dev/vritant24/hooks-custom-agents

Conversation

@vritant24

@vritant24 Vritant Bhardwaj (vritant24) commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

What this changes

A custom agent file can declare hooks:, and the Copilot runtime runs them while that agent is selected. Chat Customizations did not list these hooks, and VS Code passed them to the runtime even when the session's folder was untrusted.

  • Chat Customizations lists each agent's hooks, marked as running while that agent is active. They are listed only for the Copilot runtime, since other runtimes such as Codex ignore them.
  • Agent hooks are sent to the runtime only when every folder of the session is trusted. The folder an agent came from is not always known (agents copied from custom agent locations, or taken from another chat), so this applies to every custom agent, including user agents. The agents themselves still load.
  • When any session folder is untrusted, agent hooks are listed with a Won't run badge and "Won't run until you trust this folder." A session restarts when the trust of any of its folders changes.
  • Delete on an agent hook row explains that the hook is removed by editing the agent file, instead of deleting the whole file.

How to test

  1. In a git repository, add .github/agents/reviewer.agent.md with a hooks: section that declares a sessionStart hook appending a line to a file.
  2. Trusted folder: Chat Customizations > Hooks lists the hook as running while the agent is active. Select the agent in a Copilot session: the hook runs.
  3. Restricted Mode: the hook is listed with a Won't run badge. Select the agent: the agent works and the hook does not run.
  4. Multi-root workspace with one untrusted folder: agent hooks from every folder are listed with a Won't run badge and don't run.
  5. Delete an agent hook row: a message explains how to remove it, and the agent file is kept.
  6. In a Codex session, no agent hook rows are listed.

Validation

  • ./scripts/test.sh --reporter dot --run src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts --run src/vs/platform/agentHost/test/node/sessionCustomizationDiscovery.test.ts --run src/vs/platform/agentHost/test/node/copilotAgent.test.ts --run src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentCustomizationItemProvider.test.ts --run src/vs/workbench/contrib/chat/test/browser/aiCustomization/customizationMigration.test.ts: passed (3,275 passing)
  • ./scripts/test.sh --reporter dot --timeout 180000 --run src/vs/platform/agentHost/test/node/providerIntegration/copilotCustomizations.integrationTest.ts --run src/vs/platform/agentHost/test/node/copilotSdkCustomizationDiscovery.integrationTest.ts: passed (13 passing)
  • ./scripts/test-agent-host-e2e.sh --grep "customization discovery|custom agent|hook": passed (20 passing)
  • pnpm run typecheck-client and oxlint: passed
  • Checked the listing manually in Code OSS on macOS before the review changes. Whether the hook runs when the agent is selected was checked with the SDK directly, not in a signed-in VS Code session.

Known gaps

  • The hooks of agents from plugins or custom agent locations get the Won't run badge only when the host also lists another untrusted hook or agent file.
  • Delete is still offered on agent hook rows; it now explains instead of deleting.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Untrusted agent hooks can bypass trust checks, and deleting an agent-hook row can remove the entire agent file.

5 open issues
What changed in this PR

Adds workspace-trust enforcement and Chat Customizations visibility for hooks declared in Copilot custom agent files.

Changes:

  • Filters agent hooks during session launch while keeping the agent available.
  • Lists agent-declared hooks and marks hooks blocked by folder trust.
  • Adds tests for launch filtering, blocked-hook discovery, and hook listing.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentCustomizationItemProvider.test.ts Tests agent-hook listing through a remote URI mapper.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentHost/​agentCustomizationItemProvider.ts Creates hook rows from agent frontmatter and suppresses active rows for blocked agents.
src/​vs/​platform/​agentHost/​test/​node/​sessionCustomizationDiscovery.test.ts Tests discovery of untrusted agent files containing hooks.
src/​vs/​platform/​agentHost/​test/​node/​copilotSessionLauncher.test.ts Tests trust-based filtering of workspace-agent hooks.
src/​vs/​platform/​agentHost/​node/​copilot/​sessionCustomizationDiscovery.ts Publishes blocked-hook entries for untrusted agent files.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotSessionLauncher.ts Applies hook filtering when preparing runtime agent definitions.
src/​vs/​platform/​agentHost/​node/​copilot/​copilotPluginConverters.ts Adds hook detection and optional hook inclusion during conversion.

Review effort: Max

@vritant24
Vritant Bhardwaj (vritant24) marked this pull request as ready for review November 19, 2026 23:38
Base automatically changed from dev/vritant24/hooks-trust to main November 20, 2026 00:01
The Copilot runtime runs the `hooks:` of a custom agent file while that agent
is selected. Chat Customizations did not list these hooks, and VS Code passed
them to the runtime for agent files in untrusted folders.

Chat Customizations now lists each agent's hooks as running while that agent
is active, and hooks of agent files in an untrusted workspace folder are not
passed to the runtime and are shown as "Won't run until you trust this
folder".

Co-authored-by: Copilot <[email protected]>
…trusted

The folder an agent came from is not always known: agents copied from other
locations, or taken from another chat, live outside the session's folders, so
checking the agent's own path let their hooks run in an untrusted folder.
Custom agent hooks are now sent only when every session folder is trusted, and
a session restarts when the trust of any of its folders changes.

Chat Customizations lists agents that declare hooks as not running whenever a
session folder is untrusted, and badges every agent hook row in that case. It
lists agent hooks only for the Copilot runtime, since other runtimes ignore
them, and deleting an agent hook row explains that it is edited in the agent
file instead of deleting the file.

Co-authored-by: Copilot <[email protected]>
@vritant24
Vritant Bhardwaj (vritant24) force-pushed the dev/vritant24/hooks-custom-agents branch from e58727c to a9e0f8c Compare November 20, 2026 00:07
@vritant24
Vritant Bhardwaj (vritant24) added this pull request to the merge queue Nov 20, 2026
Merged via the queue into main with commit 1dedb18 Nov 20, 2026
38 checks passed
@vritant24
Vritant Bhardwaj (vritant24) deleted the dev/vritant24/hooks-custom-agents branch November 20, 2026 00:31
@vritant24 Vritant Bhardwaj (vritant24) mentioned this pull request Nov 23, 2026
3 tasks done
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.

3 participants