Skip to content

fix: parse inline --flag=value form in claude_args#1487

Open
HumphreySun98 wants to merge 1 commit into
anthropics:mainfrom
HumphreySun98:fix/claude-args-inline-flag-value
Open

fix: parse inline --flag=value form in claude_args#1487
HumphreySun98 wants to merge 1 commit into
anthropics:mainfrom
HumphreySun98:fix/claude-args-inline-flag-value

Conversation

@HumphreySun98

Copy link
Copy Markdown
Contributor

What

claude_args written in the inline --flag=value form — which the Claude Code CLI itself accepts — is silently mis-parsed: the flag name and value are never split, so the whole token becomes a bogus extraArgs key and the value is dropped.

Why it matters

parseClaudeArgsToExtraArgs (base-action/src/parse-sdk-options.ts) does const flag = arg.slice(2) and never splits on =. So --allowedTools=Edit,Read becomes the key "allowedTools=Edit,Read" (value null) instead of allowedTools → "Edit,Read". Downstream, parseSdkOptions keys its interception/merge/detection off exact flag names, so with the = form:

  • --allowedTools= / --disallowedTools= / --add-dir= are not merged into sdkOptions — the tools/dirs are silently dropped, and the raw allowedTools=… token leaks through to the CLI as a malformed flag (reintroducing the duplicate---allowedTools clobbering that --allowed-tools parsing broken after USE_AGENT_SDK default changed to true (PR #738) #746 hardened against).
  • --json-schema={…} is not detectedhasJsonSchema stays false, so structured output is silently skipped.

Reproduced on current main:

--allowedTools Edit,Read   → allowedTools: ["Edit","Read"]                              (space form, works)
--allowedTools=Edit,Read   → allowedTools: undefined, extraArgs: {"allowedTools=Edit,Read": null}   (BUG)
--json-schema={...}        → hasJsonSchema: false                                       (BUG)

Fix

In the arg loop, split the flag on the first = only (so a value that itself contains =, e.g. inline JSON, is preserved) and route the inline value through the same accumulating / non-accumulating handling used for the space-separated form. --flag=value and --flag value now produce identical results, and --flag=value consumes no following token (matching CLI semantics).

Tests

Added a --flag=value (inline value) form suite to base-action/test/parse-sdk-options.test.ts: the =-form allowedTools equals the space form; --json-schema=… sets hasJsonSchema; split-on-first-= preserves = inside the value; disallowedTools / add-dir work; and repeated --allowedTools=… accumulate. Each fails before the fix and passes after.

Verification

  • bun test774 pass, 0 fail (5 new).
  • bun run typecheck → clean.
  • bun run format:check → clean.

parseClaudeArgsToExtraArgs only handled the space-separated `--flag value`
form: it did `flag = arg.slice(2)` without splitting on `=`, so a
CLI-valid token like `--allowedTools=Edit,Read` became the bogus extraArg
key "allowedTools=Edit,Read" with the value dropped. This bypassed the
allowedTools/disallowedTools/add-dir merge and the --json-schema
detection that parseSdkOptions keys off exact flag names — silently
dropping tools and disabling structured output.

Split the flag on the first `=` only (preserving `=` inside values such
as inline JSON) and route the inline value through the same
accumulating/non-accumulating handling as the space form, so
`--flag=value` and `--flag value` are equivalent. Adds regression tests.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant