Skip to content

fix: replace shell-quote with literal arg splitter to handle # in claude_args values#982

Open
Mellowambience wants to merge 1 commit intoanthropics:mainfrom
Mellowambience:fix/shell-quote-hash-comment-bug
Open

fix: replace shell-quote with literal arg splitter to handle # in claude_args values#982
Mellowambience wants to merge 1 commit intoanthropics:mainfrom
Mellowambience:fix/shell-quote-hash-comment-bug

Conversation

@Mellowambience
Copy link

Fixes #980

Problem

shell-quote's parse() treats # as a shell comment character, returning a {comment: "..."} object instead of a string. The .filter(arg => typeof arg === "string") call drops this object, leaving the preceding flag with no value. The parser then sets that flag to null, which fails AJV schema validation and crashes the action before any API call is made.

Reproduction:

claude_args: |
  --append-system-prompt # Use best practices

append-system-prompt: null → AJV validation crash

Solution

Replace shell-quote with a purpose-built splitArgString() that:

  • Splits on whitespace
  • Respects double-quoted strings (spaces inside quotes preserved)
  • Never interprets shell metacharacters#, !, ~, $ are all treated as literal characters

claude_args is a list of CLI flags, not a shell command. There's no reason for # to be interpreted as a comment.

Changes

  • base-action/src/parse-sdk-options.ts: Add splitArgString(), replace parseShellArgs(claudeArgs).filter(...) with splitArgString(claudeArgs)

Workaround for users (until merged)

Double-quote values containing #:

claude_args: |
  --append-system-prompt "# Use best practices"

Testing

Manually verified against the reproduction case. Happy to add unit tests to the test suite if you can point me to the right test file — I see __tests__/ referenced but wasn't sure of the exact conventions here.

Fixes anthropics#980

shell-quote's parse() treats # as a shell comment character, returning a
{comment: '...'} object. The .filter(arg => typeof arg === 'string') call
drops this, leaving the preceding flag with no value. The parser then sets
that flag to null, which fails AJV schema validation and crashes the action.

Replacement: splitArgString() splits on whitespace, respects double-quoted
strings, and never interprets shell metacharacters. claude_args is a list
of CLI flags, not a shell command — # should never be treated as a comment.
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.

shell-quote treats # in claude_args values as comments, causing null values and AJV crash

1 participant