MCPcopy Create free account
hub / github.com/WJX20/claude-code / setPluginEnabledOp

Function setPluginEnabledOp

src/services/plugins/pluginOperations.ts:574–748  ·  view source on GitHub ↗
(
  plugin: string,
  enabled: boolean,
  scope?: InstallableScope,
)

Source from the content-addressed store, hash-verified

572 * @returns Result indicating success/failure
573 */
574export async function setPluginEnabledOp(
575 plugin: string,
576 enabled: boolean,
577 scope?: InstallableScope,
578): Promise<PluginOperationResult> {
579 const operation = enabled ? 'enable' : 'disable'
580
581 // Built-in plugins: always use user-scope settings, bypass the normal
582 // scope-resolution + installed_plugins lookup (they're not installed).
583 if (isBuiltinPluginId(plugin)) {
584 const { error } = updateSettingsForSource('userSettings', {
585 enabledPlugins: {
586 ...getSettingsForSource('userSettings')?.enabledPlugins,
587 [plugin]: enabled,
588 },
589 })
590 if (error) {
591 return {
592 success: false,
593 message: `Failed to ${operation} built-in plugin: ${error.message}`,
594 }
595 }
596 clearAllCaches()
597 const { name: pluginName } = parsePluginIdentifier(plugin)
598 return {
599 success: true,
600 message: `Successfully ${operation}d built-in plugin: ${pluginName}`,
601 pluginId: plugin,
602 pluginName,
603 scope: 'user',
604 }
605 }
606
607 if (scope) {
608 assertInstallableScope(scope)
609 }
610
611 // ── Resolve pluginId and scope from settings ──
612 // Search across editable scopes for any mention (enabled or disabled) of
613 // this plugin. Does NOT pre-gate on installed_plugins.json.
614 let pluginId: string
615 let resolvedScope: InstallableScope
616
617 const found = findPluginInSettings(plugin)
618
619 if (scope) {
620 // Explicit scope: use it. Resolve pluginId from settings if possible,
621 // otherwise require a full plugin@marketplace identifier.
622 resolvedScope = scope
623 if (found) {
624 pluginId = found.pluginId
625 } else if (plugin.includes('@')) {
626 pluginId = plugin
627 } else {
628 return {
629 success: false,
630 message: `Plugin "${plugin}" not found in settings. Use plugin@marketplace format.`,
631 }

Callers 3

enablePluginOpFunction · 0.85
disablePluginOpFunction · 0.85
disableAllPluginsOpFunction · 0.85

Calls 14

isBuiltinPluginIdFunction · 0.85
updateSettingsForSourceFunction · 0.85
getSettingsForSourceFunction · 0.85
clearAllCachesFunction · 0.85
parsePluginIdentifierFunction · 0.85
assertInstallableScopeFunction · 0.85
findPluginInSettingsFunction · 0.85
isPluginBlockedByPolicyFunction · 0.85
scopeToSettingSourceFunction · 0.85
getPluginEditableScopesFunction · 0.85
loadAllPluginsFunction · 0.85
findReverseDependentsFunction · 0.85

Tested by

no test coverage detected