fix(llm): support ANTHROPIC_API_KEY as fallback in environment and shell RC resolution

Author: DevCop95Created Sep 17, 2026Updated Sep 18, 2026

OpenCodeReview Version

v1.12.4

Operating System

Windows / Linux / macOS

Installation Method

npm (global) / Built from source

LLM Provider

Anthropic (Claude)

Bug Description

When running ocr review with Anthropic credentials configured via environment variables (without ~/.opencodereview/config.json), OCR fails with:

Error: resolve LLM endpoint: no valid LLM endpoint configured; one of OCR_LLM_URL/OCR_LLM_TOKEN/OCR_LLM_MODEL, ~/.opencodereview/config.json, or ANTHROPIC_BASE_URL/ANTHROPIC_AUTH_TOKEN/ANTHROPIC_MODEL must be set

In internal/llm/resolver.go:

  1. tryCCEnv and parseShellRC only check for ANTHROPIC_AUTH_TOKEN and ignore ANTHROPIC_API_KEY, even though ANTHROPIC_API_KEY is the standard variable used across the Anthropic SDK, Claude ecosystem, and even in OCR's own internal/llm/providers.go (EnvVar: "ANTHROPIC_API_KEY").
  2. tryCCEnv strictly hardcodes AuthHeader: "authorization". When ANTHROPIC_API_KEY is used, the header should be x-api-key.
  3. tryCCEnv and parseShellRC require ANTHROPIC_BASE_URL to be explicitly set. For official Anthropic API usage, ANTHROPIC_BASE_URL is omitted and should default to https://api.anthropic.com.

Steps to Reproduce

  1. Set ANTHROPIC_API_KEY="sk-..." and ANTHROPIC_MODEL="claude-opus-4-6" (or proxy ANTHROPIC_BASE_URL). Do not set ANTHROPIC_AUTH_TOKEN.
  2. Ensure no ~/.opencodereview/config.json exists.
  3. Run ocr review.
  4. Observe the error: resolve LLM endpoint: no valid LLM endpoint configured; one of ... must be set.

Expected Behavior

tryCCEnv and parseShellRC should fall back to ANTHROPIC_API_KEY when ANTHROPIC_AUTH_TOKEN is unset, default baseURL to https://api.anthropic.com if omitted, and use x-api-key auth header when authenticating with ANTHROPIC_API_KEY.

Proposed Fix

In internal/llm/resolver.go:

  • In tryCCEnv: fall back to ANTHROPIC_API_KEY when ANTHROPIC_AUTH_TOKEN is unset, set authHeader = "x-api-key", and default baseURL = "https://api.anthropic.com".
  • In parseShellRC: parse ANTHROPIC_API_KEY exports and default baseURL = "https://api.anthropic.com".
  • Unit tests added in resolver_norm_test.go and resolver_shellrc_test.go covering fallback, precedence, and default URL. All tests pass with go test ./internal/llm.

Linked Pull Request: #1375 (Complete fix, unit tests, CLA signed, and CI checks passing).

Source: alibaba/open-code-review