---------- listing logic ---------------------------------------------------- listClaudePlugins reads Claude Code's metadata files and prints installed plugins and marketplaces — matching the information `claude plugin list` and `claude plugin marketplace list` provide.
(out io.Writer, pluginsDir string)
| 54 | // plugins and marketplaces — matching the information `claude plugin list` and |
| 55 | // `claude plugin marketplace list` provide. |
| 56 | func listClaudePlugins(out io.Writer, pluginsDir string) (pluginCount, marketplaceCount int) { |
| 57 | // 1. Read installed_plugins.json |
| 58 | installedPath := filepath.Join(pluginsDir, "installed_plugins.json") |
| 59 | installed := readClaudeInstalledPlugins(installedPath) |
| 60 | |
| 61 | // 2. Read known_marketplaces.json |
| 62 | marketplacesPath := filepath.Join(pluginsDir, "known_marketplaces.json") |
| 63 | marketplaces := readClaudeKnownMarketplaces(marketplacesPath) |
| 64 | |
| 65 | // 3. Read settings.json for enabled status |
| 66 | homeDir := filepath.Dir(pluginsDir) // ~/.claude |
| 67 | settingsPath := filepath.Join(homeDir, "settings.json") |
| 68 | enabledPlugins := readClaudeEnabledPlugins(settingsPath) |
| 69 | |
| 70 | // 4. Print installed plugins |
| 71 | if len(installed.Plugins) > 0 { |
| 72 | // Sort plugin keys for deterministic output. |
| 73 | keys := make([]string, 0, len(installed.Plugins)) |
| 74 | for k := range installed.Plugins { |
| 75 | keys = append(keys, k) |
| 76 | } |
| 77 | sort.Strings(keys) |
| 78 | |
| 79 | fmt.Fprintf(out, "claude — Installed plugins (%d):\n", len(keys)) |
| 80 | for _, key := range keys { |
| 81 | installs := installed.Plugins[key] |
| 82 | if len(installs) == 0 { |
| 83 | continue |
| 84 | } |
| 85 | inst := installs[0] // take the first installation |
| 86 | |
| 87 | version := inst.Version |
| 88 | if version == "" { |
| 89 | version = "unknown" |
| 90 | } |
| 91 | scope := inst.Scope |
| 92 | if scope == "" { |
| 93 | scope = "user" |
| 94 | } |
| 95 | |
| 96 | // Determine enabled status from settings.json |
| 97 | status := "enabled" |
| 98 | // enabledPlugins is keyed by plugin@marketplace and the value is |
| 99 | // true (enabled) or false (disabled). |
| 100 | if enabled, ok := enabledPlugins[key]; ok && !enabled { |
| 101 | status = "disabled" |
| 102 | } |
| 103 | |
| 104 | fmt.Fprintf(out, " %-45s %-18s %-8s %s\n", key, version, scope, status) |
| 105 | } |
| 106 | pluginCount = len(keys) |
| 107 | } else { |
| 108 | fmt.Fprintln(out, "claude — No plugins installed") |
| 109 | } |
| 110 | |
| 111 | // 5. Print marketplaces |
| 112 | if len(marketplaces) > 0 { |
| 113 | fmt.Fprintln(out) |
no test coverage detected