Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,9 @@ PROJECT_TYPE="typescript"
CLAUDE_CODE_CMD="claude"
# CLAUDE_CODE_CMD="npx @anthropic-ai/claude-code" # Alternative: use npx

# Optional Anthropic-compatible API base URL override
# CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"

# Shell init file — source before running claude (useful for zsh/fish users
# whose PATH or env vars are only set in their shell's init file)
#RALPH_SHELL_INIT_FILE="~/.zshrc"
Expand Down
8 changes: 8 additions & 0 deletions ralph_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ _env_CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-}"
_env_CLAUDE_AUTO_UPDATE="${CLAUDE_AUTO_UPDATE:-}"
_env_CLAUDE_MODEL="${CLAUDE_MODEL:-}"
_env_CLAUDE_EFFORT="${CLAUDE_EFFORT:-}"
_env_CLAUDE_ANTHROPIC_BASE_URL="${CLAUDE_ANTHROPIC_BASE_URL:-}"
_env_RALPH_SHELL_INIT_FILE="${RALPH_SHELL_INIT_FILE:-}"
_env_ENABLE_NOTIFICATIONS="${ENABLE_NOTIFICATIONS:-}"
_env_ENABLE_BACKUP="${ENABLE_BACKUP:-}"
Expand Down Expand Up @@ -113,6 +114,7 @@ CLAUDE_AUTO_UPDATE="${CLAUDE_AUTO_UPDATE:-true}" # Auto-update Claude CLI at st
CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-claude}" # Claude Code CLI command (default: global install)
CLAUDE_MODEL="${CLAUDE_MODEL:-}" # Model override (e.g. claude-sonnet-4-6); empty = CLI default
CLAUDE_EFFORT="${CLAUDE_EFFORT:-}" # Effort level override (e.g. high, low); empty = CLI default
CLAUDE_ANTHROPIC_BASE_URL="${CLAUDE_ANTHROPIC_BASE_URL:-}" # Anthropic-compatible API base URL override; empty = CLI default
RALPH_SHELL_INIT_FILE="${RALPH_SHELL_INIT_FILE:-}" # Shell init file to source before running claude (e.g. ~/.zshrc)
DRY_RUN="${DRY_RUN:-false}" # Simulate loop without making actual Claude API calls
ENABLE_NOTIFICATIONS="${ENABLE_NOTIFICATIONS:-false}" # Enable desktop notifications; set true or use --notify flag
Expand Down Expand Up @@ -328,6 +330,7 @@ load_ralphrc() {
[[ -n "$_env_CLAUDE_AUTO_UPDATE" ]] && CLAUDE_AUTO_UPDATE="$_env_CLAUDE_AUTO_UPDATE"
[[ -n "$_env_CLAUDE_MODEL" ]] && CLAUDE_MODEL="$_env_CLAUDE_MODEL"
[[ -n "$_env_CLAUDE_EFFORT" ]] && CLAUDE_EFFORT="$_env_CLAUDE_EFFORT"
[[ -n "$_env_CLAUDE_ANTHROPIC_BASE_URL" ]] && CLAUDE_ANTHROPIC_BASE_URL="$_env_CLAUDE_ANTHROPIC_BASE_URL"
[[ -n "$_env_RALPH_SHELL_INIT_FILE" ]] && RALPH_SHELL_INIT_FILE="$_env_RALPH_SHELL_INIT_FILE"
[[ -n "$_env_ENABLE_NOTIFICATIONS" ]] && ENABLE_NOTIFICATIONS="$_env_ENABLE_NOTIFICATIONS"
[[ -n "$_env_ENABLE_BACKUP" ]] && ENABLE_BACKUP="$_env_ENABLE_BACKUP"
Expand Down Expand Up @@ -1559,6 +1562,11 @@ build_claude_command() {
CLAUDE_CMD_ARGS+=("--effort" "$CLAUDE_EFFORT")
fi

# Add Anthropic-compatible API base URL override (for custom providers)
if [[ -n "${CLAUDE_ANTHROPIC_BASE_URL:-}" ]]; then
CLAUDE_CMD_ARGS+=("--anthropic-base-url" "$CLAUDE_ANTHROPIC_BASE_URL")
fi

Comment on lines +1565 to +1569

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.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if the Claude CLI supports --anthropic-base-url
claude --help 2>&1 | grep -i "base-url\|anthropic" || echo "Flag not found in --help output"

Repository: frankbria/ralph-claude-code

Length of output: 197


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the relevant code path and any references to the env var/flag name.
rg -n "CLAUDE_ANTHROPIC_BASE_URL|anthropic-base-url|api-base-url|base-url" .

# Check the local Claude CLI help more directly for base-url-related options.
claude --help 2>&1 | sed -n '1,220p'

Repository: frankbria/ralph-claude-code

Length of output: 3100


🌐 Web query:

Claude Code CLI --anthropic-base-url option supported flag base url documentation

💡 Result:

Claude Code CLI does not provide a command-line flag named --anthropic-base-url [1][2]. Instead, custom API endpoints are configured exclusively via the ANTHROPIC_BASE_URL environment variable [3][4][5]. You can set this variable in your shell for a single session, as a persistent environment variable, or within the Claude Code settings file [4][5][6]. Configuration Methods: 1. Shell Environment (Temporary): export ANTHROPIC_BASE_URL=https://your-gateway.example.com export ANTHROPIC_AUTH_TOKEN=your-gateway-key 2. Settings File (Persistent): You can define the variable in your ~/.claude/settings.json file using an env block: { "env": { "ANTHROPIC_BASE_URL": "https://your-gateway.example.com", "ANTHROPIC_AUTH_TOKEN": "your-gateway-key" } } Key Details: - Purpose: ANTHROPIC_BASE_URL is used to point the CLI toward LLM gateways, corporate proxies, or local mock servers [4][5][6]. - Authentication: When using a custom base URL, you typically use ANTHROPIC_AUTH_TOKEN to provide the necessary authorization credentials instead of the standard ANTHROPIC_API_KEY [4][7]. - Priority: If both a shell export and a settings-file entry are present, the settings-file value generally takes precedence [4]. You can verify which URL is being used by running the /status command within the Claude Code CLI [4].

Citations:


Use ANTHROPIC_BASE_URL instead of --anthropic-base-url

Claude CLI doesn’t expose a --anthropic-base-url flag; custom endpoints need to be passed via ANTHROPIC_BASE_URL in the process environment (or settings file), otherwise custom-provider runs will fail at startup.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ralph_loop.sh` around lines 1565 - 1569, The Claude CLI base URL override is
being passed as an unsupported command-line flag, so update the custom-provider
handling in the shell logic around the CLAUDE_CMD_ARGS construction to use the
ANTHROPIC_BASE_URL process environment variable instead. Keep the existing
CLAUDE_ANTHROPIC_BASE_URL input, but export/map it into the environment before
launching Claude rather than appending "--anthropic-base-url" to the argv array,
so startup works with custom endpoints.

# Add output format flag
if [[ "$CLAUDE_OUTPUT_FORMAT" == "json" ]]; then
CLAUDE_CMD_ARGS+=("--output-format" "json")
Expand Down
4 changes: 4 additions & 0 deletions templates/ralphrc.template
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ CLAUDE_AUTO_UPDATE=true
# Minimum Claude CLI version required
CLAUDE_MIN_VERSION="2.0.76"

# Optional Anthropic-compatible API base URL override for custom providers
# Example: MiniMax Claude-compatible endpoint
# CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"

# Enable verbose logging
RALPH_VERBOSE=false

Expand Down
45 changes: 44 additions & 1 deletion tests/unit/test_cli_modern.bats
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ setup() {
_env_CLAUDE_CODE_CMD="${CLAUDE_CODE_CMD:-}"
_env_CLAUDE_MODEL="${CLAUDE_MODEL:-}"
_env_CLAUDE_EFFORT="${CLAUDE_EFFORT:-}"
_env_CLAUDE_ANTHROPIC_BASE_URL="${CLAUDE_ANTHROPIC_BASE_URL:-}"
_env_RALPH_SHELL_INIT_FILE="${RALPH_SHELL_INIT_FILE:-}"

load_ralphrc() {
Expand All @@ -202,6 +203,7 @@ setup() {
[[ -n "$_env_CLAUDE_CODE_CMD" ]] && CLAUDE_CODE_CMD="$_env_CLAUDE_CODE_CMD"
[[ -n "$_env_CLAUDE_MODEL" ]] && CLAUDE_MODEL="$_env_CLAUDE_MODEL"
[[ -n "$_env_CLAUDE_EFFORT" ]] && CLAUDE_EFFORT="$_env_CLAUDE_EFFORT"
[[ -n "$_env_CLAUDE_ANTHROPIC_BASE_URL" ]] && CLAUDE_ANTHROPIC_BASE_URL="$_env_CLAUDE_ANTHROPIC_BASE_URL"
[[ -n "$_env_RALPH_SHELL_INIT_FILE" ]] && RALPH_SHELL_INIT_FILE="$_env_RALPH_SHELL_INIT_FILE"
RALPHRC_LOADED=true
return 0
Expand Down Expand Up @@ -548,6 +550,11 @@ build_claude_command() {
CLAUDE_CMD_ARGS+=("--effort" "$CLAUDE_EFFORT")
fi

# Add Anthropic-compatible API base URL override
if [[ -n "${CLAUDE_ANTHROPIC_BASE_URL:-}" ]]; then
CLAUDE_CMD_ARGS+=("--anthropic-base-url" "$CLAUDE_ANTHROPIC_BASE_URL")
fi

# Add output format flag
if [[ "$CLAUDE_OUTPUT_FORMAT" == "json" ]]; then
CLAUDE_CMD_ARGS+=("--output-format" "json")
Expand Down Expand Up @@ -1937,6 +1944,17 @@ EOF
assert_equal "$CLAUDE_EFFORT" "high"
}

@test "CLAUDE_ANTHROPIC_BASE_URL from .ralphrc is loaded correctly" {
cat > "$TEST_DIR/.ralphrc" << 'EOF'
CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"
EOF
_env_CLAUDE_ANTHROPIC_BASE_URL=""
CLAUDE_ANTHROPIC_BASE_URL=""

load_ralphrc
assert_equal "$CLAUDE_ANTHROPIC_BASE_URL" "https://api.minimax.io/anthropic/v1"
}

@test "CLAUDE_MODEL env var takes precedence over .ralphrc" {
cat > "$TEST_DIR/.ralphrc" << 'EOF'
CLAUDE_MODEL="claude-sonnet-4-6"
Expand All @@ -1959,6 +1977,17 @@ EOF
assert_equal "$CLAUDE_EFFORT" "high"
}

@test "CLAUDE_ANTHROPIC_BASE_URL env var takes precedence over .ralphrc" {
cat > "$TEST_DIR/.ralphrc" << 'EOF'
CLAUDE_ANTHROPIC_BASE_URL="https://api.example.com/anthropic/v1"
EOF
_env_CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"
CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"

load_ralphrc
assert_equal "$CLAUDE_ANTHROPIC_BASE_URL" "https://api.minimax.io/anthropic/v1"
}

@test "build_claude_command includes --model flag when CLAUDE_MODEL is set" {
CLAUDE_MODEL="claude-sonnet-4-6"
CLAUDE_EFFORT=""
Expand All @@ -1981,15 +2010,29 @@ EOF
[[ "${CLAUDE_CMD_ARGS[*]}" == *"high"* ]]
}

@test "build_claude_command omits --model and --effort when not configured" {
@test "build_claude_command includes --anthropic-base-url flag when CLAUDE_ANTHROPIC_BASE_URL is set" {
CLAUDE_MODEL=""
CLAUDE_EFFORT=""
CLAUDE_ANTHROPIC_BASE_URL="https://api.minimax.io/anthropic/v1"
echo "test prompt" > "$TEST_DIR/PROMPT.md"

build_claude_command "$TEST_DIR/PROMPT.md" "" ""

[[ "${CLAUDE_CMD_ARGS[*]}" == *"--anthropic-base-url"* ]]
[[ "${CLAUDE_CMD_ARGS[*]}" == *"https://api.minimax.io/anthropic/v1"* ]]
}

@test "build_claude_command omits --model, --effort, and --anthropic-base-url when not configured" {
CLAUDE_MODEL=""
CLAUDE_EFFORT=""
CLAUDE_ANTHROPIC_BASE_URL=""
echo "test prompt" > "$TEST_DIR/PROMPT.md"

build_claude_command "$TEST_DIR/PROMPT.md" "" ""

[[ "${CLAUDE_CMD_ARGS[*]}" != *"--model"* ]]
[[ "${CLAUDE_CMD_ARGS[*]}" != *"--effort"* ]]
[[ "${CLAUDE_CMD_ARGS[*]}" != *"--anthropic-base-url"* ]]
}

# ==============================================================================
Expand Down