Skip to content

fix(import): ralph-import hangs indefinitely when converting PRDs#103

Closed
merlinrabens wants to merge 1 commit into
frankbria:mainfrom
merlinrabens:fix/add-print-flag-for-noninteractive-cli
Closed

fix(import): ralph-import hangs indefinitely when converting PRDs#103
merlinrabens wants to merge 1 commit into
frankbria:mainfrom
merlinrabens:fix/add-print-flag-for-noninteractive-cli

Conversation

@merlinrabens
Copy link
Copy Markdown

@merlinrabens merlinrabens commented Jan 20, 2026

TL;DR

ralph-import hangs 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:

[INFO] Using modern CLI with JSON output format

...and never completes. This happens because:

  1. Missing --print flag - Without this, Claude CLI starts an interactive session that hangs when stdin comes from a file
  2. MCP server loading - The CLI loads all user-configured MCP servers (Firecrawl, Airtable, etc.), adding 30+ seconds of startup delay even when they're not needed
  3. Incorrect CLI detection - The script checks for npx @anthropic/claude-code which fails for users with global claude installs

The Fix

  • Add --print flag for non-interactive (piped) input mode
  • Add --strict-mcp-config to skip loading user MCP servers
  • Use $CLAUDE_CODE_CMD --version for CLI detection
  • Refactor command building to use array for shell safety

Testing

  • ralph-import now completes successfully (~2-3 min for complex PRDs)
  • Generated files contain properly converted content from PRD
  • No false "CLI not found" warning for global installs

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 20, 2026

Walkthrough

Replaces inline Claude CLI invocations in ralph_import.sh with a quoted CLAUDE_CMD_ARGS array built from CLAUDE_CODE_CMD, adds --print and other CLI flags in modern mode, unifies execution via "${CLAUDE_CMD_ARGS[@]}", preserves error handling and JSON parsing, and logs CLI stderr/session info when present.

Changes

Cohort / File(s) Summary
Claude CLI invocation & execution
ralph_import.sh
Introduced CLAUDE_CODE_CMD usage and a quoted CLAUDE_CMD_ARGS array; added --print, --strict-mcp-config, --output-format, and --allowedTools in modern mode; unified execution via "${CLAUDE_CMD_ARGS[@]}" with stdin/stdout redirection.
Argument safety & logging
ralph_import.sh
Added explicit local array initialization for safe quoting/shell-escaping; capture and log CLI stderr and session IDs when present; retained existing error handling and JSON parsing flow.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 I hopped through code with gentle paws,
Built a tidy arg array without a pause,
Claude now marches in a single line,
Prints its thoughts, keeps logs just fine,
Little rabbit cheers — the flow's divine! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Title check ⚠️ Warning The title mentions fixing ralph-import hangs, but the actual primary changes are adding --print and --strict-mcp-config flags for non-interactive CLI usage. Update title to reflect the main technical fix: 'fix(import): add --print and --strict-mcp-config for non-interactive Claude CLI usage' to accurately describe the primary changes.
✅ Passed checks (2 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp Bot commented Jan 20, 2026

Add --print and --strict-mcp-config to all Claude CLI invocations in ralph_import.sh to support non-interactive usage

Update check_dependencies to call $CLAUDE_CODE_CMD --version and adjust the install warning; refactor convert_prd_with_claude to build a single argument array and always pass --print and --strict-mcp-config, preserving modern flags and adding these flags to legacy mode, with unified exit handling and separate stderr logging in ralph_import.sh.

📍Where to Start

Start with the convert_prd_with_claude routine in ralph_import.sh, then review check_dependencies for the updated CLI detection.


Macroscope summarized df686f1.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 with CLAUDE_CMD_ARGS array.

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_ARGS array 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=$?
+    fi

As per coding guidelines, use CLAUDE_CMD_ARGS for shell-safe command building.

Comment thread ralph_import.sh Outdated
Comment on lines +430 to +437
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find if CLAUDE.md exists and check its structure
git ls-files | grep -i claude

Repository: frankbria/ralph-claude-code

Length of output: 178


🏁 Script executed:

# Search for --print flag usage in the codebase
rg "\-\-print" -n

Repository: 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 3

Repository: frankbria/ralph-claude-code

Length of output: 53


🏁 Script executed:

# Also check the Key Commands section in CLAUDE.md
cat -n CLAUDE.md | head -100

Repository: frankbria/ralph-claude-code

Length of output: 4446


🏁 Script executed:

# Check Recent Improvements section
rg "Recent Improvements|--output-format" CLAUDE.md -A 5 -B 2

Repository: 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.

@merlinrabens merlinrabens force-pushed the fix/add-print-flag-for-noninteractive-cli branch from 261c692 to 77fed3e Compare January 20, 2026 12:27
@merlinrabens merlinrabens changed the title fix(import): add --print flag for non-interactive Claude CLI usage fix(import): add --print and --strict-mcp-config for non-interactive CLI usage Jan 20, 2026
…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.
@merlinrabens merlinrabens force-pushed the fix/add-print-flag-for-noninteractive-cli branch from 77fed3e to df686f1 Compare January 20, 2026 12:29
@merlinrabens merlinrabens changed the title fix(import): add --print and --strict-mcp-config for non-interactive CLI usage fix(import): ralph-import hangs indefinitely when converting PRDs Jan 20, 2026
@frankbria
Copy link
Copy Markdown
Owner

@claude Review the PR

@claude
Copy link
Copy Markdown

claude Bot commented Jan 30, 2026

Claude encountered an error —— View job

Command failed: git fetch origin --depth=20 fix/add-print-flag-for-noninteractive-cli

I'll analyze this and get back to you.

@frankbria
Copy link
Copy Markdown
Owner

Review Summary

Thanks for this fix! The --print and --strict-mcp-config flags are exactly what's needed to prevent ralph-import from hanging in non-interactive mode.

✅ Code Review: Approved

The fix looks good:

  • --print correctly enables non-interactive mode for piped input
  • --strict-mcp-config prevents unnecessary MCP server loading (30+ second savings)
  • Array-based command building improves shell safety
  • Using $CLAUDE_CODE_CMD instead of hardcoded npx path fixes detection for global installs

All 440 tests pass.

⚠️ Action Required: Rebase Needed

This PR is 20 commits behind main and needs to be rebased before merging. Two commits have touched ralph_import.sh since this PR was created:

  • c7e7a1c: refactor(naming): remove @ prefix from on-disk filenames
  • 9b19d70: feat(structure): migrate Ralph files to .ralph/ subfolder

Please rebase onto current main:

git fetch origin
git rebase origin/main
git push --force-with-lease

Once rebased and CI passes, this is ready to merge.

@frankbria frankbria self-assigned this Jan 30, 2026
@frankbria
Copy link
Copy Markdown
Owner

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 --print flag is required for piped input to prevent Claude CLI from starting an interactive session that hangs. We also added --strict-mcp-config per your suggestion to skip loading user MCP servers.

Credit given in the commit message. Thanks for the contribution!

@frankbria frankbria closed this Feb 2, 2026
frankbria pushed a commit that referenced this pull request Feb 2, 2026
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)
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.

2 participants