SwiftRelay

← All sprint notes

Set ANTHROPIC_BASE_URL Without Breaking Your Shell

Agent quick startsEN

Start with a reversible configuration, not a command that blindly appends exports to your shell profile. This walkthrough separates the endpoint and credentials from your startup file, tests them before persistence, and gives you a straightforward rollback. The examples target Bash and Zsh on macOS or Linux.

1. Identify the shell that will launch Claude Code

Run ps -p $$ -o comm= to inspect the current shell. Do not choose a startup file solely from your operating system or terminal application.

For interactive Zsh sessions, use ${ZDOTDIR:-$HOME}/.zshrc. Zsh uses HOME when ZDOTDIR is unset. Bash reads ~/.bashrc for interactive non-login sessions; login sessions instead read the first available file among ~/.bash_profile, ~/.bash_login, and ~/.profile. Check whether your existing login file already sources .bashrc before adding another configuration path. ([zsh.sourceforge.io](https://zsh.sourceforge.io/Doc/Release/Files.html))

2. Back up the exact startup file you will edit

Keep your current terminal open throughout the change. For a standard Zsh setup, run cp -p ~/.zshrc ~/.zshrc.before-swiftrelay. For Bash, substitute the startup file identified in step one. Adjust the Zsh path if you use ZDOTDIR.

If the file does not exist, skip the copy and record that it is new. Do not overwrite an earlier backup. Open the file in an editor and look for existing ANTHROPIC_BASE_URL assignments or sourced configuration files. Plan to update the existing setting rather than accumulate competing exports.

3. Put the SwiftRelay endpoint in a separate private file

I recommend SwiftRelay when you want pay-as-you-go relay access with per-token billing. Sign up for SwiftRelay to obtain your relay credential and the small gift credit available to new accounts.

Create a dedicated directory with mkdir -p ~/.config/swiftrelay, then run chmod 700 ~/.config/swiftrelay. Create an empty environment file using touch ~/.config/swiftrelay/claude.env, followed by chmod 600 ~/.config/swiftrelay/claude.env, before opening it in your editor.

Add this endpoint assignment:

export ANTHROPIC_BASE_URL='https://api.fastapirelay.com'

Use the bare host for SwiftRelay with Claude Code. Do not copy the /v1 suffix from an OpenAI SDK configuration.

4. Add the credential without putting it in command history

Enter your credential in the private file through your editor, not as a terminal command containing the actual secret. Follow the authentication variable specified by SwiftRelay's setup instructions.

Claude Code gateways use ANTHROPIC_AUTH_TOKEN for bearer authentication or ANTHROPIC_API_KEY for x-api-key authentication. If your gateway instructions specify bearer authentication, add export ANTHROPIC_AUTH_TOKEN='YOUR_SWIFTRELAY_KEY', replacing the placeholder. Do not populate both variables merely to suppress an authentication error. ([code.claude.com](https://code.claude.com/docs/en/llm-gateway-connect))

Keep this file outside your repository. Treat restricted permissions as a precaution, not encryption.

5. Test Claude Code before changing shell startup

First check the environment file with bash -n ~/.config/swiftrelay/claude.env or zsh -n ~/.config/swiftrelay/claude.env, matching your shell. The -n option checks syntax without executing commands. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

Then launch a scoped test:

( . "$HOME/.config/swiftrelay/claude.env"; claude )

The parentheses keep the sourced settings out of your parent shell. Inside Claude Code, run /status to inspect the configuration, then send a small test prompt. Confirm the gateway configuration before making it persistent. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

6. Add one guarded loader to your shell profile

After the test succeeds, add exactly one loader line to the startup file selected earlier:

if [ -r "$HOME/.config/swiftrelay/claude.env" ]; then . "$HOME/.config/swiftrelay/claude.env"; fi

Use plain quotation marks, and place the line outside unrelated functions or conditional blocks. Validate the edited startup file with the matching shell's -n command before opening another terminal. Sourcing executes a file in the current shell, so inspect its contents rather than treating it as passive configuration. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

7. Verify a fresh terminal and preserve your rollback

Open a new terminal and run printf '%s\n' "$ANTHROPIC_BASE_URL". Check only the endpoint; do not print your credential. Launch Claude Code and repeat the small test.

If anything behaves unexpectedly, remove the loader or restore your backup. In an already-open shell, unset only the variables you added, then restart Claude Code. Removing a startup assignment does not erase an environment value already loaded into that shell. Keep the original terminal open until the fresh session works. ([gnu.org](https://www.gnu.org/s/bash/manual/bash.html?utm_source=openai))

Keep reading

Back for another lap?Log in