Docs for SCORPIOX CODE @ 77c49df

Using Claude Code CLI Subscription in SCORPIOX CODE

Claude Code CLI subscription via OAuth session login and local token daemon.

You have a Claude Code CLI subscription (a Claude Pro or Max plan, or a Claude Code seat) and you don't want to meter per-token against an Anthropic API key. You can use it directly in SCORPIOX CODE. Instead of billing API tokens, the Claude Code provider signs you in with the same OAuth session login the Claude Code CLI performs and sends every request to the Anthropic endpoint your subscription already pays for — wearing the same wire identity the CLI itself wears.

This page walks through the session login, where the token is stored and how it is refreshed automatically, the configuration keys behind PROVIDER=claude_code, multi-account setups with profiles (/profile and /use), how to drive a login without a TTY (machine mode), and how a direct subscription differs from standard API-key usage in the Anthropic provider.

Docs for SCORPIOX CODE @ 77c49df.


When to use this provider

ScenarioExample
You have a Claude / Claude Code subscriptionPro, Max, or a Claude Code seat you already pay for
You don't have (or don't want) an Anthropic API keyNo pay-per-token billing — requests draw on your subscription allowance
Headless / over SSHThe login is paste-code: approve in a browser on any device, paste the code back into the terminal
Driven by SCORPIO BOTThe login splits into separate --start / --finish commands with no open TTY — see Machine mode
Several Claude accountsOne named credential file per account, one profile per file, switch with /profile

If you are instead calling the Anthropic API with an API key (ANTHROPIC_API_KEY), that is the Anthropic provider (PROVIDER=anthropic) — a different billing model for the same models. See Claude Code provider vs. the Anthropic API-key provider below.


Step 1 — Sign in with the OAuth session flow

The login is the OAuth authorization-code flow with PKCE (Proof Key for Code Exchange) — the same flow the official Claude Code CLI performs, using the Claude Code client identity. SCORPIOX CODE generates the PKCE verifier and challenge for you, prints one authorization URL, and waits for you to paste the resulting authorization code back. It is deliberately SSH- and headless-friendly: no browser is required on the machine you run from.

scorpiox-claudecode-login

You will see something like this:

scorpiox-claudecode-login v...

Generating PKCE challenge...

Open this URL in your browser to authorize:

  https://claude.com/cai/oauth/authorize?code=true&response_type=code&...&code_challenge=...&code_challenge_method=S256

After logging in, paste the authorization code below.
Code: >

Do exactly what it says:

  1. Open the printed URL in a browser — on any device, wherever you are signed into Claude.
  2. Log in to your Claude account and approve the requested permissions.
  3. The browser lands on a Claude callback page. Copy the code shown there and paste it back into the terminal.

SCORPIOX CODE exchanges the code for an access token and a refresh token (the PKCE verifier proves the exchange came from the same terminal that started the flow) and saves both. On success you will see:

Login successful
  Saved to /home/you/.claude/.credentials.json
  Token expires in 86400s

A few things worth knowing about this flow:

Overwriting existing credentials

If a credential file already exists, the login refuses to clobber it:

Credentials already exist: /home/you/.claude/.credentials.json
Use --force to overwrite.

Pass --force to re-authorize deliberately and replace the stored token — for example after an account change, a plan change, or a refresh that keeps failing:

scorpiox-claudecode-login --force

Named accounts

By default the login writes ~/.claude/.credentials.json. To keep several accounts side by side, give each one a name:

scorpiox-claudecode-login --name personal   # -> ~/.claude/accounts/personal.json
scorpiox-claudecode-login --name work       # -> ~/.claude/accounts/work.json

Account names accept letters, digits, -, _ and . (up to 64 characters). A named file is only used by the provider when a profile points CLAUDE_CODE_CREDENTIALS_FILE at it — see Multi-account: profiles and switching.

Creating the claude_code profile

At the end of a successful login, SCORPIOX CODE offers to write a ready-made profile (the prompt is skipped when stdin is not a TTY):

Create 'claude_code' config profile?
  Will create: /home/you/.claude/scorpiox-env/claude_code.txt
  Contents:
    PROVIDER=claude_code
    CLAUDE_CODE_TOKEN_SOURCE=local
    MODEL=claude-opus-4-6

Create? [Y/n]

Say yes and the profile is written to ~/.claude/scorpiox-env/claude_code.txt, ready to activate with /profile claude_code. Decline and the tool prints the exact commands to create the file by hand instead.


Step 2 — Turn on the Claude Code provider

The provider switches on with PROVIDER=claude_code. For a personal subscription you also set CLAUDE_CODE_TOKEN_SOURCE=local, so the provider reads the credential file your login just wrote. That is the whole setup:

PROVIDER=claude_code
CLAUDE_CODE_TOKEN_SOURCE=local

Activate the profile — or put those keys in any cascade tier of scorpiox-env.txt, or export them as OS environment variables — and SCORPIOX CODE connects:

/profile claude_code      # activate this profile and persist it

You can also select the provider for a single run from the command line:

sx --provider claude_code -p 'explain this code'
sx --provider claude_code -m opus -p 'review this'

Configuration keys

All keys can live in any cascade tier of scorpiox-env.txt, in a named profile, or as OS environment variables — the highest tier that sets a key wins. See Configuration and Profiles for the full cascade and precedence rules.

KeyTypeDefaultDescription
PROVIDERchoice(unset)Set to claude_code to activate this provider.
CLAUDE_CODE_TOKEN_SOURCEchoicelocalWhere the OAuth token comes from: local, http, ssh, or tcp. Use local for a login you ran with scorpiox-claudecode-login.
CLAUDE_CODE_CREDENTIALS_FILEtext(empty)Override the local credential path (default ~/.claude/.credentials.json). Point it at a named account such as ~/.claude/accounts/work.json to pin a profile to one login.
MODELtextsonnetWhich model to run: a short alias (opus, sonnet, haiku) or a full model ID. See Choosing a model.
CLAUDE_CODE_API_URLtextapi.anthropic.comHost the provider calls. Domain only — the /v1/messages?beta=true path is appended automatically.
CLAUDE_CODE_PROXY_URLtextanthropic.scorpiox.netProxy host to route requests through instead of the direct endpoint. Used only when the proxy is enabled.
CLAUDE_CODE_PROXY_ENABLEDbool01 = send requests to CLAUDE_CODE_PROXY_URL instead of CLAUDE_CODE_API_URL.
CLAUDE_CODE_PROXY_STRICTbool01 = fail when the proxy is down. 0 = fall back to the direct endpoint for that request. See Proxy and endpoint overrides.
CLAUDE_CODE_CLI_VERSIONtext2.1.280CLI version reported in the request user-agent. The OS environment variable of the same name beats this value.
CLAUDE_CODE_REMOTE_URLtext(empty)Token endpoint, used only when CLAUDE_CODE_TOKEN_SOURCE=http.
TOKEN_HTTP_API_KEYtext(empty)Bearer key sent to that HTTP token endpoint, when it requires one.
CLAUDE_CODE_SSH_HOST / _PORT / _USER / _PASStext(empty)Used only when CLAUDE_CODE_TOKEN_SOURCE=ssh — fetch the token from a remote machine over SSH. Host and user are required in that mode.
TCP_HOST / TCP_PORT / TCP_API_KEY / TCP_UPSTREAMtextproxy.scorpiox.net / 9800 / (empty) / (empty)Used only when CLAUDE_CODE_TOKEN_SOURCE=tcp — fetch the token over a raw TCP socket. TCP_HOST accepts a comma-separated list for failover.
STREAMINGbool01 = stream server-sent events. See What a request looks like.
THINKING / THINKING_BUDGETbool / number1 / 10000Extended-thinking toggle and its token budget (clamped to 1,000–128,000).
TOOLSbool1Include the tool definitions so the agent can run commands and edit files.
USAGE_SPEED_ESTIMATEbool0Opt-in client-side speed figures in the status bar while streaming.

In the config editor (/config in a session, or scorpiox-config from a shell) the CLAUDE_CODE_* keys live in the Provider & Authentication section and appear once PROVIDER is claude_code. The remote-token keys are shown conditionally: CLAUDE_CODE_REMOTE_URL and TOKEN_HTTP_API_KEY when the source is http, the CLAUDE_CODE_SSH_* set when the source is ssh. CLAUDE_CODE_CREDENTIALS_FILE is honored everywhere but is not part of that editor's list — set it in a profile file or the environment.


Where the token lives

On login, SCORPIOX CODE writes the OAuth tokens to ~/.claude/.credentials.json under a claudeAiOauth section:

~/.claude/.credentials.json
  claudeAiOauth:
    accessToken    <- short-lived bearer token sent with every request
    refreshToken   <- what makes renewal possible without signing in again
    expiresAt      <- expiry timestamp in milliseconds
    scopes         <- the permissions the login was granted

No API key is involved, and no API key is ever written. With CLAUDE_CODE_TOKEN_SOURCE=local, every request reads the current access token from that file, so a refresh that happens outside the session is picked up on the next turn.

Treat that file as what it is: a live credential that can renew your account session. Do not commit it, do not copy it into shared dotfile repos, and do not loosen its permissions.


Token persistence and automatic refresh

The access token from the OAuth session is short-lived by design — but you do not manage it. SCORPIOX CODE handles the whole lifecycle:

Manual refresh

You can force the same renewal from a shell at any time:

scorpiox-claudecode-refreshtoken                       # refresh only if expired
scorpiox-claudecode-refreshtoken --force               # always refresh
scorpiox-claudecode-refreshtoken --credentials-file ~/.claude/accounts/work.json

The tool prints the current and new expiry times, backs up the credential file before touching it, and rewrites only the three OAuth fields — everything else in the file is preserved byte for byte. --verbose additionally prints the old and new token material to the terminal, which is occasionally useful for diagnostics and exactly as sensitive as it sounds; run it on a machine you trust.

As long as the refresh token in the credential file is intact, you generally sign in once. If you ever see an unauthorized or token-expired hint, the fix is almost always one of:

scorpiox-claudecode-refreshtoken --force   # token expired — renew it
scorpiox-claudecode-login --force          # refresh failed / account changed — re-login

Inspecting the resolved token

For diagnostics you can resolve the token exactly the way the provider does, without making a model request:

scorpiox-claudecode-fetchtoken -config --verbose

The tool prints one JSON line containing the access token and its expiry, and --verbose adds the cascade tiers it consulted to get there. It reads the same keys as the provider — CLAUDE_CODE_TOKEN_SOURCE and friends — so what it resolves is what a request would send. Note that, like --verbose above, it prints live credential material: use it for checks, not for logging.


Checking your subscription usage

The provider runs against the same usage windows the Claude Code CLI enforces. Check how full they are with:

scorpiox-claudecode-usage            # human-readable summary
scorpiox-claudecode-usage --json     # raw JSON

You get one row per active window — the 5-hour session window, the weekly window, weekly per-model windows (Opus, Sonnet, OAuth apps), and any others your plan exposes — each with its utilization percentage, the reset time in UTC and your local timezone, and a countdown to the reset. When your plan has an extra-usage allowance, its enabled state, utilization, and used-versus-limit spend are shown too. That is exactly what you want to know before kicking off a long autonomous run: whether the window will hold and when it turns over.

Inside a session, /usage runs the same tool and shows the result as Claude Usage when the Claude Code provider is active. In addition, the per-response 5h: and 7d: figures in the status bar come straight from the rate-limit headers Anthropic returns on this provider, so the live utilization is visible while you work — see Token Usage Observability.


Choosing a model

MODEL accepts either a short alias or a full Claude model ID. The aliases at this commit resolve to:

MODEL valueResolves to
(empty)claude-sonnet-4-6 (the provider default sonnet)
opusclaude-opus-4-6
sonnetclaude-sonnet-4-6
haikuclaude-haiku-4-5-20251001
any other valuepassed through as-is

Anything that is not one of the three aliases — a newer claude-* ID your account has access to, for example — is sent to the endpoint unchanged. That is how you run a model version the built-in defaults do not know about without editing anything.

Model overrides

Pin a specific version to each alias with the override keys:

When set, an override replaces the built-in ID for that alias — so MODEL=opus resolves to your pinned version instead of the default one. Full model IDs written directly in MODEL are never overridden; they pass through as-is. Leave an override empty to keep the built-in default.

Switch models at runtime without editing any file with the in-session /model command, or set a standing default in your profile. /model takes the same values as MODEL — aliases and full IDs both work. You can also pin a model for a single run with sx -m opus, or override any key for that run only with sx -e CLAUDE_CODE_TOKEN_SOURCE=local.

You can list everything the endpoint currently advertises with:

scorpiox-claudecode-models              # full model list, raw JSON
scorpiox-claudecode-models <model-id>   # one model's detail

What a request looks like

For each turn SCORPIOX CODE sends one Messages API request that is wire-compatible with the Claude Code CLI:

  1. Endpoint — https://api.anthropic.com/v1/messages?beta=true (or your proxy host, same path). Requests carry the Claude Code beta flags, including the OAuth beta and interleaved thinking.
  2. Identity — the access token as an OAuth bearer token, plus the CLI's own client headers: a claude-cli/<version> (external, cli) user-agent built from CLAUDE_CODE_CLI_VERSION, and the standard client metadata headers the CLI sends. This is what makes the request indistinguishable from the CLI you already use.
  3. System prompt — sent as two text blocks, each marked as ephemeral cache control so the provider can reuse the prefix between turns.
  4. Messages — the conversation, with consecutive same-role entries grouped, and a cache breakpoint on the last block of each role. A resumed-after-compaction conversation gets a synthetic user marker so the history stays valid.
  5. Thinking and tools — an extended-thinking block with THINKING_BUDGET tokens when THINKING=1, and the tool definitions when TOOLS=1.

Each request gets a five-minute timeout, so long agentic turns are not cut off mid-flight. The response comes back as content blocks with a stop reason and a usage object; token counts, cache read/write figures, and the rate-limit utilization are surfaced in the status bar and the session stats — see Token Usage Observability.

Streaming and speed estimates

STREAMING=0 (the default) sends one request and parses one complete response. STREAMING=1 asks for server-sent events instead; the response is parsed the same way either way, so the only practical difference is how the body is delivered. Pair streaming with the opt-in speed estimate to get live prompt and generation rates in the status bar:

STREAMING=1
USAGE_SPEED_ESTIMATE=1

Estimates include network latency and wear a tilde (~pp / ~tg) in the status bar to say so.


Proxy and endpoint overrides

Two keys decide where requests actually go, and they interact:

Failover behavior is what CLAUDE_CODE_PROXY_STRICT is for:

SettingBehavior when the proxy is unreachable
CLAUDE_CODE_PROXY_STRICT=0 (default)That request is retried once against the direct endpoint, and the proxy is kept for subsequent requests
CLAUDE_CODE_PROXY_STRICT=1The request fails — no silent fall-back to direct egress

A typical setup for a network where Anthropic is reachable only through the proxy:

PROVIDER=claude_code
CLAUDE_CODE_TOKEN_SOURCE=local
CLAUDE_CODE_PROXY_ENABLED=1
CLAUDE_CODE_PROXY_URL=anthropic.scorpiox.net
CLAUDE_CODE_PROXY_STRICT=1

Remote token sources: http, ssh, tcp

local is all a personal subscription needs. The other three sources exist so that one credential can serve a whole fleet — a build box, a container, or a machine that should never hold the credential file itself:

SourceWhere the token comes fromKeys that matter
local~/.claude/.credentials.json (or CLAUDE_CODE_CREDENTIALS_FILE)none extra
httpAn HTTP endpoint returning the token JSONCLAUDE_CODE_REMOTE_URL, optional TOKEN_HTTP_API_KEY
sshAnother machine's credential file, read over SSHCLAUDE_CODE_SSH_HOST, _USER, optional _PORT, _PASS
tcpA token server over a raw TCP socketTCP_HOST (comma-separated for failover), TCP_PORT, optional TCP_API_KEY, optional TCP_UPSTREAM

The token server speaks a small request/response protocol (SXV1 ... TYPE=claude) and answers with the same credential JSON the local file holds, so the provider consumes all four sources identically. In http, ssh, and tcp modes the token is re-fetched on every request and no refresh is performed locally — the endpoint owning the credential is responsible for keeping it valid.


Multi-account: profiles and switching

Many people have more than one Claude account (personal plus work, for example). The Claude Code provider supports that in two layers: named credential files and named config profiles.

Save more than one login

scorpiox-claudecode-login --name personal   # -> ~/.claude/accounts/personal.json
scorpiox-claudecode-login --name work       # -> ~/.claude/accounts/work.json

Bind each login to a profile

Now make one profile per account and point CLAUDE_CODE_CREDENTIALS_FILE at the right file, so the profile always uses that account:

# ~/.claude/scorpiox-env/claude-personal.txt
PROVIDER=claude_code
CLAUDE_CODE_TOKEN_SOURCE=local
CLAUDE_CODE_CREDENTIALS_FILE=~/.claude/accounts/personal.json
MODEL=claude-opus-4-6
# ~/.claude/scorpiox-env/claude-work.txt
PROVIDER=claude_code
CLAUDE_CODE_TOKEN_SOURCE=local
CLAUDE_CODE_CREDENTIALS_FILE=~/.claude/accounts/work.json
MODEL=claude-sonnet-4-6

Profiles can live at any tier — ~/.claude/scorpiox-env/<name>.txt for your own machine, .scorpiox/scorpiox-env/<name>.txt committed to a project so the whole team gets the same account and model.

Switch accounts and models in-session

With those profiles in place, switching accounts is just switching profiles — no re-login, no restart:

/profile claude-work      # persistent — writes ACTIVE_PROFILE, survives restarts
/use    claude-personal   # session-only — gone when the session ends
/profile                  # list profiles and the active one (opens the picker where available)
/profile off              # deactivate and drop back to the base cascade

/profile and /use both trigger a live provider reload, so the new account and model take effect immediately. If the switch cannot complete, SCORPIOX CODE reverts to the previous profile — you are never left half-switched. The difference is scope: /profile <name> persists (it writes ACTIVE_PROFILE, so it survives restarts), while /use <name> is session-only (an in-memory switch that disappears when the session ends). See Configuration and Profiles for the full switching semantics.

Inspect what is actually configured

Use scorpiox-config to see resolved values and where each one comes from (which cascade tier won):

scorpiox-config            # open the interactive config editor
scorpiox-config --verbose  # print key values with their source tier

--verbose reports CLAUDE_CODE_TOKEN_SOURCE, CLAUDE_CODE_API_URL, the proxy keys, MODEL, and ACTIVE_PROFILE, so you can confirm you are pointed at the account and endpoint you expect before a long run.


Machine mode (no TTY)

Sometimes you cannot hold a terminal open between "here is the URL" and "paste the code" — a background agent, a CI step, or SCORPIO BOT's provider flow. The login ships an additive machine mode: the same PKCE flow split into separate, non-interactive commands that print a single line of JSON to stdout. Tokens are never printed — only status. Running the tool with no machine flag is the original interactive behaviour, unchanged.

FlagWhat it does
--statusReport the login state for this node as a single JSON line (add --name for a named account).
--startBegin the login: returns the auth_url, and keeps the PKCE state for 10 minutes.
--finish <code\|->Exchange the pasted code for tokens (- reads the code from stdin).
--cancelDrop a pending login.
--create-profileWith --finish: also write the claude_code profile, without prompting.
--name <account>Operate on a named account instead of the default credential file.

A typical machine-mode login:

# 1. Start — prints the URL to open
scorpiox-claudecode-login --start
# {"ok":true,"provider":"claudecode","flow":"paste_code","auth_url":"https://claude.com/cai/oauth/authorize?...","expires_in":600,"hint":"Sign in, then paste the code shown on the callback page."}

# 2. Open that URL in any browser, sign in, approve, copy the code.

# 3. Finish — exchange the code
scorpiox-claudecode-login --finish "$CODE" --create-profile
# {"ok":true,"provider":"claudecode","logged_in":true,"path":"/home/you/.claude/.credentials.json","expires_in":86400,"profile":"claude_code","profile_created":true}

Things worth knowing:


Claude Code provider vs. the Anthropic API-key provider

It is easy to confuse the two because they both run Anthropic models. Here is the difference:

Claude Code provider (this page)Anthropic provider (PROVIDER=anthropic)
PROVIDER valueclaude_codeanthropic
AuthenticationOAuth session login (scorpiox-claudecode-login), bearer token refreshed automaticallyANTHROPIC_API_KEY sent as x-api-key
BillingYour Claude / Claude Code subscription allowance (5-hour + weekly windows)Pay-per-token API usage on your key
What you needA Claude Pro / Max / Claude Code seatAn Anthropic API key and console account
Token lifecycleShort-lived access token + stored refresh token, renewed for youStatic API key, nothing to refresh
Endpointapi.anthropic.com/v1/messages?beta=true (or the SCORPIOX proxy)Any Anthropic-compatible endpoint you name
Redirectable to your own URLProxy host only — the Claude Code surface stays the Claude Code surfaceFully — custom, zai, and antigravity modes
Wire formatFull Claude Code CLI emulation (user-agent, client metadata headers, beta flags)Plain Messages API, no CLI-emulating headers
Usage visibilitySubscription windows: 5h: / 7d: in the status bar, plus the usage toolToken counts only — no subscription headers

Rule of thumb: a Claude / Claude Code seat, use claude_code. An API key or a custom endpoint, use anthropic.

Both providers reach Anthropic's Messages API and share the same request builder, but the credentials, headers, and billing are different. Only the Anthropic provider can be pointed at a non-Anthropic URL.


Gotchas


Quick reference

GoalWhat to set
Personal subscription, first loginscorpiox-claudecode-login, then PROVIDER=claude_code + CLAUDE_CODE_TOKEN_SOURCE=local
Re-authenticatescorpiox-claudecode-login --force
A second accountscorpiox-claudecode-login --name work + a profile pinning CLAUDE_CODE_CREDENTIALS_FILE
Renew the token by handscorpiox-claudecode-refreshtoken --force
See the subscription windowsscorpiox-claudecode-usage, or /usage in-session
List the endpoint's modelsscorpiox-claudecode-models
Pick a modelMODEL=opus (or sonnet / haiku / a full claude-* ID), or /model in-session
Pin a model versionCLAUDE_MODEL_OPUS_ID_OVERRIDE (and the Sonnet / Haiku keys)
Route through the proxyCLAUDE_CODE_PROXY_ENABLED=1 (+ CLAUDE_CODE_PROXY_STRICT=1 to fail loudly)
Fleet token sourceCLAUDE_CODE_TOKEN_SOURCE=tcp (or http / ssh) with its keys
Login from a scriptscorpiox-claudecode-login --start then --finish <code>
One-off run overridesx --provider claude_code -e CLAUDE_CODE_TOKEN_SOURCE=local -p "..."

Sign in once, let the refresh loop keep the token alive, and pick the profile that points at the account and model you want.


See also