Skip to content

fix(ralph-wiggum): stop parsing /ralph-loop prompt text as shell code - #80495

Open
Serhii-Leniv wants to merge 1 commit into
anthropics:mainfrom
Serhii-Leniv:fix-ralph-loop-shell-parsing
Open

fix(ralph-wiggum): stop parsing /ralph-loop prompt text as shell code#80495
Serhii-Leniv wants to merge 1 commit into
anthropics:mainfrom
Serhii-Leniv:fix-ralph-loop-shell-parsing

Conversation

@Serhii-Leniv

Copy link
Copy Markdown

Fixes #16037

Problem

/ralph-loop substitutes $ARGUMENTS directly into the auto-executed shell line in ralph-loop.md, so the user's prompt text is parsed as shell code. The loop then fails before it starts for everyday prompts. Reproduced on Claude Code v2.1.218 (Windows, git-bash shell):

Prompt after /ralph-loop Result
Fix the bug in Bob's code bash: eval: unexpected EOF while looking for matching '
Fix auth; then add tests Shell command permission check failed: Parse error
Fix the $(hostname) placeholder bug permission check failed: Contains command_substitution
multi-line prompt This Bash command contains multiple operations (the original report)

The permission check is the only thing standing between $(...) in a prompt and actual execution — a commenter on #16037 works around the failure with --dangerously-skip-permissions, at which point prompt text can run as code.

Fix

  • commands/ralph-loop.md: feed $ARGUMENTS to the setup script via a quoted heredoc on stdin, so prompt text is never interpreted by the shell. Verified on v2.1.218 that the heredoc form passes the allowed-tools permission check that the inline form fails.
  • scripts/setup-ralph-loop.sh: read the raw argument text from stdin and parse --max-iterations / --completion-promise textually (quoted promises still work; quotes are now literal characters). Direct invocation with positional argv still works. Surrounding quotes on the prompt are stripped, matching the README's /ralph-loop "Build X" --completion-promise "DONE" usage.
  • The state file format is unchanged, so hooks/stop-hook.sh needs no changes. Bumped plugin version 1.0.0 → 1.0.1.

Testing

  • 33-case script test suite (all passing): options in any position, quoted/bare promises, multi-line prompts, apostrophes/semicolons/$(...) kept literal, CRLF input, argv fallback, --help, and all error branches.
  • End-to-end on v2.1.218 via claude -p --plugin-dir: /ralph-wiggum:ralph-loop Say hello then stop; mention Bob's code --max-iterations 1 — previously failed pre-model; now the loop starts, runs one iteration, hits the max-iterations limit, and cleans up its state file.

This PR was written with the assistance of Claude Code; all changes were reviewed and the tests run by me.

The /ralph-loop command substituted $ARGUMENTS directly into the
auto-executed shell line, so the user's prompt text was parsed as shell
code. Any prompt containing an apostrophe (Bob's), a semicolon, $(...),
or a newline made the setup command fail its permission check (or fail
to parse) before the loop ever started:

  Error: Shell command permission check failed for pattern ...
  This Bash command contains multiple operations.

With permission checks bypassed, $(...) in a prompt would even execute.

Feed $ARGUMENTS to setup-ralph-loop.sh via a quoted heredoc on stdin
instead, so prompt text is never shell-parsed, and parse the
--max-iterations / --completion-promise options textually in the
script. Direct argv invocation still works. The state file format is
unchanged, so stop-hook.sh is unaffected.

Fixes anthropics#16037

@SafeMemoryZone SafeMemoryZone left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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.

ralph-wiggum plugin: Bash command permission check fails on multi-line scripts with newlines

2 participants