intercepting-commands

Intercept Visual Studio commands to run custom logic before, after, or instead of default handlers.

14|2|Updated Mar 24, 2026
One-click install
npx skills add https://github.com/madskristensen/vs-agent-plugins --skill intercepting-commands
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: intercepting-commands
Source: https://github.com/madskristensen/vs-agent-plugins/tree/main/skills/intercepting-commands
Command: npx skills add https://github.com/madskristensen/vs-agent-plugins --skill intercepting-commands

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Intercept existing Visual Studio commands to run custom logic before, after, or instead of the default handler. Use when you need to cancel, replace, or augment command behavior such as Save or Build, or to react to command execution across different extension approaches.

Core Features & Use Cases

  • VisualStudio.Extensibility: the out-of-process model does not support command interception; consider event-based approaches like IDocumentEventsListener for related scenarios.
  • VSIX Community Toolkit: use VS.Commands.InterceptAsync to attach before/after handlers to known commands.
  • VSSDK: implement IOleCommandTarget and register via IVsRegisterPriorityCommandTarget for in-process interception; for after-execution logic, hook into DTE.CommandEvents.AfterExecute or use post-exec patterns.

Quick Start

Initialize the interception in the extension package and test with a sample command to verify before/after behavior.

Frequently Asked Questions about intercepting-commands

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I intercept Visual Studio commands to run custom logic before or after execution?

To intercept Visual Studio commands, use the VSIX Community Toolkit's VS.Commands.InterceptAsync to attach before or after handlers to known commands, or implement VSSDK's IOleCommandTarget via IVsRegisterPriorityCommandTarget for in-process interception.

Can I cancel or replace default Visual Studio command behavior like Save or Build?

Yes, you can cancel, replace, or augment default Visual Studio command behavior like Save or Build by intercepting the command to run custom logic instead of the default handler using VSSDK or VSIX Community Toolkit approaches.

Does VisualStudio.Extensibility support command interception?

No, the VisualStudio.Extensibility out-of-process model does not support command interception. For related scenarios in this model, consider using event-based approaches like IDocumentEventsListener instead of direct command interception.

What's the best way to run logic after a Visual Studio command executes?

The best way to run logic after a Visual Studio command executes is hooking into DTE CommandEvents.AfterExecute or using post-execution patterns with VSSDK, while the VSIX Community Toolkit supports after-interception directly via InterceptAsync.

How do I register a priority command target for in-process command interception in VSSDK?

To register a priority command target for in-process command interception in VSSDK, implement the IOleCommandTarget interface and register it using IVsRegisterPriorityCommandTarget within your extension package.