claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

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

Open Pochetes opened this issue 11 months ago • 4 comments

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Description

I'm encountering a permission check error when using the ralph-wiggum plugin from claude-plugins-official. The plugin's bash command contains newlines, which triggers Claude Code's security safeguards.

Error Message

Error: Bash command permission check failed for pattern "```!
"/Users/rmart/.claude/plugins/cache/claude-plugins-official/ralph-wiggum/6d3752c000e2/scripts/setup-ralph-loop.sh" "write 1+1 in a file" --max-iterations 25
# Extract and display completion promise if set
if [ -f .claude/ralph-loop.local.md ]; then
  PROMISE=$(grep '^completion_promise:' .claude/ralph-loop.local.md | sed 's/completion_promise: *//' | sed 's/^"\(.*\)"$/\1/')
...
```": Command contains newlines that could separate multiple commands

Steps to Reproduce

  1. Install the ralph-wiggum plugin from the official Claude plugins repository
  2. Run a task like: "write 1+1 in a file"
  3. Observe the permission check error

Expected Behavior

The plugin should be able to execute its bash scripts without triggering newline-based command separation security checks.

Root Cause

The ralph-wiggum plugin is attempting to run a multi-line bash script (setup-ralph-loop.sh) via the Bash tool. Claude Code's security checks prevent executing commands containing newlines because newlines could potentially be used to chain multiple commands together. This is a legitimate security concern, but it conflicts with the plugin's implementation approach.

Suggested Solution

The plugin maintainers should refactor the script to:

  1. Write the script to a temporary file first, then execute that file instead of embedding multi-line commands
  2. Or encode/structure the command to avoid passing raw newlines to the Bash execution layer

Environment

  • System: macOS
  • Plugin: ralph-wiggum (claude-plugins-official)
  • Claude Code: Latest version

What Should Happen?

The ralph-wiggum plugin should be able to execute its bash scripts without triggering newline-based command separation security checks. The plugin's multi-line setup script should run successfully and return proper completion promises without permission errors.

Error Messages/Logs

Error: Bash command permission check failed for pattern "!
"/Users/rmart/.claude/plugins/cache/claude-plugins-official/ralph-wiggum/6d3752c000e2/scripts/setup-ralph-loop.sh" "write 1+1 in a file" --max-iterations 25
# Extract and display completion promise if set
if [ -f .claude/ralph-loop.local.md ]; then
  PROMISE=$(grep '^completion_promise:' .claude/ralph-loop.local.md | sed 's/completion_promise: *//' | sed 's/^"\(.*\)"$/\1/')
  if [ -n "$PROMISE" ] && [ "$PROMISE" != "null" ]; then
    echo ""
    echo "═══════════════════════════════════════════════════════════"
    echo "CRITICAL - Ralph Loop Completion Promise"
    echo "═══════════════════════════════════════════════════════════"
...
": Command contains newlines that could separate multiple commands

Steps to Reproduce

  1. Install the ralph-wiggum plugin from claude-plugins-official
  2. Run a task with the plugin, e.g., "write 1+1 in a file"
  3. Observe that the plugin attempts to execute its setup-ralph-loop.sh bash script
  4. The bash command permission check fails with the error message about newlines
  5. The task does not complete because the script cannot be executed

Claude Model

None

Is this a regression?

No, this never worked

Last Working Version

No response

Claude Code Version

Latest

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

This is a plugin-specific issue where the official ralph-wiggum plugin's bash script execution is blocked by Claude Code's security safeguards against command injection. The plugin attempts to execute a multi-line bash script that contains legitimate content, but the security check is overly restrictive for plugin use cases. The plugin maintainers should refactor their implementation to avoid passing raw newlines in bash commands.

Pochetes avatar Jan 02 '26 04:01 Pochetes

Found 3 possible duplicate issues:

  1. https://github.com/anthropics/claude-code/issues/16028
  2. https://github.com/anthropics/claude-code/issues/15708
  3. https://github.com/anthropics/claude-code/issues/12170

This issue will be automatically closed as a duplicate in 3 days.

  • If your issue is a duplicate, please close it and 👍 the existing issue instead
  • To prevent auto-closure, add a comment or 👎 this comment

🤖 Generated with Claude Code

github-actions[bot] avatar Jan 02 '26 04:01 github-actions[bot]

+1

lenichols avatar Jan 04 '26 09:01 lenichols

+1

taigfs avatar Jan 05 '26 12:01 taigfs

+1 - WSL2 running via windows 10. Adding

  "permissions": {
    "allow": ["Bash"]
  },

Or running Claude Code in --dangerously-skip-permissions mode it works as intended.

jspicher avatar Jan 05 '26 12:01 jspicher

My solution:

write the prompt to /tmp/prompt.txt, then use this:

~/.claude/plugins/cache/claude-plugins-official/ralph-loop/b97f6eadd929/scripts/setup-ralph-loop.sh
#!/bin/bash

# Ralph Loop Setup Script
# Creates state file for in-session Ralph loop

set -euo pipefail

# Parse arguments
PROMPT_PARTS=()
MAX_ITERATIONS=0
COMPLETION_PROMISE="null"

# Parse options and positional arguments
while [[ $# -gt 0 ]]; do
  case $1 in
    -h|--help)
      cat << 'HELP_EOF'
Ralph Loop - Interactive self-referential development loop

USAGE:
  /ralph-loop [PROMPT...] [OPTIONS]

ARGUMENTS:
  PROMPT...    Initial prompt to start the loop (can be multiple words without quotes)

OPTIONS:
  --max-iterations <n>           Maximum iterations before auto-stop (default: unlimited)
  --completion-promise '<text>'  Promise phrase (USE QUOTES for multi-word)
  -h, --help                     Show this help message

DESCRIPTION:
  Starts a Ralph Loop in your CURRENT session. The stop hook prevents
  exit and feeds your output back as input until completion or iteration limit.

  To signal completion, you must output: <promise>YOUR_PHRASE</promise>

  Use this for:
  - Interactive iteration where you want to see progress
  - Tasks requiring self-correction and refinement
  - Learning how Ralph works

EXAMPLES:
  /ralph-loop Build a todo API --completion-promise 'DONE' --max-iterations 20
  /ralph-loop --max-iterations 10 Fix the auth bug
  /ralph-loop Refactor cache layer  (runs forever)
  /ralph-loop --completion-promise 'TASK COMPLETE' Create a REST API

STOPPING:
  Only by reaching --max-iterations or detecting --completion-promise
  No manual stop - Ralph runs infinitely by default!

MONITORING:
  # View current iteration:
  grep '^iteration:' .claude/ralph-loop.local.md

  # View full state:
  head -10 .claude/ralph-loop.local.md
HELP_EOF
      exit 0
      ;;
    --max-iterations)
      if [[ -z "${2:-}" ]]; then
        echo "❌ Error: --max-iterations requires a number argument" >&2
        echo "" >&2
        echo "   Valid examples:" >&2
        echo "     --max-iterations 10" >&2
        echo "     --max-iterations 50" >&2
        echo "     --max-iterations 0  (unlimited)" >&2
        echo "" >&2
        echo "   You provided: --max-iterations (with no number)" >&2
        exit 1
      fi
      if ! [[ "$2" =~ ^[0-9]+$ ]]; then
        echo "❌ Error: --max-iterations must be a positive integer or 0, got: $2" >&2
        echo "" >&2
        echo "   Valid examples:" >&2
        echo "     --max-iterations 10" >&2
        echo "     --max-iterations 50" >&2
        echo "     --max-iterations 0  (unlimited)" >&2
        echo "" >&2
        echo "   Invalid: decimals (10.5), negative numbers (-5), text" >&2
        exit 1
      fi
      MAX_ITERATIONS="$2"
      shift 2
      ;;
    --completion-promise)
      if [[ -z "${2:-}" ]]; then
        echo "❌ Error: --completion-promise requires a text argument" >&2
        echo "" >&2
        echo "   Valid examples:" >&2
        echo "     --completion-promise 'DONE'" >&2
        echo "     --completion-promise 'TASK COMPLETE'" >&2
        echo "     --completion-promise 'All tests passing'" >&2
        echo "" >&2
        echo "   You provided: --completion-promise (with no text)" >&2
        echo "" >&2
        echo "   Note: Multi-word promises must be quoted!" >&2
        exit 1
      fi
      COMPLETION_PROMISE="$2"
      shift 2
      ;;
    *)
      # Non-option argument - collect all as prompt parts
      PROMPT_PARTS+=("$1")
      shift
      ;;
  esac
done

# Join all prompt parts with spaces
PROMPT="$(cat /tmp/prompt.txt)"

# Validate prompt is non-empty
if [[ -z "$PROMPT" ]]; then
  echo "❌ Error: No prompt provided" >&2
  echo "" >&2
  echo "   Ralph needs a task description to work on." >&2
  echo "" >&2
  echo "   Examples:" >&2
  echo "     /ralph-loop Build a REST API for todos" >&2
  echo "     /ralph-loop Fix the auth bug --max-iterations 20" >&2
  echo "     /ralph-loop --completion-promise 'DONE' Refactor code" >&2
  echo "" >&2
  echo "   For all options: /ralph-loop --help" >&2
  exit 1
fi

# Create state file for stop hook (markdown with YAML frontmatter)
mkdir -p .claude

# Quote completion promise for YAML if it contains special chars or is not null
if [[ -n "$COMPLETION_PROMISE" ]] && [[ "$COMPLETION_PROMISE" != "null" ]]; then
  COMPLETION_PROMISE_YAML="\"$COMPLETION_PROMISE\""
else
  COMPLETION_PROMISE_YAML="null"
fi

cat > .claude/ralph-loop.local.md <<EOF
---
active: true
iteration: 1
max_iterations: $MAX_ITERATIONS
completion_promise: $COMPLETION_PROMISE_YAML
started_at: "$(date -u +%Y-%m-%dT%H:%M:%SZ)"
---

$PROMPT
EOF

# Output setup message
cat <<EOF
🔄 Ralph loop activated in this session!

Iteration: 1
Max iterations: $(if [[ $MAX_ITERATIONS -gt 0 ]]; then echo $MAX_ITERATIONS; else echo "unlimited"; fi)
Completion promise: $(if [[ "$COMPLETION_PROMISE" != "null" ]]; then echo "${COMPLETION_PROMISE//\"/} (ONLY output when TRUE - do not lie!)"; else echo "none (runs forever)"; fi)

The stop hook is now active. When you try to exit, the SAME PROMPT will be
fed back to you. You'll see your previous work in files, creating a
self-referential loop where you iteratively improve on the same task.

To monitor: head -10 .claude/ralph-loop.local.md

⚠️  WARNING: This loop cannot be stopped manually! It will run infinitely
    unless you set --max-iterations or --completion-promise.

🔄
EOF

# Output the initial prompt if provided
if [[ -n "$PROMPT" ]]; then
  echo ""
  echo "$PROMPT"
fi

# Display completion promise requirements if set
if [[ "$COMPLETION_PROMISE" != "null" ]]; then
  echo ""
  echo "═══════════════════════════════════════════════════════════"
  echo "CRITICAL - Ralph Loop Completion Promise"
  echo "═══════════════════════════════════════════════════════════"
  echo ""
  echo "To complete this loop, output this EXACT text:"
  echo "  <promise>$COMPLETION_PROMISE</promise>"
  echo ""
  echo "STRICT REQUIREMENTS (DO NOT VIOLATE):"
  echo "  ✓ Use <promise> XML tags EXACTLY as shown above"
  echo "  ✓ The statement MUST be completely and unequivocally TRUE"
  echo "  ✓ Do NOT output false statements to exit the loop"
  echo "  ✓ Do NOT lie even if you think you should exit"
  echo ""
  echo "IMPORTANT - Do not circumvent the loop:"
  echo "  Even if you believe you're stuck, the task is impossible,"
  echo "  or you've been running too long - you MUST NOT output a"
  echo "  false promise statement. The loop is designed to continue"
  echo "  until the promise is GENUINELY TRUE. Trust the process."
  echo ""
  echo "  If the loop should stop, the promise statement will become"
  echo "  true naturally. Do not force it by lying."
  echo "═══════════════════════════════════════════════════════════"
fi

This basically reads the prompt from /tmp/prompt.txt instead of using the arguments (which breaks if you have special characters or new lines)

denysvitali avatar Jan 07 '26 19:01 denysvitali

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Feb 07 '26 10:02 github-actions[bot]

This is still an issue when the prompt is multi-line

crobinson42 avatar Feb 20 '26 14:02 crobinson42

Still reproducible on v2.1.218 — and it's broader than newlines: any prompt with an apostrophe (Bob's), semicolon, or $(...) fails the same way, because $ARGUMENTS is substituted straight into the auto-executed shell line. Opened #80495, which feeds the arguments to the setup script via a quoted heredoc on stdin so prompt text is never shell-parsed (verified end-to-end on 2.1.218).

serhiileniv avatar Jul 23 '26 09:07 serhiileniv