claude setup-token creates a long-lived OAuth token for your Claude subscription. You usually export it as CLAUDE_CODE_OAUTH_TOKEN, which puts the token in every agent’s environment. With OneCLI, you store the token once in the gateway instead. Agents call api.anthropic.com as usual, and the gateway adds the token to each request.
What you will set up
- A Claude subscription token stored as an Anthropic secret in OneCLI
- Claude Code running through the OneCLI gateway with
onecli run -- claude - Requests to
api.anthropic.comthat carry your token, without the token in the agent’s environment
Before you start
- A Claude Pro, Max, Team, or Enterprise plan. The free plan doesn’t include Claude Code, so it can’t create a token.
- Claude Code installed. Check with
claude --version. - A running OneCLI instance. For a local one, run:
10255.
Steps
1
Generate the token
Run:A browser window opens. Sign in to the Claude account that has your plan and approve. The terminal prints a token that starts with
sk-ant-oat. Copy all of it, on one line. The token is valid for one year, and the command doesn’t save it anywhere.2
Store it in OneCLI
In the dashboard, open your agent’s Models page, click Add LLM key, and choose Anthropic. Paste the token into Secret value and click Add Secret.OneCLI sees the
sk-ant-oat prefix and injects the token as Authorization: Bearer {token}. API keys go in the x-api-key header instead. See Anthropic for both options.3
Remove the token from your shell
If you exported the token before, remove it so it stays only in OneCLI:Also delete any matching
export lines from ~/.zshrc or ~/.bashrc.4
Run Claude Code through the gateway
Sign the CLI in with your OneCLI API key from the dashboard, then start Claude Code:You’ll see
onecli: gateway connected. Starting claude.... onecli run sets the proxy and CA certificate and removes ANTHROPIC_API_KEY from the environment. On each request to api.anthropic.com, the gateway replaces the Authorization header with your stored token. See Coding agents for all onecli run options.Use the token in other agents
Any agent whose traffic goes through the gateway gets the same token on Anthropic requests:- Containers and custom agents: use the Node.js SDK to apply the proxy settings.
- Claude Code without the CLI wrapper: install the Claude Code plugin.
- Limit which agents can use the secret with agent access and rules.
FAQ
What does claude setup-token do?
What does claude setup-token do?
It runs the same browser sign-in as
/login and prints a one-year OAuth token for your Claude subscription. Usage counts against your plan, not API billing.Why store it in OneCLI instead of CLAUDE_CODE_OAUTH_TOKEN?
Why store it in OneCLI instead of CLAUDE_CODE_OAUTH_TOKEN?
An environment variable is readable by the agent and by every process it starts. In OneCLI, the token stays in the gateway, and you can revoke or rotate it in one place.
What happens when the token expires?
What happens when the token expires?
Anthropic rejects requests and the key shows Key rejected on the Models page. Run
claude setup-token again and update the secret with the pencil icon.Can I use an API key instead?
Can I use an API key instead?
Yes. Paste a Claude Console key (
sk-ant-api...) into the same field. OneCLI injects it as x-api-key. See Anthropic.