HOW-TO · DEV

How to install Claude Code CLI and authenticate with your Anthropic account

intermediate15 minBy Fredoline Eruo
Target environment
Ubuntu 24.04 · Claude Code 1.xmacOS 14.x · Claude Code 1.x
PREREQUISITES

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

  1. Open a terminal session and verify Node.js and npm are present by running node --version and npm --version. Both commands should return version numbers without errors.
  2. Install the Claude Code package globally using the command npm install -g @anthropic-ai/claude-code.
  3. Confirm the installation completed successfully by running claude --version. A version string such as 1.x.x should appear.
  4. Initiate the authentication flow by running claude auth login. This command opens the default system browser to an Anthropic OAuth page.
  5. In the browser window, sign in with the Anthropic account credentials and grant permission for the CLI to access the account.
  6. After approval, the browser displays a success confirmation. Return to the terminal.
  7. The CLI automatically detects the completed OAuth handshake and stores the token in ~/.config/claude-code/credentials.json.
  8. As an alternative for server or CI environments, set the ANTHROPIC_API_KEY environment variable to a valid API key instead of using the browser-based login.
  9. 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

  1. Node.js version too old — The install command fails or the CLI exits immediately. Confirm node --version returns 18 or higher. Use a version manager like nvm to upgrade if needed.

  2. 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 login and proceed immediately.

  3. 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.

  4. npm global bin directory not in PATH — After installation, running claude may produce "command not found". Ensure the npm global bin path is included in $PATH, or use npx claudecode as a fallback.

Related guides

  • Navigate and edit files using Claude Code's interactive mode
  • Configure Claude Code's forbidden tool restrictions for safe usage