Claude Code Login Commands
Level 1 · Get started
How to sign in from a session or from your shell, and make a token for a CI job. Then the commands that show your account, plan, usage and costs.
Course contentsLesson 3 of 17
Level 1 · Get started
Level 2 · Inside a conversation
Level 3 · Parallel work and review
Level 4 · Setup and extensions
Level 5 · Scripts and servers
After this lesson you can
- Sign in with /login or claude auth login
- Check sign-in from a script by its exit code
- Make a one-year token for a CI job
11 mincovers 11 glossary entries
Worth reading first: Install, Update and Doctor
How to sign in, and check who you are signed in as
Claude Code needs an Anthropic account before it does any work. Inside a session, /login signs you in and /logout signs you out. From the shell, claude auth login does the same with no session open. A Claude plan is paid by the month. A Console account pays for what you use.
claude auth login takes three flags. --console signs in with a Console account, so use is billed there rather than to a plan. --sso sends you to your company's single sign-on. --email fills in your address. claude auth logout signs you out again.
claude auth status answers the question a script asks: am I signed in? It prints JSON, or plain text with --text. It ends with exit code 0 when you are signed in and 1 when you are not. Its authMethod field says how, such as claude.ai, api_key or oauth_token.
A Console account can also work with an API key, a long secret string, instead of a browser sign-in. A CI job has no browser at all. claude setup-token opens the browser once on your own computer. After you approve, it prints a token that lasts one year.
That token is saved nowhere, so copy it at once. Put it in the job's secret store as CLAUDE_CODE_OAUTH_TOKEN. It needs a Claude plan. Anyone who holds it can work as you for a year, so treat it like a password.
/status shows what is running right now. It opens the settings panel on its Status tab: your version, the model, the account and whether the link to Anthropic works. It runs at once, even in the middle of a reply. It is the first thing to check when work lands on the wrong account.
/usage shows what the session has cost and how close you are to your plan's limits. On a Claude plan it also breaks down what counts against them. /cost and /stats open the same view. /insights looks further back, with a web page report on your recent sessions on this computer.
Two account commands change things outside Claude Code. /upgrade opens the page where you move to a higher plan. /privacy-settings shows choices such as whether your chats may be used to train Claude. It is only there on personal Claude plans.
claude auth login --console
claude auth status --text
claude setup-token
# in the CI job's settings
export CLAUDE_CODE_OAUTH_TOKEN=your-tokenWorked example
Lucy's nightly job fails at 2 am
Lucy's CI job runs Claude Code every night and fails with a sign-in error. The runner has no browser to sign in with.
She runs claude setup-token on her laptop, approves it, and saves the token in the CI secret store. The job now starts with claude auth status, which ends with 0, and it runs for the next 12 months.
The words for this lesson11
Check yourself
How does a script check that Claude Code is signed in?
Finished this lesson?
Marking it complete also marks its 11 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.