Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ tmux attach -t <session-name>

### Running Tests
```bash
# Run all tests (556 tests)
# Run all tests (566 tests)
npm test

# Run specific test suites
Expand Down Expand Up @@ -216,12 +216,20 @@ Ralph uses modern Claude Code CLI flags for structured communication:

**Configuration Variables:**
```bash
CLAUDE_CODE_CMD="claude" # Claude Code CLI command (configurable via .ralphrc, Issue #97)
CLAUDE_OUTPUT_FORMAT="json" # Output format: json (default) or text
CLAUDE_ALLOWED_TOOLS="Write,Read,Edit,Bash(git add *),Bash(git commit *),...,Bash(npm *),Bash(pytest)" # Allowed tool permissions (see File Protection)
CLAUDE_USE_CONTINUE=true # Enable session continuity
CLAUDE_MIN_VERSION="2.0.76" # Minimum Claude CLI version
```

**Claude Code CLI Command (Issue #97):**
- `CLAUDE_CODE_CMD` defaults to `"claude"` (global install)
- Configurable via `.ralphrc` for alternative installations (e.g., `"npx @anthropic-ai/claude-code"`)
- Auto-detected during `ralph-enable` and `ralph-setup` (prefers `claude` if available, falls back to npx)
- Validated at startup with `validate_claude_command()` — displays clear error with installation instructions if not found
- Environment variable `CLAUDE_CODE_CMD` takes precedence over `.ralphrc`

Comment on lines +219 to +232
Copy link
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:

# Search for all references to anthropic/claude-code in the codebase
rg "anthropic.*claude-code|claude-code.*anthropic" -i

Repository: frankbria/ralph-claude-code

Length of output: 2497


🏁 Script executed:

# Also search for references in .ralphrc examples and setup documentation
rg -t md -t sh "CLAUDE_CODE_CMD|npx" | head -30

Repository: frankbria/ralph-claude-code

Length of output: 2775


🌐 Web query:

Claude Code CLI npm package name official documentation

💡 Result:

  • Official Claude Code CLI npm package name: @anthropic-ai/claude-code (installed e.g. npm install -g @anthropic-ai/claude-code``). [1][2]
  • Official documentation: Anthropic’s “Claude Code SDK” docs (includes CLI usage via the claude command). [1]

Sources: [1] Anthropic docs, Claude Code SDK; [2] npm package page for @anthropic-ai/claude-code.


Fix inconsistent Claude Code CLI package name references across the codebase.

The canonical npm package is @anthropic-ai/claude-code, but inconsistencies exist:

  • Lines 219-232 in CLAUDE.md are correct (@anthropic-ai/claude-code)
  • However, another section of CLAUDE.md incorrectly references @anthropic/claude-code (missing -ai)
  • create_files.sh also incorrectly uses @anthropic/claude-code

Update these references to @anthropic-ai/claude-code for consistency across setup documentation and scripts to avoid user confusion during installation.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CLAUDE.md` around lines 219 - 232, There are inconsistent package-name
references for the Claude Code CLI: replace every occurrence of the incorrect
"@anthropic/claude-code" with the canonical "@anthropic-ai/claude-code" in the
docs and scripts; specifically update the misplaced reference in CLAUDE.md (the
other section that currently shows "@anthropic/claude-code") and the install
line in create_files.sh so they match the CLAUDE_CODE_CMD documentation and
validation (validate_claude_command()) to avoid install/runtime confusion.

**CLI Options:**
- `--output-format json|text` - Set Claude output format (default: json). Note: `--live` mode requires JSON and will auto-switch from text to json.
- `--allowed-tools "Write,Read,Bash(git *)"` - Restrict allowed tools
Expand Down Expand Up @@ -511,13 +519,13 @@ Ralph uses a multi-layered strategy to prevent Claude from accidentally deleting

## Test Suite

### Test Files (556 tests total)
### Test Files (566 tests total)

| File | Tests | Description |
|------|-------|-------------|
| `test_circuit_breaker_recovery.bats` | 19 | Cooldown timer, auto-reset, parse_iso_to_epoch, CLI flag (Issue #160) |
| `test_cli_parsing.bats` | 35 | CLI argument parsing for all flags + monitor parameter forwarding |
| `test_cli_modern.bats` | 56 | Modern CLI commands (Phase 1.1) + build_claude_command fix + live mode text format fix (#164) + errexit pipeline guard (#175) + ALLOWED_TOOLS tightening (#149) + API limit false positive detection (#183) |
| `test_cli_modern.bats` | 66 | Modern CLI commands (Phase 1.1) + build_claude_command fix + live mode text format fix (#164) + errexit pipeline guard (#175) + ALLOWED_TOOLS tightening (#149) + API limit false positive detection (#183) + Claude CLI command validation (#97) |
| `test_json_parsing.bats` | 52 | JSON output format parsing + Claude CLI format + session management + array format |
| `test_session_continuity.bats` | 44 | Session lifecycle management + expiration + circuit breaker integration + issue #91 fix |
| `test_exit_detection.bats` | 53 | Exit signal detection + EXIT_SIGNAL-based completion indicators + progress detection |
Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Ralph is an implementation of the Geoffrey Huntley's technique for Claude Code t

**Version**: v0.11.5 - Active Development
**Core Features**: Working and tested
**Test Coverage**: 556 tests, 100% pass rate
**Test Coverage**: 566 tests, 100% pass rate

Comment on lines +21 to 22
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Align test-count references after the 566 update.

Several lines now say 566 tests, but other nearby lines still show 556/556 passing and “Added 8 new tests” even though 548 → 566 implies +18. Please update the badge/summary text so counts and deltas match.

Based on learnings: Documentation MUST remain synchronized with codebase: inline script comments for all functions, README updates for features, template file updates for patterns, and CLAUDE.md updates for new commands and behaviors.

Also applies to: 50-51, 639-640, 665-667, 773-773

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` around lines 21 - 22, Update the README test-summary and any
test-count badges/text so all references reflect 566 tests and a +18 delta
instead of the old 556/556 and “Added 8 new tests”; specifically find the "Test
Coverage" badge/header and the lines that say "556/556 passing" and "Added 8 new
tests" (occurrences noted around the sections referenced in the review) and
change them to consistent wording (e.g., "566 tests, 100% pass" and "Added 18
new tests" or equivalent delta language) so every summary, badge and sentence
that mentions test counts or deltas is synchronized.

### What's Working Now
- Autonomous development loops with intelligent exit detection
Expand Down Expand Up @@ -47,7 +47,7 @@ Ralph is an implementation of the Geoffrey Huntley's technique for Claude Code t
- Three-layer API limit detection: timeout guard → structural JSON (`rate_limit_event`) → filtered text fallback
- Unattended mode: API limit prompt now auto-waits on timeout instead of exiting
- Fixed bash 3.x compatibility: `${,,}` lowercase substitution replaced with POSIX `tr` (#187)
- Added 8 new tests for API limit detection (548 → 556 tests)
- Added 8 new tests for API limit detection (548 → 566 tests)

**v0.11.4 - Bug Fixes & Compatibility**
- Fixed progress detection: Git commits within a loop now count as progress (#141)
Expand Down Expand Up @@ -400,6 +400,10 @@ Each Ralph project can have a `.ralphrc` configuration file:
PROJECT_NAME="my-project"
PROJECT_TYPE="typescript"

# Claude Code CLI command (auto-detected, override if needed)
CLAUDE_CODE_CMD="claude"
# CLAUDE_CODE_CMD="npx @anthropic-ai/claude-code" # Alternative: use npx

# Loop settings
MAX_CALLS_PER_HOUR=100
CLAUDE_TIMEOUT_MINUTES=15
Expand Down Expand Up @@ -613,7 +617,7 @@ my-project/
## System Requirements

- **Bash 4.0+** - For script execution
- **Claude Code CLI** - `npm install -g @anthropic-ai/claude-code`
- **Claude Code CLI** - `npm install -g @anthropic-ai/claude-code` (or use npx — set `CLAUDE_CODE_CMD` in `.ralphrc`)
- **tmux** - Terminal multiplexer for integrated monitoring (recommended)
- **jq** - JSON processing for status tracking
- **Git** - Version control (projects are initialized as git repos)
Expand All @@ -632,7 +636,7 @@ If you want to run the test suite:
# Install BATS testing framework
npm install -g bats bats-support bats-assert

# Run all tests (556 tests)
# Run all tests (566 tests)
npm test

# Run specific test suites
Expand All @@ -658,7 +662,7 @@ bats tests/integration/test_installation.bats
```

Current test status:
- **556 tests** across 18 test files
- **566 tests** across 18 test files
- **100% pass rate** (556/556 passing)
- Comprehensive unit and integration tests
- Specialized tests for JSON parsing, CLI flags, circuit breaker, EXIT_SIGNAL behavior, enable wizard, and installation workflows
Expand Down Expand Up @@ -728,6 +732,7 @@ tail -f .ralph/logs/ralph.log

### Common Issues

- **Ralph exits silently on first loop** - Claude Code CLI may not be installed or not in PATH. Ralph validates the command at startup and shows installation instructions. If using npx, add `CLAUDE_CODE_CMD="npx @anthropic-ai/claude-code"` to `.ralphrc`
- **Rate Limits** - Ralph automatically waits and displays countdown
- **5-Hour API Limit** - Ralph detects and prompts for user action (wait or exit)
- **Stuck Loops** - Check `fix_plan.md` for unclear or conflicting tasks
Expand Down Expand Up @@ -765,7 +770,7 @@ cd ralph-claude-code

# Install dependencies and run tests
npm install
npm test # All 556 tests must pass
npm test # All 566 tests must pass
```

### Priority Contribution Areas
Expand Down
10 changes: 8 additions & 2 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,14 @@ check_dependencies() {
fi
fi

# Claude Code CLI will be downloaded automatically when first used
log "INFO" "Claude Code CLI (@anthropic-ai/claude-code) will be downloaded when first used."
# Check Claude Code CLI availability
if command -v claude &>/dev/null; then
log "INFO" "Claude Code CLI found: $(command -v claude)"
else
log "WARN" "Claude Code CLI ('claude') not found in PATH."
log "INFO" " Install globally: npm install -g @anthropic-ai/claude-code"
log "INFO" " Or use npx: set CLAUDE_CODE_CMD=\"npx @anthropic-ai/claude-code\" in .ralphrc"
fi

# Check tmux (optional)
if ! command -v tmux &> /dev/null; then
Expand Down
14 changes: 14 additions & 0 deletions lib/enable_core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,14 @@ generate_ralphrc() {
local project_type="${2:-unknown}"
local task_sources="${3:-local}"

# Auto-detect Claude Code CLI command
local claude_cmd="claude"
if ! command -v claude &>/dev/null; then
if command -v npx &>/dev/null; then
claude_cmd="npx @anthropic-ai/claude-code"
fi
fi
Comment on lines +684 to +690
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Verify the Claude Code CLI package name used for the npx fallback.

The fallback uses npx @anthropic-ai/claude-code``. The repo integration guidance calls out npx anthropic/claude-code; if the package name is wrong, new .ralphrc defaults will be unusable. Also, `claude_cmd` is snake_case; please switch to camelCase (e.g., `claudeCmd`) to match shell style rules.

What is the correct npm package name and npx invocation for the Claude Code CLI? Is it `@anthropic-ai/claude-code` or `@anthropic/claude-code`?

Based on learnings: All integration points must be with: Claude Code CLI (npx anthropic/claude-code), tmux terminal multiplexer, Git repositories, jq for JSON processing, GitHub Actions CI/CD, and standard Unix tools (bash, grep, date, etc.).
As per coding guidelines: **/*.sh: Use camelCase for variable names in bash and shell scripts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/enable_core.sh` around lines 684 - 690, Change the snake_case variable
claude_cmd to camelCase claudeCmd and update all references; also correct the
npx fallback package name from "@anthropic-ai/claude-code" to
"anthropic/claude-code" so the fallback becomes "npx anthropic/claude-code";
ensure the command -v checks and the assignment inside the auto-detect block use
claudeCmd consistently (including any later uses of the variable).


cat << RALPHRCEOF
# .ralphrc - Ralph project configuration
# Generated by: ralph enable
Expand All @@ -690,6 +698,12 @@ generate_ralphrc() {
PROJECT_NAME="${project_name}"
PROJECT_TYPE="${project_type}"

# Claude Code CLI command
# If "claude" is not in your PATH, set to your installation:
# "npx @anthropic-ai/claude-code" (uses npx, no global install needed)
# "/path/to/claude" (custom path)
CLAUDE_CODE_CMD="${claude_cmd}"

# Loop settings
MAX_CALLS_PER_HOUR=100
CLAUDE_TIMEOUT_MINUTES=15
Expand Down
5 changes: 5 additions & 0 deletions ralph_import.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ set -e

# Configuration
CLAUDE_CODE_CMD="claude"
# Load CLAUDE_CODE_CMD from .ralphrc if available
if [[ -f ".ralphrc" ]]; then
_ralphrc_cmd=$(grep "^CLAUDE_CODE_CMD=" ".ralphrc" 2>/dev/null | cut -d= -f2- | tr -d '"' | tr -d "'")
[[ -n "$_ralphrc_cmd" ]] && CLAUDE_CODE_CMD="$_ralphrc_cmd"
fi
Comment on lines +9 to +13
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Handle npx-style CLAUDE_CODE_CMD in dependency checks + camelCase naming.

Loading CLAUDE_CODE_CMD enables values like npx …, but the later command -v "$CLAUDE_CODE_CMD" will always warn when the value contains spaces. Consider validating only the executable token (or reuse a validate_claude_command-style check). Also, _ralphrc_cmd should be camelCase.

Suggested fix for the dependency check
-    if ! command -v "$CLAUDE_CODE_CMD" &> /dev/null 2>&1; then
+    local claudeCmdBin="${CLAUDE_CODE_CMD%% *}"
+    if ! command -v "$claudeCmdBin" &> /dev/null 2>&1; then
As per coding guidelines: `**/*.sh`: Use camelCase for variable names in bash and shell scripts.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ralph_import.sh` around lines 9 - 13, The code reads CLAUDE_CODE_CMD from
.ralphrc into a snake_case _ralphrc_cmd and later calls command -v on the entire
string which fails for npx-style values; rename the temp variable to camelCase
(e.g., ralphRcCmd) and extract/validate only the executable token (the first
whitespace-delimited word) before assigning to CLAUDE_CODE_CMD or before calling
command -v; reuse or call the existing validate_claude_command-style logic (or
implement equivalent) to check the executable token and preserve the full
original value in CLAUDE_CODE_CMD when valid.


# Modern CLI Configuration (Phase 1.1)
# These flags enable structured JSON output and controlled file operations
Expand Down
95 changes: 95 additions & 0 deletions ralph_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _env_CLAUDE_SESSION_EXPIRY_HOURS="${CLAUDE_SESSION_EXPIRY_HOURS:-}"
_env_VERBOSE_PROGRESS="${VERBOSE_PROGRESS:-}"
_env_CB_COOLDOWN_MINUTES="${CB_COOLDOWN_MINUTES:-}"
_env_CB_AUTO_RESET="${CB_AUTO_RESET:-}"
_env_CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-}"

# Now set defaults (only if not already set by environment)
MAX_CALLS_PER_HOUR="${MAX_CALLS_PER_HOUR:-100}"
Expand Down Expand Up @@ -116,6 +117,7 @@ RALPHRC_LOADED=false
# - CB_SAME_ERROR_THRESHOLD
# - CB_OUTPUT_DECLINE_THRESHOLD
# - RALPH_VERBOSE
# - CLAUDE_CODE_CMD (path or command for Claude Code CLI)
#
load_ralphrc() {
if [[ ! -f "$RALPHRC_FILE" ]]; then
Expand Down Expand Up @@ -152,11 +154,69 @@ load_ralphrc() {
[[ -n "$_env_VERBOSE_PROGRESS" ]] && VERBOSE_PROGRESS="$_env_VERBOSE_PROGRESS"
[[ -n "$_env_CB_COOLDOWN_MINUTES" ]] && CB_COOLDOWN_MINUTES="$_env_CB_COOLDOWN_MINUTES"
[[ -n "$_env_CB_AUTO_RESET" ]] && CB_AUTO_RESET="$_env_CB_AUTO_RESET"
[[ -n "$_env_CLAUDE_CODE_CMD" ]] && CLAUDE_CODE_CMD="$_env_CLAUDE_CODE_CMD"
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Medium

ralph_loop.sh:157 The environment override for CLAUDE_CODE_CMD won't work because _env_CLAUDE_CODE_CMD is captured (line 48) after the default is set (line 29). Consider changing line 29 to CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-claude}" to preserve user values.

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file ralph_loop.sh around line 157:

The environment override for `CLAUDE_CODE_CMD` won't work because `_env_CLAUDE_CODE_CMD` is captured (line 48) after the default is set (line 29). Consider changing line 29 to `CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-claude}"` to preserve user values.


RALPHRC_LOADED=true
return 0
}

# validate_claude_command - Verify the Claude Code CLI is available
#
# Checks that CLAUDE_CODE_CMD resolves to an executable command.
# For npx-based commands, validates that npx is available.
# Returns 0 if valid, 1 if not found (with helpful error message).
#
validate_claude_command() {
local cmd="$CLAUDE_CODE_CMD"

# For npx-based commands, check that npx itself is available
if [[ "$cmd" == npx\ * ]] || [[ "$cmd" == "npx" ]]; then
if ! command -v npx &>/dev/null; then
echo ""
echo -e "${RED}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║ NPX NOT FOUND ║${NC}"
echo -e "${RED}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}CLAUDE_CODE_CMD is set to use npx, but npx is not installed.${NC}"
echo ""
echo -e "${YELLOW}To fix this:${NC}"
echo " 1. Install Node.js (includes npx): https://nodejs.org"
echo " 2. Or install Claude Code globally:"
echo " npm install -g @anthropic-ai/claude-code"
echo " Then set in .ralphrc: CLAUDE_CODE_CMD=\"claude\""
echo ""
return 1
fi
return 0
fi

# For direct commands, check that the command exists
if ! command -v "$cmd" &>/dev/null; then
echo ""
echo -e "${RED}╔════════════════════════════════════════════════════════════╗${NC}"
echo -e "${RED}║ CLAUDE CODE CLI NOT FOUND ║${NC}"
echo -e "${RED}╚════════════════════════════════════════════════════════════╝${NC}"
echo ""
echo -e "${YELLOW}The Claude Code CLI command '${cmd}' is not available.${NC}"
echo ""
echo -e "${YELLOW}Installation options:${NC}"
echo " 1. Install globally (recommended):"
echo " npm install -g @anthropic-ai/claude-code"
echo ""
echo " 2. Use npx (no global install needed):"
echo " Add to .ralphrc: CLAUDE_CODE_CMD=\"npx @anthropic-ai/claude-code\""
echo ""
echo -e "${YELLOW}Current configuration:${NC} CLAUDE_CODE_CMD=\"${cmd}\""
echo ""
echo -e "${YELLOW}After installation or configuration:${NC}"
echo " ralph --monitor # Restart Ralph"
echo ""
return 1
fi

return 0
}

# Colors for terminal output
RED='\033[0;31m'
GREEN='\033[0;32m'
Expand Down Expand Up @@ -1256,6 +1316,35 @@ execute_claude_code() {
local claude_pid=$!
local progress_counter=0

# Early failure detection: if the command doesn't exist or fails immediately,
# the backgrounded process dies before the monitoring loop starts (Issue #97)
sleep 1
if ! kill -0 $claude_pid 2>/dev/null; then
wait $claude_pid 2>/dev/null
local early_exit=$?
Comment on lines +1322 to +1324
Copy link
Contributor

Choose a reason for hiding this comment

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

🟡 Medium

ralph_loop.sh:1322 Early failure detection treats exit code 0 as a failure. Consider checking $early_exit -ne 0 before entering the error path.

-        if ! kill -0 $claude_pid 2>/dev/null; then
-            wait $claude_pid 2>/dev/null
-            local early_exit=$?
+        if ! kill -0 $claude_pid 2>/dev/null; then
+            wait $claude_pid 2>/dev/null
+            local early_exit=$?
+            # Only treat non-zero exit as failure (Issue #97)
+            if [[ $early_exit -eq 0 ]]; then
+                log_status "INFO" "Claude Code completed quickly (exit code 0)"
+            else

🚀 Want me to fix this? Reply ex: "fix it for me".

🤖 Prompt for AI
In file ralph_loop.sh around lines 1322-1324:

Early failure detection treats exit code 0 as a failure. Consider checking `$early_exit -ne 0` before entering the error path.

local early_output=""
if [[ -f "$output_file" && -s "$output_file" ]]; then
early_output=$(tail -5 "$output_file" 2>/dev/null)
fi
log_status "ERROR" "❌ Claude Code process exited immediately (exit code: $early_exit)"
if [[ -n "$early_output" ]]; then
log_status "ERROR" "Output: $early_output"
fi
echo ""
echo -e "${RED}Claude Code failed to start.${NC}"
echo ""
echo -e "${YELLOW}Possible causes:${NC}"
echo " - '${CLAUDE_CODE_CMD}' command not found or not executable"
echo " - Claude Code CLI not installed"
echo " - Authentication or configuration issue"
echo ""
echo -e "${YELLOW}To fix:${NC}"
echo " 1. Verify Claude Code works: ${CLAUDE_CODE_CMD} --version"
echo " 2. Or set a different command in .ralphrc: CLAUDE_CODE_CMD=\"npx @anthropic-ai/claude-code\""
echo ""
return 1
fi
Comment on lines +1319 to +1346
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Early-failure check can misclassify fast successes.

If the CLI exits within 1s with exit code 0, this block still logs an error and returns 1. Consider only treating non‑zero early exits as failures or short‑circuit to the normal success path. Also, early_exit / early_output should be camelCase per shell style.

As per coding guidelines: **/*.sh: Use camelCase for variable names in bash and shell scripts.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@ralph_loop.sh` around lines 1319 - 1346, The early-failure block currently
treats any immediate exit (within sleep 1) as an error; change it to only treat
non-zero early exits as failures: after wait $claude_pid capture the exit into
earlyExit (camelCase) and read earlyOutput (camelCase) from "$output_file"; if
earlyExit is non-zero then log via log_status and print the diagnostic messages
referencing CLAUDE_CODE_CMD as now, otherwise treat a zero earlyExit as a normal
success (skip error logging and return/continue accordingly). Also rename
variables early_exit -> earlyExit and early_output -> earlyOutput throughout
this block to follow camelCase shell style.


# Show progress while Claude Code is running
while kill -0 $claude_pid 2>/dev/null; do
progress_counter=$((progress_counter + 1))
Expand Down Expand Up @@ -1453,6 +1542,12 @@ main() {
fi
fi

# Validate Claude Code CLI is available before starting
if ! validate_claude_command; then
log_status "ERROR" "Claude Code CLI not found: $CLAUDE_CODE_CMD"
exit 1
fi

log_status "SUCCESS" "🚀 Ralph loop starting with Claude Code"
log_status "INFO" "Max calls per hour: $MAX_CALLS_PER_HOUR"
log_status "INFO" "Logs: $LOG_DIR/ | Docs: $DOCS_DIR/ | Status: $STATUS_FILE"
Expand Down
13 changes: 13 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ if [[ -f "$LIB_DIR/enable_core.sh" ]]; then
generate_ralphrc "$PROJECT_NAME" "generic" "local" | sed 's/Generated by: ralph enable/Generated by: ralph-setup/' > .ralphrc
else
# Fallback: create minimal .ralphrc inline (same content as generate_ralphrc)
# Auto-detect Claude Code CLI command
_claude_cmd="claude"
if ! command -v claude &>/dev/null; then
if command -v npx &>/dev/null; then
_claude_cmd="npx @anthropic-ai/claude-code"
fi
fi
cat > .ralphrc << RALPHRCEOF
# .ralphrc - Ralph project configuration
# Generated by: ralph-setup
Expand All @@ -71,6 +78,12 @@ else
PROJECT_NAME="${PROJECT_NAME}"
PROJECT_TYPE="generic"

# Claude Code CLI command
# If "claude" is not in your PATH, set to your installation:
# "npx @anthropic-ai/claude-code" (uses npx, no global install needed)
# "/path/to/claude" (custom path)
CLAUDE_CODE_CMD="${_claude_cmd}"

# Loop settings
MAX_CALLS_PER_HOUR=100
CLAUDE_TIMEOUT_MINUTES=15
Expand Down
Loading