fix(import): ralph-import hangs indefinitely when converting PRDs#103
fix(import): ralph-import hangs indefinitely when converting PRDs#103merlinrabens wants to merge 1 commit into
Conversation
WalkthroughReplaces inline Claude CLI invocations in Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Add --print and --strict-mcp-config to all Claude CLI invocations in
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@ralph_import.sh`:
- Around line 430-437: Add documentation for the --print flag to CLAUDE.md: in
the Key Commands section add an entry describing --print (used by
ralph_import.sh for non-interactive output) alongside the existing
--output-format and --allowed-tools entries, and update the Recent Improvements
(v0.9.8) changelog to mention the new --print option and its purpose; ensure the
description clarifies expected behavior and any interaction with --output-format
and --allowed-tools so users know how to use it with the CLAUDE CLI.
🧹 Nitpick comments (1)
ralph_import.sh (1)
426-438: Build the Claude CLI command withCLAUDE_CMD_ARGSarray.Line 430/437 still constructs the command inline, which risks quoting issues and violates the script guidelines for command arrays. Consider consolidating both paths into a
CLAUDE_CMD_ARGSarray to preserve proper quoting and reduce injection risk.✅ Proposed refactor
- if [[ "$use_modern_cli" == "true" ]]; then - # Modern CLI invocation with JSON output and controlled tool permissions - # --allowedTools permits file operations without user prompts - # Array expansion preserves quoting for each tool argument - if $CLAUDE_CODE_CMD --print --output-format "$CLAUDE_OUTPUT_FORMAT" --allowedTools "${CLAUDE_ALLOWED_TOOLS[@]}" < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then - cli_exit_code=0 - else - cli_exit_code=$? - fi - else - # Standard CLI invocation (backward compatible) - if $CLAUDE_CODE_CMD --print < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then - cli_exit_code=0 - else - cli_exit_code=$? - fi - fi + local -a CLAUDE_CMD_ARGS=() + if [[ "$use_modern_cli" == "true" ]]; then + # Modern CLI invocation with JSON output and controlled tool permissions + # --allowedTools permits file operations without user prompts + CLAUDE_CMD_ARGS=( + "$CLAUDE_CODE_CMD" + --print + --output-format "$CLAUDE_OUTPUT_FORMAT" + --allowedTools "${CLAUDE_ALLOWED_TOOLS[@]}" + ) + else + # Standard CLI invocation (backward compatible) + CLAUDE_CMD_ARGS=("$CLAUDE_CODE_CMD" --print) + fi + + if "${CLAUDE_CMD_ARGS[@]}" < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then + cli_exit_code=0 + else + cli_exit_code=$? + fiAs per coding guidelines, use
CLAUDE_CMD_ARGSfor shell-safe command building.
| if $CLAUDE_CODE_CMD --print --output-format "$CLAUDE_OUTPUT_FORMAT" --allowedTools "${CLAUDE_ALLOWED_TOOLS[@]}" < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then | ||
| cli_exit_code=0 | ||
| else | ||
| cli_exit_code=$? | ||
| fi | ||
| else | ||
| # Standard CLI invocation (backward compatible) | ||
| if $CLAUDE_CODE_CMD < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then | ||
| if $CLAUDE_CODE_CMD --print < "$CONVERSION_PROMPT_FILE" > "$CONVERSION_OUTPUT_FILE" 2> "$stderr_file"; then |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# First, find if CLAUDE.md exists and check its structure
git ls-files | grep -i claudeRepository: frankbria/ralph-claude-code
Length of output: 178
🏁 Script executed:
# Search for --print flag usage in the codebase
rg "\-\-print" -nRepository: frankbria/ralph-claude-code
Length of output: 426
🏁 Script executed:
# Check the context around ralph_import.sh lines 430-437
cat -n ralph_import.sh | sed -n '420,445p'Repository: frankbria/ralph-claude-code
Length of output: 1476
🏁 Script executed:
# Check CLAUDE.md for --print flag documentation
rg "\-\-print" CLAUDE.md -C 3Repository: frankbria/ralph-claude-code
Length of output: 53
🏁 Script executed:
# Also check the Key Commands section in CLAUDE.md
cat -n CLAUDE.md | head -100Repository: frankbria/ralph-claude-code
Length of output: 4446
🏁 Script executed:
# Check Recent Improvements section
rg "Recent Improvements|--output-format" CLAUDE.md -A 5 -B 2Repository: frankbria/ralph-claude-code
Length of output: 1704
Document the --print flag in CLAUDE.md.
The --print flag is used in ralph_import.sh (lines 430, 437) for non-interactive output but is missing from CLAUDE.md. Add it to the Key Commands section (alongside --output-format and --allowed-tools) and update the Recent Improvements section (v0.9.8) to document this flag.
🤖 Prompt for AI Agents
In `@ralph_import.sh` around lines 430 - 437, Add documentation for the --print
flag to CLAUDE.md: in the Key Commands section add an entry describing --print
(used by ralph_import.sh for non-interactive output) alongside the existing
--output-format and --allowed-tools entries, and update the Recent Improvements
(v0.9.8) changelog to mention the new --print option and its purpose; ensure the
description clarifies expected behavior and any interaction with --output-format
and --allowed-tools so users know how to use it with the CLAUDE CLI.
261c692 to
77fed3e
Compare
…CLI usage The Claude CLI requires: - --print flag for non-interactive (piped) input mode - --strict-mcp-config to skip loading user MCP servers for faster startup Also fixes the CLI version check to use the configured CLAUDE_CODE_CMD variable instead of npx, which improves detection for global installs. This fixes ralph-import getting stuck when converting PRDs.
77fed3e to
df686f1
Compare
|
@claude Review the PR |
|
Claude encountered an error —— View job I'll analyze this and get back to you. |
Review SummaryThanks for this fix! The ✅ Code Review: ApprovedThe fix looks good:
All 440 tests pass.
|
|
Thank you @merlinrabens for identifying this critical issue! 🙏 The branch was too far behind main to merge directly, but we've applied your fix in commit fe94cbd. The key insight was correct: the Credit given in the commit message. Thanks for the contribution! |
Without --print, Claude CLI starts an interactive session that hangs when stdin comes from a file/pipe. This caused ralph-import to hang indefinitely when converting PRDs. Changes: - Add --print flag for non-interactive (piped) input mode - Add --strict-mcp-config to skip loading user MCP servers (faster startup) Credit: @merlinrabens (PR #103)
TL;DR
ralph-importhangs indefinitely when converting PRDs because the Claude CLI is invoked without required flags for non-interactive mode.The Problem
When running
ralph-import <prd> <project>, the script gets stuck at:...and never completes. This happens because:
--printflag - Without this, Claude CLI starts an interactive session that hangs when stdin comes from a filenpx @anthropic/claude-codewhich fails for users with globalclaudeinstallsThe Fix
--printflag for non-interactive (piped) input mode--strict-mcp-configto skip loading user MCP servers$CLAUDE_CODE_CMD --versionfor CLI detectionTesting
ralph-importnow completes successfully (~2-3 min for complex PRDs)