How to install Claude Code CLI and authenticate with your Anthropic account
Node.js 18+ installed, npm package manager available, Anthropic account with API access
What this does
This guide walks through installing the Claude Code command-line interface via npm and completing the OAuth authentication flow that links the CLI tool to an Anthropic account. After setup, the CLI can make API calls on behalf of the authenticated user, enabling code editing, review, and automation workflows directly from the terminal.
Steps
- Open a terminal session and verify Node.js and npm are present by running
node --versionandnpm --version. Both commands should return version numbers without errors. - Install the Claude Code package globally using the command
npm install -g @anthropic-ai/claude-code. - Confirm the installation completed successfully by running
claude --version. A version string such as1.x.xshould appear. - Initiate the authentication flow by running
claude auth login. This command opens the default system browser to an Anthropic OAuth page. - In the browser window, sign in with the Anthropic account credentials and grant permission for the CLI to access the account.
- After approval, the browser displays a success confirmation. Return to the terminal.
- The CLI automatically detects the completed OAuth handshake and stores the token in
~/.config/claude-code/credentials.json. - As an alternative for server or CI environments, set the
ANTHROPIC_API_KEYenvironment variable to a valid API key instead of using the browser-based login. - Verify authentication by running
claude auth status. The output confirms whether the CLI is currently authenticated and which account is active.
Verification
claude auth status
Expected output:
Authenticated as: [email protected]
Account ID: org-xxxxxxxxxxxx
Status: active
Common failures
Node.js version too old — The install command fails or the CLI exits immediately. Confirm
node --versionreturns 18 or higher. Use a version manager likenvmto upgrade if needed.Browser authentication times out — The OAuth flow requires completing the sign-in within a few minutes. If the browser tab is left idle, the token may not be exchanged. Re-run
claude auth loginand proceed immediately.Invalid or expired API key in environment variable — When using
ANTHROPIC_API_KEY, an incorrect key produces an authentication error on every command. Verify the key matches the one shown in the Anthropic dashboard under API keys.npm global bin directory not in PATH — After installation, running
claudemay produce "command not found". Ensure the npm global bin path is included in$PATH, or usenpx claudecodeas a fallback.
Related guides
- Navigate and edit files using Claude Code's interactive mode
- Configure Claude Code's forbidden tool restrictions for safe usage