Skip to content

fix: preserve repeated plugin-dir flags in claude args - #1838

Open
v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/plugin-dir-accumulate
Open

v0ropaev wants to merge 1 commit into
anthropics:mainfrom
v0ropaev:fix/plugin-dir-accumulate

Conversation

@v0ropaev

Copy link
Copy Markdown

Fixes #1728

Summary

  • Preserve repeated --plugin-dir flags parsed from claude_args.
  • Map the values onto the SDK's typed plugins option ({ type: "local", path }), which emits one --plugin-dir per entry. Same approach as the --add-dir fix in fix: preserve repeated add-dir flags in claude args #1256.
  • Remove plugin-dir from extraArgs, except for a bare --plugin-dir (e.g. from an unset variable): that one still reaches the CLI, so it keeps failing with option '--plugin-dir <path>' argument missing instead of the plugin being skipped silently.

Root Cause

plugin-dir wasn't in ACCUMULATING_FLAGS, so each occurrence overwrote the previous one and only the last plugin was loaded, with no warning, although the CLI documents the flag as repeatable.

Adding it to the set alone isn't enough: accumulated values are joined with \x00, and the SDK turns each extraArgs entry into exactly one argv element, so the spawn throws

ERR_INVALID_ARG_VALUE: The argument 'args[8]' must be a string without null bytes. Received './plugin-a\x00./plugin-b'

(SDK 0.3.274, same on node 24 and bun 1.3). #1736 and #1816 only add the flag to the set, and their tests assert the joined value left in extraArgs, so bun test passes but the actual run would fail on the first job with two plugin dirs. Thanks to @farmer-data, whose review on #1736 spotted the ERR_INVALID_ARG_VALUE and pointed at the plugins option.

Validation

  • bun test test/parse-sdk-options.test.ts: 46 pass (5 new: repeated flags across lines and with other flags in between, a single flag, a bare flag, other flags preserved, and a parser-wide check that no extraArgs value contains \x00, which fails against the accumulate-only change)
  • bun test: 971 pass
  • bun run typecheck, bun run format:check: clean
  • End to end through the SDK with the bundled Claude Code 2.1.274 binary (offline, up to the init message): --plugin-dir A --plugin-dir B lists both plugins and their commands; on main only B is loaded.

Notes

  • --plugin-url has no SDK option, so a repeated space-separated --plugin-url still keeps only the last value; not changed here. The inline --plugin-url=A --plugin-url=B form already passes through as is.
  • --plugin-dir-no-mcp (hidden, the SDK emits it for skipMcpDiscovery) is left as is. Happy to map it to skipMcpDiscovery in this PR if you'd like.

plugin-dir was not in ACCUMULATING_FLAGS, so each repeated --plugin-dir
in claude_args overwrote the previous one and only the last plugin
reached the CLI, with no warning. The CLI documents the flag as
repeatable.

Accumulating the values is not enough on its own: extraArgs holds one
value per flag and the SDK passes that value through as a single argv
entry, so a NUL-joined value makes the spawn throw
ERR_INVALID_ARG_VALUE. Map the values to the SDK's plugins option
instead, which emits one --plugin-dir per entry, mirroring the existing
add-dir handling. A bare --plugin-dir is still passed through, so the
CLI keeps rejecting it instead of the plugin being skipped silently.
@v0ropaev

v0ropaev commented Oct 6, 2026

Copy link
Copy Markdown
Author

No workflow has run on this one, or on #1868 and #1869, because fork PRs here wait for an approval. Happy to leave them sitting, just noting that there is no CI signal on any of the three yet.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

claude_args: repeated --plugin-dir collapses to last-one-wins (not in ACCUMULATING_FLAGS), silently dropping plugins

1 participant