Skip to content

fix: keep claude_args flags when the block opens with a comment line - #1893

Open
MuhammadMehroz786 wants to merge 1 commit into
anthropics:mainfrom
MuhammadMehroz786:fix/claude-args-leading-comment
Open

MuhammadMehroz786 wants to merge 1 commit into
anthropics:mainfrom
MuhammadMehroz786:fix/claude-args-leading-comment

Conversation

@MuhammadMehroz786

Copy link
Copy Markdown

Fixes #1892

Problem

stripShellComments (base-action/src/parse-sdk-options.ts) only drops a # comment that starts its own line. Tag mode and agent mode, however, append the user's claude_args to their own flag line with a space:

claudeArgs += ` ${userClaudeArgs}`;                  // src/modes/tag/index.ts
claudeArgs = `${claudeArgs} ${userClaudeArgs}`.trim(); // src/modes/agent/index.ts

When the block opens with a comment line, that comment no longer starts a line of the joined string, so it survives stripShellComments, and shell-quote treats everything from the # to the end of the string as one comment, newlines included. Every user flag is silently lost and the run proceeds on the action's defaults. Meanwhile parseAllowedTools tokenizes the user's block on its own, so the inline-comment server is still installed while the SDK never receives --allowedTools (the disagreement parse-tools.ts says to avoid, #1357).

Reproduced through parseSdkOptions on the current main:

space join:   model undefined, maxTurns undefined, extraArgs { "permission-mode": "acceptEdits" }
newline join: model "opus",    maxTurns 120,       extraArgs { "permission-mode": "acceptEdits", "strict-mcp-config": null }

Fix

Join the user's block on a newline instead of a space in both modes. The user's first line is then always its own line, so a leading full-line comment is stripped exactly like one anywhere else in the block. shell-quote already treats a newline as whitespace between tokens, and the joined string goes straight from prepareResult.claudeArgs to runClaude in-process, so nothing else on the path needs to change.

Tests

Added one test per mode that sets CLAUDE_ARGS to a block opening with a comment line, runs the mode's prepare*, and feeds the result through parseSdkOptions. Both fail on main (model comes back undefined) and pass with the fix.

  • bun test: 968 pass, 0 fail
  • bun run typecheck: clean
  • bun run format:check: clean

🤖 Generated with Claude Code

Tag mode and agent mode appended the user's claude_args to their own
flag line with a space. stripShellComments only drops a `#` comment that
starts its own line, so when the user's block opened with a comment the
comment no longer started a line of the joined string, shell-quote
treated everything from that `#` to the end of the string as one
comment, and every flag in the block was silently lost.

Join on a newline instead, so the user's first line is always its own
line and a leading comment is stripped like any other.

Fixes anthropics#1892

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.

A leading comment line in claude_args swallows every flag: the modes join the block onto their own flag line with a space

1 participant