How to create and use a one-year Claude Code login token with setup-token
claude setup-token creates an OAuth token that lasts one year. It's meant for CI pipelines, scripts and other places where you can't sign in through a browser.
- Run it in a terminal. It opens the same browser approval flow as
/login, and the token prints to the terminal once you approve.
claude setup-token
- The token isn't saved anywhere. Copy it right away into the environment variable wherever you want to authenticate.
export CLAUDE_CODE_OAUTH_TOKEN=your-token
It requires a Pro, Max, Team or Enterprise subscription, and usage counts against that plan. The token can only make model requests, so it can't open Remote Control sessions or fetch claude.ai connectors. MCP servers you configure locally still work. --bare doesn't read this variable, so authenticate with ANTHROPIC_API_KEY or apiKeyHelper there instead.
If ANTHROPIC_API_KEY, ANTHROPIC_AUTH_TOKEN or apiKeyHelper is also set, that credential wins. Running /login while the variable is set switches only the current session to the new login; new sessions read the variable again. Posts on X suggest using it in place of your normal login, but you lose the features above, and a leaked token lets someone send requests on your subscription for a year, so keep it out of your repository.
Sources
Get notified when a new tip lands
Tip alerts only go out in the app. Install it and turn notifications on.