API Cost Optimization
Claude models can be very expensive to operate, however, many optimizations exist that can substantially reduce the cost of using these models.
According to Anthropic, the average cost of using ClaudeCode is $6 per day. However, incorrect usage patterns can cause token utilization to be higher. Common issues include:
- Having too many MCP servers
- Over-use of CLAUDE.md instead of skills
- Not using language-aware code intelligence plugins
- Not clearing context between tasks
- Using a overpowered model for the task
A comprehensive overview is available here: https://code.claude.com/docs/en/costs
1. Set Environment Variables
Set the following variables in your environment:
# Set authorization and base URL
export ANTHROPIC_AUTH_TOKEN=$CBORG_API_KEY
export ANTHROPIC_BASE_URL=https://api.cborg.lbl.gov
# Recommended setting
export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
# Recommended setting
export DISABLE_TELEMETRY=1
# Recommended setting for compatibility
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
# Recommended setting to reduce model throttling
# Higher max output tokens can be used but may cause prompts to be rejected with "too many tokens" error
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=8192
# Recommended setting to suppress terminal flicker
export CLAUDE_CODE_NO_FLICKER=1
Note: Model selection variables (ANTHROPIC_MODEL, ANTHROPIC_DEFAULT_OPUS_MODEL, ANTHROPIC_DEFAULT_SONNET_MODEL, ANTHROPIC_DEFAULT_HAIKU_MODEL, CLAUDE_CODE_SUBAGENT_MODEL) are not required to use Claude models, and setting them is not recommended. Claude Code selects current Claude models on its own. Setting these variables pins specific model versions that must be updated by hand when new models are released, and Claude Code may treat the pinned names as unsupported third-party models. To switch models during a session, use the /model command inside Claude Code.
2. Verify Environment Variables
Restart your shell and verify that the environment variables are now present:
env | grep ANTHROPIC
3. Start Claude Code
Now start Claude Code in your project directory:
cd my-project
claude
4. Optional: Install VS Code Extension
If you are a VS Code user, install the “Claude Code for VSCode” extension. When claude is run through the VS Code terminal, it will use VS Code to display highlighted diffs for approval.
5. Optional: Use CBorg as a Backup Provider
If you normally use Claude Code with a Claude Pro, Max, or Team subscription, you can keep that as your default and launch Claude Code against CBorg only when needed – for example, when your subscription usage limit is reached.
Instead of exporting the variables from step 1, add this function to your ~/.zshrc or ~/.bashrc:
# Claude Code on CBorg -- launches claude with CBorg API auth and model routing.
# Env vars are process-scoped (not exported) so the parent shell is untouched.
cborg-claude() {
ANTHROPIC_AUTH_TOKEN=$CBORG_API_KEY \
ANTHROPIC_BASE_URL=https://api.cborg.lbl.gov \
DISABLE_NON_ESSENTIAL_MODEL_CALLS=1 \
DISABLE_TELEMETRY=1 \
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 \
CLAUDE_CODE_NO_FLICKER=1 \
claude "$@"
}
Restart your shell, then run cborg-claude in place of claude. Plain claude continues to use your subscription. Arguments are passed through, so cborg-claude --continue resumes your most recent conversation on CBorg.
6. Optional: One-Hour Prompt Cache
Claude Code caches your conversation so that each new request re-reads it at a small fraction of the normal input price. By default this cache expires after 5 minutes without a request. You can extend it to 1 hour:
export CLAUDE_CODE_PROMPT_CACHE_TTL=1h
For most users this increases cost. Writing to the 1-hour cache costs 2x the normal input price, compared with 1.25x for the 5-minute cache. While Claude Code is working it sends requests every few seconds, which keeps the 5-minute cache alive on its own – so the 1-hour setting usually just makes every cache write more expensive. In an analysis of one week of CBorg Claude Code traffic (September 2026), switching everyone to the 1-hour cache would have raised Claude Code costs by about 7%, and roughly 4 out of 5 users would have paid more.
The 1-hour cache only saves money if you regularly leave a session idle for 5 to 60 minutes and then continue it – for example, reading and reviewing results between prompts, or rotating between several sessions. Users with that pattern saved up to about 30%. If you are unsure, keep the default.
7. Optional: Run Claude Code with Gemini Flash
Set the following variables in your environment:
# Set authorization and base URL
export ANTHROPIC_AUTH_TOKEN=$CBORG_API_KEY
export ANTHROPIC_BASE_URL=https://api.cborg.lbl.gov
# Model selection -- using aliases to latest version of each model
export ANTHROPIC_DEFAULT_HAIKU_MODEL=gemini-flash-lite
export ANTHROPIC_DEFAULT_SONNET_MODEL=gemini-flash
export ANTHROPIC_DEFAULT_OPUS_MODEL=gemini-flash-high
# Default conversation model
export ANTHROPIC_MODEL=gemini-flash
# Default subagent model
export CLAUDE_CODE_SUBAGENT_MODEL=gemini-flash-lite
# Recommended setting
export DISABLE_NON_ESSENTIAL_MODEL_CALLS=1
# Recommended setting
export DISABLE_TELEMETRY=1
# Recommended setting for compatibility
export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1
# Recommended setting to reduce model throttling
# Higher max output tokens can be used but may cause prompts to be rejected with "too many tokens" error
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=8192
# Recommended setting to suppress terminal flicker
export CLAUDE_CODE_NO_FLICKER=1