Guide

How to Install Claude Code: npm Setup, Auth & First Run

Claude Code is Anthropic's official CLI coding agent. This guide covers the install commands Anthropic lists today — the native installer it recommends, Homebrew, WinGet and npm — both authentication paths (Claude plan or API key), your first run, and the common install failures. The commands were run against Claude Code v2.1.260 on 2026-09-04; install options, requirements and plan access were re-checked against Anthropic's setup docs on 2026-10-01.

By DK, Editor  ·  Last verified: 2026-09-04  · Claude Code v2.1.260 (installed and run 2026-09-04); install methods, system requirements and plan access re-checked against code.claude.com/docs/en/setup and npm (latest 2.1.286) on 2026-10-01  ·  How we test

Before you start

  • A supported system: macOS 13+, Windows 10 1809+ or Windows Server 2019+, Ubuntu 20.04+, Debian 10+ or Alpine Linux 3.19+, with 4 GB+ RAM (Anthropic's setup docs, checked 2026-10-01)
  • A Claude Pro, Max, Team or Enterprise plan, or a Console (API) account — Anthropic states the free Claude plan does not include Claude Code
  • A terminal: Bash or Zsh on macOS/Linux/WSL, or PowerShell or CMD on Windows
  • Node.js 22 or later only if you install with npm — the npm package has required it since v2.1.198 (check with: node --version). The native installer, Homebrew and WinGet do not need Node

Steps

  1. 01

    Install Claude Code — the native installer (what Anthropic recommends)

    Anthropic's setup page lists the native installer as the recommended method (checked 2026-10-01). It needs no Node.js, and native installs update themselves in the background. Pick the line for your shell; Homebrew and WinGet are the package-manager alternatives (those two do not auto-update). Open a new terminal window when it finishes.

    # macOS, Linux, WSL
    curl -fsSL https://claude.ai/install.sh | bash
    
    # Windows PowerShell
    irm https://claude.ai/install.ps1 | iex
    
    # Homebrew (macOS/Linux)
    brew install --cask claude-code
    
    # WinGet (Windows)
    winget install Anthropic.ClaudeCode
  2. 02

    Or install Claude Code with npm

    If you prefer npm, this is the command. Per Anthropic's docs the npm package installs the same native binary as the standalone installer, pulled in through a per-platform optional dependency, so your package manager must allow optional dependencies. In our 2026-09-04 run the postinstall step (install.cjs) took roughly 20 seconds. The -g flag puts the claude command in your global npm bin directory.

    npm install -g @anthropic-ai/claude-code
  3. 03

    Verify the install

    After install completes, confirm the binary is on your PATH by checking the version. If the command is not found, see the PATH troubleshooting section below.

    claude --version
  4. 04

    Authenticate — Option A: Anthropic account (Claude Pro / Max / Team)

    Run claude with no arguments to start the interactive shell. On first launch it will prompt you to authenticate. Choose the 'Login with Anthropic account' flow. This opens a browser window where you authorize Claude Code against your existing Claude Pro, Max, or Team subscription. Once authorized, account metadata is saved to ~/.claude.json and the OAuth token is stored in your OS keychain (under 'Claude Safe Storage'). Subsequent launches skip the browser step automatically. This is the recommended path if you already pay for Claude at claude.ai.

    claude
  5. 05

    Authenticate — Option B: ANTHROPIC_API_KEY

    If you prefer API key authentication (useful for CI, shared machines, or pay-per-token billing), set the environment variable before running. Export it in your shell profile (~/.zshrc, ~/.bashrc, etc.) to make it permanent. With ANTHROPIC_API_KEY set, Claude Code asks you once to approve the key instead of opening a browser (Anthropic's setup docs, checked 2026-10-01).

    export ANTHROPIC_API_KEY="sk-ant-..."
    claude
  6. 06

    Run Claude Code interactively

    With no arguments, claude opens a persistent interactive session. You can type multi-line prompts, ask it to edit files, run commands, and use slash commands inside the REPL. Type /help inside the session to see available slash commands. Press Ctrl+C or type /exit to quit.

    claude
  7. 07

    Run a one-shot prompt (non-interactive / scripting mode)

    For scripting, CI pipelines, or quick one-off tasks, pass the prompt directly. The -p flag (--print) runs the prompt without entering the interactive shell and prints the result to stdout. You can also pass a prompt as a bare positional argument for convenience.

    # Using the --print flag (non-interactive)
    claude -p "Explain what this repo does"
    
    # Or as a positional argument
    claude "List all TODO comments in src/"
  8. 08

    Run Claude Code inside your IDE

    Claude Code is a terminal tool — it runs in any integrated terminal. Open your IDE's built-in terminal (VS Code: Ctrl+`, Cursor: same), navigate to your project directory, and run claude. No IDE plugin is required for this. If you want an integrated panel instead, Anthropic also ships a VS Code extension and a JetBrains plugin. The agent reads and edits files directly from the working directory.

    # Navigate to your project first
    cd /path/to/your/project
    claude
  9. 09

    Persist your API key in your shell profile (optional but recommended)

    To avoid exporting the key every session when using API key auth, add the export line to your shell profile. Replace ~/.zshrc with ~/.bashrc if you use bash.

    echo 'export ANTHROPIC_API_KEY="sk-ant-..."' >> ~/.zshrc
    source ~/.zshrc

Troubleshooting

command not found: claude after npm install -g
npm's global bin directory is not in your PATH. Find it with: npm config get prefix — then append /bin to that path and add it to your PATH. Example for macOS/Linux: add export PATH="$(npm config get prefix)/bin:$PATH" to your ~/.zshrc or ~/.bashrc, then run source ~/.zshrc. On macOS with Homebrew-managed Node, the prefix is often /opt/homebrew.
npm EBADENGINE warning about Node >=22 during install
The floor moved: v2.1.183 declared Node >=18, and since v2.1.198 the npm package declares Node 22 or later. Per Anthropic's setup docs (checked 2026-10-01), on an older Node npm prints an EBADENGINE warning rather than failing — the install completes and claude still runs, because the package only links a native binary that does not use Node at runtime. To get rid of the warning, upgrade Node (nvm install --lts && nvm use --lts) or switch to the native installer, which does not need Node at all.
npm install fails with EACCES permission denied on global install
You are trying to write to a system-owned directory. The clean fix is to configure npm to use a user-writable prefix: mkdir -p ~/.npm-global && npm config set prefix ~/.npm-global, then add export PATH="$HOME/.npm-global/bin:$PATH" to your profile. Alternatively, use nvm which installs Node in your home directory and avoids this entirely. Do not use sudo npm install -g as it can corrupt permissions.
Authentication loop — browser opens but Claude Code never recognizes the login
This usually means the callback URL was blocked or the browser closed before the token was written. Try again in a browser that is not blocking redirects. If you are on a headless server or CI environment, switch to ANTHROPIC_API_KEY authentication instead — set the env var and run claude without the interactive auth flow.
MCP server shows as 'pending-approval' and tools are not available
Claude Code requires explicit approval of MCP servers defined in a project's .mcp.json file before it exposes their tools. When prompted inside the interactive session, choose to approve the server. If you accidentally rejected it, run claude mcp reset-project-choices inside the project directory, then restart claude to see the approval prompt again.

FAQ

Do I need a paid Claude subscription to use Claude Code?
Yes, or an API account. Anthropic's setup docs (checked 2026-10-01) say Claude Code requires a Pro, Max, Team, Enterprise or Console account, and that the free Claude plan does not include Claude Code. You can also run it through a third-party provider: Amazon Bedrock, Google Cloud's Agent Platform or Microsoft Foundry. Confirm current prices on claude.com.
Can I use Claude Code with AWS Bedrock or Google Vertex instead of the Anthropic API?
Yes. Anthropic's setup docs list Amazon Bedrock, Google Cloud's Agent Platform (Vertex AI) and Microsoft Foundry as supported third-party providers (checked 2026-10-01). Each uses its own credentials (AWS credentials, Google Cloud application default credentials, and so on) rather than ANTHROPIC_API_KEY. See the provider pages in Anthropic's Claude Code documentation for the exact environment variables.
Where does Claude Code store its configuration?
User-scoped account metadata is stored in ~/.claude.json. When you authenticate via Anthropic account login, the OAuth token itself is stored in your OS keychain (under 'Claude Safe Storage'), not in the JSON file. Project-level MCP server definitions are stored in a .mcp.json file in the project root. You can inspect ~/.claude.json and .mcp.json directly with any text editor.
Is Claude Code the same as the claude.ai web interface?
No. Claude Code is a separate terminal-based coding agent that reads and edits files on your local machine, runs shell commands, and operates as an agentic loop. The claude.ai web interface is a chat UI. Claude Code uses the same underlying models but is designed for software development workflows in your terminal or IDE.
How do I update Claude Code to a newer version?
It depends on how you installed it (Anthropic's setup docs, checked 2026-10-01). Native installs update themselves in the background, and claude update applies an update immediately. For npm, run npm install -g @anthropic-ai/claude-code@latest — Anthropic says to avoid npm update -g, which may not move you to the newest release. Homebrew: brew upgrade claude-code. WinGet: winget upgrade Anthropic.ClaudeCode. Check the installed version with claude --version.
Does Claude Code run on Windows, or do I need WSL?
Both work. Claude Code v2.1.260 publishes native Windows binaries — its package.json lists @anthropic-ai/claude-code-win32-x64 and @anthropic-ai/claude-code-win32-arm64 as optional dependencies alongside the macOS and Linux ones, so npm install -g @anthropic-ai/claude-code in PowerShell pulls a native build rather than needing a Linux layer. WSL is still fully supported and is what we would pick if your project already lives on a Linux filesystem, because the agent runs shell commands constantly and WSL avoids path and line-ending friction. The one combination to avoid is running Claude Code inside WSL while pointing it at a Windows-side npm installation under /mnt/c — Claude Code detects that setup and complains, and it is the most common cause of a broken install on Windows.
Claude Code is not working — how do I tell if it is me or if it is down?
Check the service before you touch your install: status.claude.com is the official status page for the Anthropic API that Claude Code calls. If it is green, the problem is local, and there are three checks that resolve most of it. First, claude --version — if the command is not found, it is a PATH problem, not a Claude Code problem (see the troubleshooting section above). Second, claude doctor, which checks the health of the installation and reads your settings files. Third, claude auth status, which tells you whether you are actually signed in; an expired login shows up as "Not logged in" the moment you send a prompt, not at startup. If all three are clean and it still fails, start it with claude --safe-mode, which disables CLAUDE.md, skills, plugins, hooks, MCP servers and custom commands — if it works in safe mode, one of your customisations is the cause.