The claude-litellm Shell Script¶
Recommended pattern for running Claude Code (and any future CLI tool that speaks Anthropic's API
format) against Navigator. The script reads .env, exports the correct environment variables, and
hands off to the underlying binary.
The Script¶
Save this as claude-litellm somewhere on your PATH (typically ~/.local/bin/claude-litellm),
then chmod +x to make it executable:
#!/usr/bin/env bash
# Run Claude Code routed through the LiteLLM proxy defined in ./.env
# Expects ANTHROPIC_API_KEY and LITELLM_BASE_URL in .env.
set -euo pipefail
if [ ! -f .env ]; then
echo "claude-litellm: no .env in $(pwd)" >&2
exit 1
fi
set -a
# shellcheck disable=SC1091
source .env
set +a
: "${LITELLM_BASE_URL:?LITELLM_BASE_URL missing from .env}"
: "${ANTHROPIC_API_KEY:?ANTHROPIC_API_KEY missing from .env}"
export ANTHROPIC_BASE_URL="$LITELLM_BASE_URL"
export ANTHROPIC_AUTH_TOKEN="$ANTHROPIC_API_KEY"
unset ANTHROPIC_API_KEY
exec claude "$@"
What Each Part Does¶
set -euo pipefailmakes the script fail loudly on any error, unset variable, or pipe failure. Prevents silent-fail scenarios where the wrong key gets used.- The
.envexistence check keeps the script from accidentally running with system-level env vars if the local.envis missing. set -a/source/set +atemporarily marks all sourced variables for export. Standard pattern for loading.envfiles in bash.- The two
${VAR:?}assertions require both variables to exist and be non-empty. If either is missing, the script fails with a clear message. ANTHROPIC_BASE_URLis what Claude Code reads to decide which host to talk to. Setting it here routes traffic through Navigator instead ofapi.anthropic.com.ANTHROPIC_AUTH_TOKEN(notANTHROPIC_API_KEY) is the correct variable for a proxy key. Claude Code treatsANTHROPIC_API_KEYas a real Anthropic key and validates it against Anthropic's format.ANTHROPIC_AUTH_TOKENis passed through as a bearer token, which is what Navigator expects.unset ANTHROPIC_API_KEYremoves the raw key from the child process's environment. OnlyANTHROPIC_AUTH_TOKENis exported to Claude Code.exec claude "$@"replaces the shell process with Claude Code, passing through any arguments.execis used so signals propagate correctly.