Run Claude Code in the cloud with your own API key

Anthropic's cloud sessions and Remote Control only work with a claude.ai subscription. If you pay per token with your own API key or a gateway, you need a different setup—here's how it works.

What the official cloud options don't support

According to Anthropic's documentation:

  • Remote Control — "API keys are not supported." It also stops working when ANTHROPIC_BASE_URL points anywhere other than api.anthropic.com, and your own computer has to stay on.
  • Cloud sessions (Claude Code on the web) — require signing in with a claude.ai account and "aren't available through third-party providers." API keys set in the cloud environment don't override your subscription.

So if you use an Anthropic Console key, a company gateway, OpenRouter, or another Anthropic-compatible provider, the official cloud features are off the table. The CLI itself works fine with all of them—it just needs somewhere to run.

How Claude Code picks up your key

Anthropic API keyANTHROPIC_API_KEYSent as the x-api-key header. Used instead of your subscription when set.
Gateway / relay tokenANTHROPIC_AUTH_TOKENSent as a Bearer token. Anthropic recommends it when you're unsure which one a gateway expects.
EndpointANTHROPIC_BASE_URLWhere requests go. Leave unset for Anthropic's own API.
Model mappingANTHROPIC_DEFAULT_*_MODELMap the opus, sonnet, and haiku aliases to the model IDs your provider offers.

Setup on any Linux server

  1. Install Claude Code

    Follow Anthropic's install guide on the server, or use a machine that already has it.

  2. Add your credentials to settings

    Put them under env in ~/.claude/settings.json so they apply no matter how claude is launched.

  3. Keep it running

    Start sessions inside tmux so they survive disconnects, and secure remote access to the box.

  4. Verify

    Run /status inside Claude Code to confirm the base URL and credential it's actually using.

~/.claude/settings.json
{
  "env": {
    "ANTHROPIC_API_KEY": "sk-ant-..."
  }
}

For a gateway or relay, use ANTHROPIC_BASE_URL plus ANTHROPIC_AUTH_TOKEN instead. Never put keys in a project's committed .claude/settings.json.

The shortcut: AlwaysAgent

AlwaysAgent hands you a dedicated US Linux server with Claude Code and Codex preinstalled and a browser workspace on top. Paste your key, base URL, or relay in settings and start a session.

  • Your keys stay on your own server. We never proxy your model calls or add a markup.
  • Close your laptop and the task keeps running; check in from your phone.
  • Use an Anthropic key, OpenRouter, a relay, or your claude.ai login—switch per session.

FAQ

Does Claude Code on the web support API keys?
No. Anthropic's docs state cloud sessions require a claude.ai account and aren't available through third-party providers. Use a server you control if you want to pay per token.
Should I use ANTHROPIC_API_KEY or ANTHROPIC_AUTH_TOKEN?
Use ANTHROPIC_API_KEY for an Anthropic Console key. For gateways and relays, use ANTHROPIC_AUTH_TOKEN unless the provider says it expects an x-api-key header.
Will my API key override my Claude subscription?
Yes. When a key or gateway token is set, Claude Code uses it and bills per token, even if you're logged in. Unset it to go back to your subscription.

Your own server, your own key

AlwaysAgent gives you a dedicated Linux server with Claude Code and Codex preinstalled. Paste your key in settings and start from any browser.

Try it for $0.05/h →