Install and Configure Claude Code CLI on Windows: A Setup Guide

    This guide explains how to install and configure Anthropic's Claude Code CLI on Windows 10 or Windows 11. It covers Node.js setup, npm global directory and PATH configuration, installation and verification, first launch, subscription and API account authorization, and workspace trust checks. By following the steps, you can run the `claude` command from any project directory and complete account authorization.

    Scope and Prerequisites

    This guide uses Claude Code, Anthropic’s command-line coding tool, as an example. It can read project code, answer questions, modify files, and execute commands in a terminal. You should have basic command-line experience, use Windows 10 or Windows 11, and have a Claude subscription account or an Anthropic API account.

    After completing the steps in this guide, you will have a claude command that can run in any project directory and will have completed account authorization. Other similar tools follow similar installation logic, but refer to their official documentation for exact commands.

    1. Install the Node.js Runtime

    Claude Code depends on Node.js. Node.js is a JavaScript runtime, and installing it also includes the npm package manager. Node.js itself does not provide a code execution sandbox; it only provides the runtime environment.

    1. Go to https://nodejs.org and download the LTS (Long Term Support) .msi installer. LTS versions are more reliable for stability and compatibility in everyday development.
    2. Run the installer. It is recommended to choose a non-system drive for the installation path, such as D:\nodejs. This reduces the impact of C: drive space usage on the system.
    3. In the installation wizard, make sure “Add to PATH” is checked. This option writes Node.js and npm to the system PATH so that any terminal can recognize the node and npm commands.
    4. Click “Next” until the installation is complete.

    Claude Code has a minimum Node.js version requirement. Refer to the version stated in the official documentation.

    2. Verify the Basic Environment

    After installation, verify that the environment is working.

    1. Open a normal-privilege PowerShell or Command Prompt window. Administrator privileges are not required.
    2. Run the following commands:
    1. node -v
    2. npm -v
    1. If both commands output version numbers, the environment is configured successfully.

    If you see “is not recognized as an internal or external command,” close all terminal windows and reopen them. If it still fails, check whether the system environment variable Path includes the Node.js installation directory, such as D:\nodejs\.

    3. Configure the npm Global Directory and Registry

    Globally installed tools are placed in npm’s global directory. By default, Windows places this directory under Program Files, and writing to it requires administrator privileges. To avoid running the terminal as administrator, change the global directory to a directory under your user profile.

    1. Create the directory and set the npm global path. Replace the username with your Windows username:
    1. mkdir C:\Users\YourUsername\.npm-global
    2. npm config set prefix "C:\Users\YourUsername\.npm-global"
    1. Open “Edit system environment variables” and add C:\Users\YourUsername\.npm-global to the user environment variable Path. Save the change and reopen the terminal.

    If downloads are slow or connection attempts time out, first check the current registry:

    1. npm config get registry

    If you have an available proxy, you can also configure npm to use it. Use the port required by your proxy software:

    1. npm config set proxy http://127.0.0.1:7890
    2. npm config set https-proxy http://127.0.0.1:7890

    Mirror synchronization may be delayed. If you encounter a “package not found” error, restore the official registry:

    1. npm config set registry https://registry.npmjs.org/

    4. Install Claude Code and Verify It

    Run the global installation command:

    1. npm install -g @anthropic-ai/claude-code

    After installation, verify it:

    1. claude --version
    2. where claude

    The first command outputs the version number, and the second command shows the path to the executable. This indicates a successful installation.

    If the installation log contains ERR!, first copy the key information from the first few lines. If the issue is a dependency conflict, you can uninstall and reinstall:

    1. npm uninstall -g @anthropic-ai/claude-code
    2. npm install -g @anthropic-ai/claude-code

    Anthropic may also change the recommended installation method. Refer to the current official documentation at https://docs.anthropic.com/en/docs/claude-code/overview. If the page path changes, use the navigation on the Anthropic website.

    5. First Launch and Terminal Theme

    Run claude in any directory. On first launch, an initialization wizard appears. Use the up and down arrow keys to select a terminal theme, then press Enter to confirm.

    The theme only affects display. If reading logs is difficult in daily use, choose a higher-contrast theme to help locate error messages and code differences quickly.

    At this point, do not continue in a default directory such as C:\Users\YourUsername. The authorization steps are covered in Section 6.

    6. Account Authorization

    After initialization, the tool asks you to choose a login method. The differences between the two options are as follows:

    Item Subscription account API account
    Best for Individual developers using it interactively day to day Teams, enterprises, and scenarios requiring automated calls
    Billing Monthly or annual subscription plan Billed by actual Token usage
    Usage limits Subject to plan usage limits Subject to account quota and rate limits
    Team sharing Not convenient for sharing quota among multiple people Different keys can be assigned to different projects
    Pipeline integration Not suitable for unattended automation tasks Suitable for CI/CD pipelines

    Plan prices and quotas may change according to official policy. Check the official pricing page before purchasing.

    Subscription Account Login

    1. In the claude session, select the subscription account login method.
    2. The tool opens the Anthropic official authorization page in your default browser.
    3. Sign in to your account in the browser and confirm authorization, then close the page.
    4. Return to the terminal. A successful login message indicates completion.

    This flow is based on the OAuth 2.0 standard. Your account password is entered only on the official page, and the terminal tool receives an access token rather than your password.

    Tokens and login credentials are stored under your local user directory. Note the following:

    • Do not copy, screenshot, or paste the contents of these credential files.
    • Do not commit directories containing credentials to a Git repository or send them to others.
    • On a computer you no longer use, run /logout in the claude session to sign out.
    • Check authorized devices in your account security settings and revoke authorizations you no longer use.

    API Account Configuration

    1. Create an API Key in the Anthropic console.
    2. Do not write the key into code, configuration files, or Git repositories. It is recommended to set a user environment variable through the Windows graphical interface to avoid leaving the key in command history.
    3. If you need to set it from the command line, run the following command and then reopen the terminal:
    1. setx ANTHROPIC_API_KEY "your-key"

    To roll back, delete ANTHROPIC_API_KEY in “Edit environment variables for your account” and revoke the key in the console.

    7. Bind a Workspace and Review Trust Permissions

    The tool can only read files in the startup directory and its subdirectories, so the workspace you choose determines what it can see.

    The correct order is to enter the project directory first, then start the tool:

    1. cd D:\projects\my-app
    2. claude

    When you run it in a directory for the first time, the tool asks whether to trust the files in that directory. Verify the displayed path first, and confirm only after you are sure it is the project you want the tool to read. If the path is C:\Users\YourUsername or another default user directory, do not continue; switch to the intended project directory first.