Setting Up a Command-Line AI Coding Assistant on Windows: A Step-by-Step Guide

    A practical guide to installing and configuring a command-line AI coding assistant on Windows, using Claude Code as an example. It covers installing Node.js and Git, deploying the assistant itself, configuring an API key safely across different terminals, and the pre-flight checks to run before letting the assistant modify your project.

    Using a command-line AI coding assistant on Windows involves four steps: install the runtime environment, install a version control tool, install the assistant itself, and provide it with an API key. This guide uses Claude Code as an example and walks through each step, along with common issues and how to resolve them.

    What These Tools Can Do

    A command-line AI coding assistant runs in your terminal. It can read the project files in the current directory, understand how files reference each other, modify code, and run tests. Unlike web-based chat interfaces, it works with your actual local codebase, which makes it better suited for developing features or debugging errors in existing projects.

    Because it edits files directly, make sure your project is under version control before you start, so you can roll back if something goes wrong.

    Preparing the Runtime Environment

    2.1 Install Node.js LTS

    Claude Code depends on Node.js and requires version 18 or later. Download the current LTS Windows installer (.msi) from nodejs.org. Keep the default options during installation and make sure “Add to PATH” is checked, so that the node and npm commands work from any directory.

    After installation, open a new PowerShell window and run:

    1. node -v
    2. npm -v

    If both commands print a version number, the environment is ready. If you see “is not recognized as the name of a cmdlet, function, script file, or operable program,” it usually means you did not reopen the terminal after installing, or the PATH option was unchecked during installation.

    2.2 Install Git for Windows

    The assistant needs to read commit history before modifying code, and it works best on a new branch. On Windows, Claude Code also relies on Git Bash to execute shell commands, so you need to install Git for Windows. Download the installer from git-scm.com and complete the installation with the default options.

    1. git --version

    If this prints a version number, Git is recognized by the system. If the assistant reports that it cannot find bash, consult the tool’s documentation for how to specify the full path to bash.exe, which is typically located in the bin folder of the Git installation directory.

    2.3 Choose a Terminal

    • Windows Terminal: Supports multiple tabs and customizable color schemes, suitable for extended use.
    • PowerShell: Preinstalled with Windows. All commands in this article assume PowerShell.
    • CMD: Also preinstalled, but its syntax for setting environment variables differs from PowerShell’s (see Section 4).
    • Editor-integrated terminal: Convenient for invoking the assistant while editing code. Some editors reset environment variables when opening a project; if your API key does not seem to take effect, verify it in a standalone system terminal first.

    Installing the Assistant

    3.1 Global Installation

    Run the following in PowerShell:

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

    After installation, run claude --version. A version number confirms a successful install.

    Common issues and fixes:

    1. Permission denied (EACCES or EPERM): Open PowerShell as administrator and retry. If it still fails, skip the global install and run it directly instead:

      1. npx @anthropic-ai/claude-code --version

      npx does not write the tool to a system directory, but it re-downloads the package each run, which is slower.

    2. Package name typo (npm returns 404): Check that the package name exactly matches the command above.

    3. Command not found: Run npm config get prefix to see the global installation directory. On Windows, the default is usually %APPDATA%\npm. Confirm this directory is in PATH, then reopen the terminal.
    4. Network proxy issues: Run npm config get proxy to check the current proxy settings and make sure they match your network environment.

    3.2 Speeding Up Downloads (Optional)

    If downloads are slow in your network environment, you can specify an alternative registry for a single install command without changing your global configuration:

    1. npm install -g @anthropic-ai/claude-code --registry=<registry-url>

    This flag applies only to the current command. If you want to use a registry permanently, run npm config set registry to change the global configuration. To restore the default later, run npm config set registry https://registry.npmjs.org.

    Obtaining and Configuring the API Key

    4.1 Create a Key

    Sign in to the Anthropic console (console.anthropic.com) and create a new key on the API Keys page. Give the key a recognizable name, such as local-windows-dev, to make troubleshooting easier later. Keys are typically shown in full only once at creation time, so copy it immediately and store it in a password manager.

    4.2 Set the Environment Variable

    On Windows, the syntax for setting environment variables depends on the terminal you use.

    PowerShell, current window only:

    1. $env:ANTHROPIC_API_KEY = "your-key"

    PowerShell, permanent:

    1. setx ANTHROPIC_API_KEY "your-key"

    setx writes a user-level environment variable that only newly opened terminals can read. After running setx, the variable in the current window remains unchanged, so you need to close and reopen the terminal.

    CMD, current window only:

    1. set ANTHROPIC_API_KEY=your-key

    For a permanent setting in CMD, use setx as well.

    The export command commonly used on Linux and macOS does not work in the default Windows terminals.

    After setting the variable, you can check whether it exists without printing the key itself:

    1. if ($env:ANTHROPIC_API_KEY) { "Set" } else { "Not set" }

    4.3 Security Considerations

    • Never write the key into project code, configuration files, or commit history.
    • Values stored via setx are kept in plaintext in the current user’s registry, and any program running under the same Windows account can read them. On shared devices, use the tool’s built-in encrypted login method instead, or set the variable manually for each session.
    • If you suspect the key has been leaked, delete it immediately in the console, create a new one, and update your local configuration.

    Once these steps are complete, navigate to your project directory and run claude to start the assistant. On first launch, the tool checks the key. If it prompts you to log in, follow the on-screen instructions to complete authorization.

    Pre-Flight Checks Before Using It in a Project

    1. Navigate to the project directory and run git status to confirm the working tree is clean. If there are uncommitted changes, commit or stash them first.
    2. Run git switch -c ai-test-branch to create a new branch and let the assistant work on it.
    3. In the tool’s permission settings, deny access to .env files, certificates, and credential files. The exact configuration options vary by tool, so refer to its official documentation. Note that .gitignore only prevents files from being committed—it does not prevent the tool from reading local files.
    4. For changes involving core business logic, review them line by line with git diff before merging.

    Quick Troubleshooting Reference

    • Command not found: Reopen the terminal and check whether the directory printed by npm config get prefix is in PATH.
    • Authentication failure: Make sure there are no extra spaces around the key and that the variable name matches what the tool expects.
    • Download timeouts: Use the registry flag from Section 3.2, or check your proxy settings.

    Following these steps in order gets you from a clean Windows machine to a fully configured command-line AI coding assistant. After that, before each new project, set up version control and review permission settings first—then let the assistant start working.