Claude Code on Carina
Claude Code is Anthropic’s command-line AI coding assistant. This guide covers getting an API key through Stanford’s AI API Gateway and running Claude Code on Carina.
Getting an API Key
- Request a key through the AI API Gateway service catalog item. Access is available to all Stanford faculty, staff, and students with a valid PTA.
- Your API key will be sent to you via secure email. Follow the setup and usage guidance linked from the AI API Gateway service page to retrieve your key.
- Copy the key somewhere safe.
See the AI API Gateway Rates page for current pricing.
Installing Claude Code
Claude Code is available as a module on Carina:
ml claude-code
Configuring Claude Code
Claude Code reads its connection to the AI API Gateway from ~/.claude/settings.json. Create the settings directory if it doesn’t already exist:
mkdir -p ~/.claude
Open (or create) the settings file:
nano ~/.claude/settings.json
Paste the following, replacing YOUR_AIAPI_KEY with the key you retrieved above:
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"env": {
"ANTHROPIC_BASE_URL": "https://aiapi-prod.stanford.edu",
"ANTHROPIC_AUTH_TOKEN": "YOUR_AIAPI_KEY",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}
Save the file (in nano: Ctrl+O, Enter, then Ctrl+X to exit), and confirm it looks right:
cat ~/.claude/settings.json
| Field | Description |
|---|---|
ANTHROPIC_BASE_URL |
The gateway’s root URL. Do not append /v1. |
ANTHROPIC_AUTH_TOKEN |
Your AI API Gateway key. |
CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS |
Prevents experimental/beta headers that can cause gateway errors. |
DISABLE_PROMPT_CACHING flag for environments where beta headers cause errors — add "DISABLE_PROMPT_CACHING": "1" to your env block if you run into prompt-caching-related errors).~/.claude/settings.json to a git repository, paste it into a shared script, or share it with others. Although the file is only readable by you, the key inside it is plaintext — anyone who gains access to your account can read it there.
Running Claude Code
Request an interactive session via Slurm’s srun command:
srun -p normal -n 1 --cpus-per-task=4 --pty bash
Once you’re on a compute node, load the module and navigate to your project directory:
ml claude-code
cd /path/to/your/project
claude
This starts an interactive Claude Code session in your terminal. See Claude Code’s documentation for usage details, slash commands, and configuration options.
Testing Your Connection
Once you’re on a compute node with Claude Code installed and configured, run a quick non-interactive prompt to confirm it can reach the gateway and authenticate:
claude -p "Say hello and name the model you're running as."
If that works, try it against a specific model to confirm routing works too:
claude --model claude-sonnet-5 -p "What model are you?"
If either command hangs, errors immediately, or returns an authentication failure, double-check ANTHROPIC_BASE_URL and ANTHROPIC_AUTH_TOKEN in ~/.claude/settings.json before opening a ticket.
Using Claude Code with OnDemand Apps
Want to use Claude Code inside VS Code, RStudio, JupyterLab, or MATLAB on Carina OnDemand? See Using Claude Code with OnDemand Apps.
Available Models
Pass a model name to Claude Code with the --model flag (for example, claude --model claude-sonnet-5) to use something other than the default.
claude --model claude-haiku-4-5
claude --model claude-sonnet-5
claude --model claude-sonnet-4-6
claude --model claude-4-5-sonnet
claude --model claude-opus-5
claude --model claude-opus-4-8
claude --model claude-opus-4-7
claude --model claude-opus-4-6