Claude Code can run through CBorg on three kinds of models. Choose one:
- Claude Code with Claude Models ($$$) – Anthropic’s Claude models, billed per token
- Claude Code with CBorg Models (no cost) – the on-prem
cborg-coder-maxmodel, not billed - Claude Code with Cloud Budget Models ($) – CBorg’s low-cost
cloud-budgetmodel, billed per token at a small fraction of the price of Claude
Claude Code with Claude Models ($$$)
API Cost Optimization
Claude models are expensive to run. Sustained heavy use of Claude Code can exceed $100 per day for a single user, and inefficient usage patterns push token consumption higher still. 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 an 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: summarize the conversation at 200K input tokens (see section 7)
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000
# 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: Launch from a Shell Function
Instead of exporting the variables from step 1, you can set them only for the Claude Code process. Your shell environment stays unchanged, and plain claude keeps whatever configuration it had. Add this function to your ~/.zshrc or ~/.bashrc:
# Claude Code on CBorg with Claude models -- launches claude with CBorg API auth.
# Env vars are process-scoped (not exported) so the parent shell is untouched.
cborg-claude-paid() {
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-paid in place of claude. Arguments are passed through, so cborg-claude-paid --continue resumes your most recent conversation.
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. Recommended: Cap Auto-Compact at 200K Tokens
Current Claude models accept up to 1M input tokens per request, and by default Claude Code lets the conversation grow until it nearly fills that window before summarizing it. Every turn re-reads the conversation so far, so input cost scales with the size of the conversation even with prompt caching – the most expensive requests of a session are the ones just before the limit. Capping the conversation at 200K tokens keeps each request’s input at roughly a fifth of that size, which is still ample room for most tasks:
export CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000
When the conversation reaches this boundary, Claude Code summarizes it and continues with a compact history. The value must be a plain integer between 100000 and 1000000 and applies to every model in the session. One caveat: the context-usage percentage shown in the status line still measures against the model’s full window, so with this setting it no longer indicates when compaction will run – watch the token count instead.
Claude Code with CBorg Models (no cost)
Claude Code can run entirely on cborg-coder-max, a model hosted by Berkeley Lab. Requests to on-prem models are not billed. Every model slot is pinned to cborg-coder-max, so Claude Code never calls a paid Claude model.
1. Configure MCP Servers
Create ~/.claude/cborg-mcp.json:
{
"mcpServers": {
"tavily": {
"type": "http",
"url": "https://api.cborg.lbl.gov/mcp/tavily",
"headers": { "Authorization": "Bearer ${CBORG_API_KEY}" }
},
"context7": {
"type": "http",
"url": "https://api.cborg.lbl.gov/mcp/context7",
"headers": { "Authorization": "Bearer ${CBORG_API_KEY}" }
},
"valency": {
"type": "http",
"url": "https://api.cborg.lbl.gov/mcp/valency",
"headers": { "Authorization": "Bearer ${CBORG_API_KEY}" }
}
}
}
Claude Code substitutes ${CBORG_API_KEY} from its own process environment, so the variable must be exported, not merely set. If it is missing – set in ~/.zshrc without export, or absent from the environment that launched Claude Code – no substitution happens and the literal text ${CBORG_API_KEY} is sent as the key. All three MCP servers then fail with 401, and the only warning is in claude mcp list or /mcp. The launchers below check for this and stop with an error instead of starting.
2. Create a Launcher Function
Add this function to your ~/.zshrc or ~/.bashrc:
# Claude Code running on CBORG's cborg-coder-max (GLM 5.3); every model slot is pinned to it.
# The model accepts 917,504 tokens in, but auto-compact is capped at 200K input
# tokens: model performance is better at shorter context lengths, prefills are
# faster, and long conversations hold GPU capacity on the shared on-prem cluster.
# Output is capped at 32K tokens -- ample for Claude Code responses, while the
# full 128K ceiling let a looping generation tie up the response for minutes.
# MCP: Tavily (web search) and Context7 (library docs) are on. Valency is off unless
# CBORG_VALENCY=1 is set, because its 38 tools would crowd the context.
# The built-in WebSearch runs on Anthropic's servers and fails through CBORG, so it is blocked.
# --disallowedTools accepts several values, so --strict-mcp-config follows it to end the
# list before "$@"; otherwise a prompt argument would be read as a tool name.
cborg-claude() {
# Fail fast when the key is absent. Claude Code sends the unexpanded
# ${CBORG_API_KEY} text if the variable is missing, which produces a 401 from
# every MCP server with no clear cause in the session.
: "${CBORG_API_KEY:?CBORG_API_KEY is not exported}"
local -a disallowed=(WebSearch)
[[ -n $CBORG_VALENCY ]] || disallowed+=(mcp__valency)
ANTHROPIC_AUTH_TOKEN=$CBORG_API_KEY \
ANTHROPIC_BASE_URL=https://api.cborg.lbl.gov \
ANTHROPIC_MODEL=cborg-coder-max \
ANTHROPIC_DEFAULT_OPUS_MODEL=cborg-coder-max \
ANTHROPIC_DEFAULT_SONNET_MODEL=cborg-coder-max \
ANTHROPIC_DEFAULT_HAIKU_MODEL=cborg-coder-max \
ANTHROPIC_DEFAULT_FABLE_MODEL=cborg-coder-max \
CLAUDE_CODE_SUBAGENT_MODEL=cborg-coder-max \
CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 \
CLAUDE_CODE_MAX_OUTPUT_TOKENS=32000 \
DISABLE_NON_ESSENTIAL_MODEL_CALLS=1 \
DISABLE_TELEMETRY=1 \
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 \
CLAUDE_CODE_NO_FLICKER=1 \
claude \
--mcp-config ~/.claude/cborg-mcp.json \
--disallowedTools "${disallowed[@]}" \
--strict-mcp-config \
"$@"
}
3. Run cborg-claude
Restart your shell, then run cborg-claude in place of claude. Arguments are passed through, so cborg-claude --continue resumes your most recent conversation. To enable the Valency MCP server for a session, run CBORG_VALENCY=1 cborg-claude.
--strict-mcp-config means only the servers in ~/.claude/cborg-mcp.json are loaded; MCP servers from your other Claude Code configuration are ignored in these sessions.
Claude Code with Cloud Budget Models ($)
cloud-budget is a CBorg alias for a low-cost cloud model, selected for cost efficiency (see Cloud Auto-Model Selection). Pinning every Claude Code model slot to it keeps sessions inexpensive. CBorg may change the model behind the alias as better-value models appear; see the models page for current pricing.
1. Configure MCP Servers
Create ~/.claude/cborg-mcp.json as described in step 1 of the no-cost setup. Both launchers share it.
2. Create a Launcher Function
Add this function to your ~/.zshrc or ~/.bashrc:
# Claude Code running on CBORG's cloud-budget alias; every model slot is pinned to it.
# Set CBORG_CLOUD_MODEL=cloud-standard to run the whole session on the next tier up.
# Auto-compact is capped at 200K input tokens to bound per-request cost -- the
# backing model accepts up to ~922K, and input is billed per token.
# MCP and tool blocking match cborg-claude: Valency is off unless CBORG_VALENCY=1 is set,
# and the built-in WebSearch, which runs on Anthropic's servers, is blocked.
# --strict-mcp-config follows --disallowedTools to end its value list before "$@".
cborg-claude-budget() {
# See cborg-claude: an unexported key reaches the MCP servers as literal text.
: "${CBORG_API_KEY:?CBORG_API_KEY is not exported}"
local model=${CBORG_CLOUD_MODEL:-cloud-budget}
local -a disallowed=(WebSearch)
[[ -n $CBORG_VALENCY ]] || disallowed+=(mcp__valency)
ANTHROPIC_AUTH_TOKEN=$CBORG_API_KEY \
ANTHROPIC_BASE_URL=https://api.cborg.lbl.gov \
ANTHROPIC_MODEL=$model \
ANTHROPIC_DEFAULT_OPUS_MODEL=$model \
ANTHROPIC_DEFAULT_SONNET_MODEL=$model \
ANTHROPIC_DEFAULT_HAIKU_MODEL=$model \
ANTHROPIC_DEFAULT_FABLE_MODEL=$model \
CLAUDE_CODE_SUBAGENT_MODEL=$model \
CLAUDE_CODE_AUTO_COMPACT_WINDOW=200000 \
CLAUDE_CODE_MAX_OUTPUT_TOKENS=32000 \
DISABLE_NON_ESSENTIAL_MODEL_CALLS=1 \
DISABLE_TELEMETRY=1 \
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 \
CLAUDE_CODE_NO_FLICKER=1 \
claude \
--mcp-config ~/.claude/cborg-mcp.json \
--disallowedTools "${disallowed[@]}" \
--strict-mcp-config \
"$@"
}
3. Run cborg-claude-budget
Restart your shell, then run cborg-claude-budget in place of claude. Arguments are passed through, so cborg-claude-budget --continue resumes your most recent conversation.
4. Optional: Move Up to cloud-standard
If cloud-budget falls short on a task – for example, repeated failed edits or missed steps in a multi-file change – switch to cloud-standard, the next tier up:
- Mid-session: run
/model cloud-standardinside Claude Code. This changes the main conversation model; subagents stay oncloud-budget. - Whole session: start with
CBORG_CLOUD_MODEL=cloud-standard cborg-claude-budget. Every model slot, including subagents, usescloud-standard.
Currently both tiers use the same model and per-token price; cloud-standard runs it at a higher reasoning effort. It spends more reasoning tokens per turn, so each turn costs more and takes longer.