Claude Code on Windows: Installation and Connecting to an Anthropic-Compatible Model Provider

    Learn how to install Claude Code on Windows 11 with PowerShell, configure an Anthropic-compatible model provider, and verify the connection. This guide covers Node.js setup, npm registry configuration, temporary and persistent environment variables, and troubleshooting installation, authentication, network, and proxy issues.

    1. Scope and Prerequisites

    Command-line AI coding tools can read project structures, modify files, and run test commands directly from a terminal. Unlike IDE extensions, they do not depend on a particular editor and can be launched from any project directory.

    This guide uses Anthropic’s official Claude Code on Windows 11 with PowerShell. The general installation workflow is similar for other npm-distributed command-line tools, although package names and environment variables will differ.

    The connection examples use a third-party model provider that offers an Anthropic-compatible API, including providers based in China. Check the provider’s documentation for availability in your region and the required connection settings.

    Before you begin, prepare:

    1. An internet-connected Windows computer with administrator privileges or permission to write to your user directory.
    2. An account with an Anthropic-compatible model provider and an API key.
    3. Approximately 30 minutes to complete the setup.

    2. Install Node.js and Configure the npm Registry

    2.1 Install Node.js

    For the npm installation workflow covered here, use Node.js 18 or later. Download an LTS installer from the official Node.js website, run it, and keep the default options. These options add Node.js to your system PATH.

    After installation, close all open terminals and launch a new PowerShell window. Run:

    1. node -v
    2. npm -v

    Both commands should return version numbers. The output of node -v should be v18 or later.

    If either command is not recognized, the terminal may still be using the previous environment settings. Close it and open a new window.

    If you need to switch between multiple Node.js versions, you can use nvm-windows instead of repeatedly reinstalling Node.js.

    2.2 Choose an npm Registry

    The default npm registry is appropriate for most users outside China. In mainland China, downloads from the default registry may be slow or time out. npmmirror is a commonly used regional alternative.

    If that mirror is appropriate for your network environment, configure it with:

    1. npm config set registry https://registry.npmmirror.com
    2. npm config get registry

    The second command should return:

    1. https://registry.npmmirror.com/

    If it still shows the official registry, check whether an .npmrc file is overriding your configuration.

    To use or restore the official registry, run:

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

    The purpose of changing registries is to improve download access, not to select a different version of Claude Code. Never store model-provider API keys in npm configuration files.

    3. Install Claude Code Globally and Verify It

    3.1 Run the Global Installation

    The -g flag installs the package globally so that its command can be called from any directory:

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

    Installation typically takes one to two minutes. Once it finishes, check the version:

    1. claude --version

    Output such as 2.x.x (Claude Code) indicates that the command is available. The exact version changes with releases; the important check is that a version number appears.

    If installation fails with an EACCES or EPERM permission error, first check the global installation directory:

    1. npm config get prefix

    On Windows, the default directory is usually %APPDATA%\npm. If it is not writable, using nvm-windows can help keep the global installation directory within your user directory, avoiding the need to run the terminal as an administrator.

    3.2 Troubleshoot an Unrecognized Command

    If Windows reports that claude is not recognized, or PowerShell cannot find the term, the global installation directory may be missing from PATH.

    Run these commands in order:

    1. npm root -g
    2. npm config get prefix
    3. Get-Command claude

    The directory returned by npm config get prefix should contain claude.cmd.

    If that file exists but Get-Command cannot find it, add the directory to your user PATH:

    1. Open Settings > System > About > Advanced system settings > Environment Variables.
    2. Under user variables, select Path.
    3. Add the directory returned by npm config get prefix.
    4. Close and reopen the terminal.

    4. Connect an Anthropic-Compatible Model Provider

    4.1 Collect the Connection Details

    You need three values from your provider:

    Setting Purpose Where to find it
    Base URL The provider’s Anthropic-compatible API endpoint The relevant API documentation
    API key The credential used to authenticate requests The provider’s key-management console
    Model name The identifier of the model you want to use The provider’s model list

    When creating a key, use a minimally privileged subaccount or project key where available, and set a monthly usage limit in the provider’s console.

    A key may be shown in full only once, when it is created. Store it securely. Do not take screenshots of it or paste it into chat logs or code repositories.

    4.2 Set Variables for the Current PowerShell Window

    Replace the placeholders below with the values supplied by your provider:

    1. $env:ANTHROPIC_BASE_URL = "<provider-compatible-api-url>"
    2. $env:ANTHROPIC_AUTH_TOKEN = "<your-api-key>"
    3. $env:ANTHROPIC_MODEL = "<provider-model-name>"

    These settings apply only to the current terminal session. Closing the window removes them, making this approach useful for temporary testing.

    If you use Command Prompt rather than PowerShell, the syntax is set ANTHROPIC_BASE_URL=.... Command Prompt treats every character after the equals sign—including trailing spaces—as part of the value. Do not add unintended spaces.

    4.3 Persist the Configuration

    To make the variables available in future terminal sessions, use setx to save them at the user level:

    1. setx ANTHROPIC_BASE_URL "<provider-compatible-api-url>"
    2. setx ANTHROPIC_AUTH_TOKEN "<your-api-key>"
    3. setx ANTHROPIC_MODEL "<provider-model-name>"

    setx does not update the current terminal. Open a new window to load the saved values.

    It also stores the values as plaintext in the user environment section of the Windows registry. This approach is therefore more appropriate for a personal computer than a shared one. On shared machines, prefer temporary settings and clear them when finished.

    You can also add these three user variables manually in the Environment Variables dialog.

    Avoid storing keys in files inside your project directory. If you do use a project-level configuration file for these settings, add it to .gitignore to prevent accidental commits.

    4.4 Test the Connection

    If you used persistent settings, open a new terminal. If you used temporary settings, stay in the window where you set them.

    First, confirm that the Base URL is available:

    1. echo $env:ANTHROPIC_BASE_URL

    Then run a non-interactive test. The -p flag requests a single response and exits:

    1. claude -p "Introduce yourself in one sentence."

    A normal response indicates that the basic connection is working.

    Next, open a project directory and run:

    1. claude

    Ask it to explain some code to check that it can read the project files.

    5. Troubleshooting

    Issue 1: npm Installation Stalls or Times Out

    Check the configured registry:

    1. npm config get registry

    Confirm that it is the registry you intended to use. If you need a regional mirror, revisit Section 2.2.

    If installation still fails with the intended registry configured, clear the cache and retry:

    1. npm cache clean --force
    2. npm install -g @anthropic-ai/claude-code

    Clearing the cache removes cached downloads, not installed programs.

    Issue 2: The claude Command Is Not Recognized

    Run:

    1. npm config get prefix
    2. Get-Command claude

    If the directory returned by the first command contains claude.cmd, but the second command cannot find it, add that directory to your user PATH as described in Section 3.2. Then reopen the terminal.

    Issue 3: Requests Return 401 or 403 Authentication Errors

    The configured token can be inspected with:

    1. echo $env:ANTHROPIC_AUTH_TOKEN

    This displays the secret in the terminal. Do not share the output or include it in screenshots.

    Check for:

    • Leading or trailing spaces.
    • Extra quotation marks accidentally included in the value.
    • A disabled or revoked key.
    • Insufficient account balance.

    Temporary PowerShell variables apply only to the current session. If you opened a different window, set them again.

    After correcting the key or account settings, repeat the test command.

    Issue 4: Connections Fail or Requests Time Out

    Check whether the endpoint is reachable:

    1. curl.exe -I "<provider-compatible-api-url>"

    Windows 10 and later include curl.exe.

    An HTTP status line shows that an HTTP server responded, but does not by itself verify the model name, credentials, or API compatibility. If the server responds, review those connection settings next.

    If the command receives no response, check your network connection and confirm that the Base URL has the correct protocol prefix.

    Issue 5: Proxy Settings Interfere with Requests

    Inspect the proxy variables:

    1. echo $env:HTTP_PROXY
    2. echo $env:HTTPS_PROXY

    If either command returns a proxy address, the terminal has proxy environment settings.

    Temporarily disabling your proxy software’s system proxy and testing again can help determine whether the proxy is responsible. Before doing so, check that this will not disrupt other applications using the network.

    To clear the variables only in the current PowerShell window, run:

    1. Remove-Item Env:HTTP_PROXY
    2. Remove-Item Env:HTTPS_PROXY

    Issue 6: Response Quality Is Unsatisfactory

    Response quality often depends on the selected model and how clearly the task is described.

    Try another model offered by the provider, split a large request into smaller steps, and specify the relevant file paths and expected results in your prompts.

    6. Final Checklist

    Use these checks to confirm that the environment is ready:

    1. Runtime and installation: node -v, npm -v, and claude --version all return version numbers.
    2. Download registry: npm config get registry returns your intended registry—either the official registry or the regional mirror selected for your network.
    3. Model connection: The following command returns a normal response:

      1. claude -p "Introduce yourself in one sentence."

    For another provider using the same Anthropic-compatible setup, update the Base URL, API key, and model name according to its documentation. The installation workflow and troubleshooting approach remain the same.