/vs-extensibility-skills:creating-dynamic-commandsfrom vs-extensibility-skills
Creates dynamic menu items that change at runtime based on data in Visual Studio extensions. Covers VisualStudio.Extensibility, VSIX Community Toolkit, and legacy VSSDK approaches.
Ships in vs-extensibility-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Dynamic commands create menu items on the fly based on runtime data. Unlike regular commands that have a fixed set of buttons, dynamic commands generate one menu item per data item — perfect for "recent files" lists, open-document pickers, or any contextual menu that changes over time.
Dynamic commands solve a fundamental UX problem: static menus can't represent variable-length data. Without dynamic commands, you'd have to pre-allocate hidden menu items and show/hide them — which is fragile and limits list size.
When to use this vs. alternatives:
The toolkit provides BaseDynamicCommand<TCommand, TItem> to make dynamic menus easy.
NuGet package: Community.VisualStudio.Toolkit
Key namespace: Community.VisualStudio.Toolkit
A dynamic command is defined like a regular button, but with the DynamicItemStart flag. This tells Visual Studio that the button is the anchor for a list of dynamic items.
<Buttons>
<Button guid="MyPackage" id="DynamicCommand" priority="0x0100" type="Button">
<Parent guid="MyPackage" id="MyMenuGroup" />
<CommandFlag>DynamicItemStart</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Dynamic Item</ButtonText>
</Strings>
</Button>
</Buttons>
Important: The command IDs that follow your button ID must be left unassigned. Visual Studio uses those sequential IDs for each dynamic item.
Create a class that inherits from BaseDynamicCommand<TCommand, TItem> where TItem is the data type each menu item represents.
Override three methods:
GetItems() — return the list of items to create menu entries for.BeforeQueryStatus(...) — set the text and visibility of each menu item.ExecuteAsync(...) — handle the click on a dynamic item.[Command("489ba882-f600-4c8b-89db-eb366a4ee3b3", 0x0100)]
public class RecentItemsCommand : BaseDynamicCommand<RecentItemsCommand, string>
{
protected override IReadOnlyList<string> GetItems()
{
// Return whatever data should generate menu items.
return new[] { "Alpha", "Beta", "Gamma" };
}
protected override void BeforeQueryStatus(OleMenuCommand menuItem, EventArgs e, string item)
{
// Set the text that appears in the menu for this item.
menuItem.Text = item;
}
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, string item)
{
await VS.MessageBox.ShowAsync($"You clicked: {item}");
}
}
Register the command the same way as any other command:
protected override async Task InitializeAsync(
CancellationToken cancellationToken,
IProgress<ServiceProgressData> progress)
{
await this.RegisterCommandsAsync();
}
When the menu opens, Visual Studio calls GetItems() to fetch the current list. It creates one menu entry per item and calls BeforeQueryStatus for each, so you can set the text, icon, enabled state, or visibility. When the user clicks an entry, ExecuteAsync (or Execute) is invoked with the corresponding item.
The generic TItem parameter can be any type:
public class RecentFile
{
public string FilePath { get; set; }
public DateTime LastOpened { get; set; }
}
[Command("489ba882-f600-4c8b-89db-eb366a4ee3b3", 0x0200)]
public class RecentFilesCommand : BaseDynamicCommand<RecentFilesCommand, RecentFile>
{
protected override IReadOnlyList<RecentFile> GetItems()
{
return MySettings.GetRecentFiles();
}
protected override void BeforeQueryStatus(OleMenuCommand menuItem, EventArgs e, RecentFile item)
{
menuItem.Text = Path.GetFileName(item.FilePath);
}
protected override async Task ExecuteAsync(OleMenuCmdEventArgs e, RecentFile item)
{
await VS.Documents.OpenAsync(item.FilePath);
}
}
In raw VSSDK, dynamic commands are built using OleMenuCommand with the MatchedCommandId pattern.
NuGet package: Microsoft.VisualStudio.SDK
Key namespaces: Microsoft.VisualStudio.Shell, System.ComponentModel.Design
Same as the toolkit approach — use DynamicItemStart:
<Buttons>
<Button guid="guidMyCmdSet" id="cmdidDynamicStart" priority="0x0100" type="Button">
<Parent guid="guidMyCmdSet" id="MyMenuGroup" />
<CommandFlag>DynamicItemStart</CommandFlag>
<CommandFlag>DynamicVisibility</CommandFlag>
<Strings>
<ButtonText>Dynamic Item</ButtonText>
</Strings>
</Button>
</Buttons>
protected override async Task InitializeAsync(
CancellationToken cancellationToken,
IProgress<ServiceProgressData> progress)
{
await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);
OleMenuCommandService commandService =
await GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService;
var dynamicItemRootId = new CommandID(
new Guid("your-command-set-guid"), 0x0100);
var dynamicCommand = new OleMenuCommand(
OnDynamicItemInvoked,
changeHandler: null,
beforeQueryStatus: OnBeforeQueryStatusDynamic,
dynamicItemRootId);
// This predicate tells VS which command IDs belong to this dynamic set
dynamicCommand.MatchedCommandId = 0;
commandService.AddCommand(dynamicCommand);
}
private readonly string[] _items = { "Alpha", "Beta", "Gamma" };
private void OnBeforeQueryStatusDynamic(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
var cmd = (OleMenuCommand)sender;
// The MatchedCommandId is set by VS to indicate which dynamic item is being queried
int index = cmd.MatchedCommandId - 0x0100; // Subtract your base command ID
cmd.Enabled = true;
cmd.Visible = index < _items.Length;
if (index < _items.Length)
{
cmd.Text = _items[index];
cmd.MatchedCommandId = 0; // Reset for next query
}
}
private void OnDynamicItemInvoked(object sender, EventArgs e)
{
ThreadHelper.ThrowIfNotOnUIThread();
var cmd = (OleMenuCommand)sender;
int index = cmd.MatchedCommandId - 0x0100;
if (index >= 0 && index < _items.Length)
{
string clickedItem = _items[index];
VsShellUtilities.ShowMessageBox(
this, $"You clicked: {clickedItem}", "Dynamic Command",
OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK,
OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
}
}
Note: The raw VSSDK approach is error-prone because you must manually manage command ID arithmetic and
MatchedCommandIdstate. The toolkit'sBaseDynamicCommand<TCommand, TItem>is strongly recommended over this pattern.
The VisualStudio.Extensibility SDK does not currently have a direct equivalent of DynamicItemStart / BaseDynamicCommand for runtime-generated menu items.
However, you can achieve similar behavior by:
Toggling command visibility — show/hide a predefined set of commands based on context using VisibleWhen constraints and runtime state.
Using a tool window with a list — present dynamic items in a tool window with a list/tree UI instead of a menu. This is often a better UX for large or variable-length lists.
Using a mixed in-proc/out-of-proc extension — keep your main logic out-of-process but use an in-process companion for the dynamic command registration.
.vsct button has the DynamicItemStart command flag. Without it, VS treats the command as a single static button.GetItems() override (Toolkit) or MatchedCommandId loop (VSSDK) isn't returning all items. Debug by checking the data source and ensuring the ID range is large enough.MatchedCommandId offset calculation is off. The selected item index is commandId - baseCommandId. Verify your base ID matches the IDSymbol value in .vsct.BeforeQueryStatus calls. Cache the list at a stable point and only refresh on explicit triggers.Do NOT pre-allocate fixed hidden commands as a substitute — use
DynamicItemStartandBaseDynamicCommand(Toolkit) orOleMenuCommandwithMatchedCommandId(VSSDK).
Do NOT use dynamic commands for very large lists (50+ items) — use a tool window with a searchable list instead.
Do NOT use VisualStudio.Extensibility for dynamic menu items — it doesn't support
DynamicItemStart. Use in-process Toolkit/VSSDK, or present items in a tool window.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Generated from the plugin's indexed repository (madskristensen/vs-agent-plugins) — no native marketplace selected
npx claudepluginhub p/madskristensen-vs-extensibility-skills41 skills in this plugin
/adding-codelens-indicatorsAdd custom CodeLens indicators that display inline information above code elements in the Visual Studio editor. Use when the user asks how to add a CodeLens indicator, show inline data above methods or classes, create a custom CodeLens provider, implement IAsyncCodeLensDataPointProvider, display git history or test status in CodeLens, or add a details popup to CodeLens entries. Covers VSSDK / VSIX Community Toolkit (in-process + out-of-process CodeLens service). VisualStudio.Extensibility (out-of-process) does not have a dedicated CodeLens API./adding-commandsAdd commands (menu items, toolbar buttons) to Visual Studio extensions. Use when the user asks how to create a command, add a menu item, add a toolbar button, register a command handler, wire up a .vsct file, use KnownMonikers icons on buttons, or place commands in menus/toolbars in a Visual Studio IDE extension. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-context-menusAdd native-looking context menus to custom WPF UI in Visual Studio extensions (tool windows, custom tree views, list views). Use when the user wants to show a right-click context menu from their own UI that looks native to VS. Covers defining VSCT context menus (type="Context"), grouping commands with separators, and programmatically showing them via IVsUIShell.ShowContextMenu. Do NOT use regular WPF ContextMenu — it won't match VS theming or support command routing. Covers VSSDK and VSIX Community Toolkit (in-process). VisualStudio.Extensibility (out-of-process) does not support VSCT-based context menus on custom UI./adding-editor-adornmentsAdd visual adornments (decorations, overlays, highlights) to the Visual Studio text editor. Use when the user asks how to draw on the editor, add inline decorations, highlight text visually, add background colors to lines, show icons in the editor, create viewport-relative overlays, or render custom WPF visuals on top of editor text. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-editor-classifiersAdd custom syntax highlighting and text classification to the Visual Studio editor. Use when the user asks how to colorize text, add syntax highlighting, create a classifier, highlight keywords, change text colors in the editor, create a custom language colorizer, or implement classification types. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches./adding-editor-marginsAdd custom margins to the Visual Studio text editor (gutter icons, side panels, bottom bars). Use when the user asks how to add a gutter, editor margin, side panel, bottom bar, line number gutter, custom glyph margin, or editor chrome. Covers VisualStudio.Extensibility (out-of-process), VSIX Community Toolkit (in-process), and legacy VSSDK (in-process) approaches.Other plugins' skills for the same job