claude-code - 💡(How to fix) Fix /reload-plugins throws TypeError: P?.reduce is not a function despite successful reload [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#47777Fetched 2026-04-15 06:42:39
View on GitHub
Comments
1
Participants
2
Timeline
5
Reactions
0
Timeline (top)
labeled ×4commented ×1

Error Message

TypeError: P?.reduce is not a function. (In 'P?.reduce((X,R)=>X+R.hooks.length,0)', 'P?.reduce' is undefined)

Root Cause

Likely root cause

Code Example

TypeError: P?.reduce is not a function. (In 'P?.reduce((X,R)=>X+R.hooks.length,0)', 'P?.reduce' is undefined)
RAW_BUFFERClick to expand / collapse

Version: Claude Code 2.1.107 (native binary, macOS Darwin 25.4.0)

What happens

Running /reload-plugins reports:

TypeError: P?.reduce is not a function. (In 'P?.reduce((X,R)=>X+R.hooks.length,0)', 'P?.reduce' is undefined)

What actually works

The reload itself succeeds. After the error is shown, new plugins appear in the available skills list and their MCP tools become callable (verified by observing nimble skills and nimble-mcp-server tools appear after installing a new plugin and running /reload-plugins). The error is thrown by what appears to be the success-summary code that aggregates total hook counts across loaded plugins.

Likely root cause

The optional chaining P?.reduce only guards against null/undefined. If P is an object (not an array), P?.reduce evaluates to undefined and calling it throws. The plugins field in ~/.claude/plugins/installed_plugins.json is serialised as an object keyed by plugin@marketplace (not an array), so any code path that consumes it expecting an array will fail at this line.

Reproduction

  1. Have ≥1 plugin installed so installed_plugins.json has a non-empty plugins object
  2. Run /reload-plugins

Environment

  • Claude Code 2.1.107 (native binary via ~/.local/bin/claude)
  • macOS Darwin 25.4.0
  • 77 installed plugins across 10 marketplaces
  • Also reproduced after cleaning up stale plugin install paths (not cause-related)

Suggested fix

Either coerce the plugins collection to an array before reducing (Object.values(P)?.reduce(...)) or guard with Array.isArray(P) ? P.reduce(...) : 0.

extent analysis

TL;DR

The error can be fixed by coercing the plugins collection to an array before reducing or by adding a check to ensure P is an array before calling reduce.

Guidance

  • The issue arises from the plugins field being an object instead of an array, causing P?.reduce to be undefined and throw an error.
  • To verify the fix, run /reload-plugins after applying the suggested changes and check if the error is resolved.
  • The suggested fix involves either using Object.values(P)?.reduce(...) to coerce the object to an array or adding a check with Array.isArray(P) ? P.reduce(...) : 0 to handle cases where P is not an array.
  • Ensure that the installed_plugins.json file is correctly formatted and that the code consuming it expects an object, not an array.

Example

// Coerce plugins collection to an array before reducing
const totalHooks = Object.values(P)?.reduce((X, R) => X + R.hooks.length, 0);

// Alternatively, guard with Array.isArray check
const totalHooks = Array.isArray(P) ? P.reduce((X, R) => X + R.hooks.length, 0) : 0;

Notes

The provided fix assumes that the plugins field in installed_plugins.json is correctly formatted as an object keyed by plugin@marketplace. If the format is incorrect, additional changes may be necessary.

Recommendation

Apply the workaround by coercing the plugins collection to an array or adding an Array.isArray check, as this directly addresses the root cause of the error and allows the code to handle the object format of the plugins field.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING