How to Set Up and Run Claude Code on Windows
This guide explains how to set up and run Claude Code on Windows, covering Node.js and Git preparation, terminal and encoding settings, npm installation, authentication configuration, first project setup, and common troubleshooting. It is aimed at developers who want to use a terminal-based AI coding assistant safely and effectively in local projects.
1. Introduction: Why Use an AI Coding Assistant in the Terminal
1.1 From copy-and-paste to direct collaboration
Web-based AI chat tools can help with many programming tasks, but making them truly useful for project development usually requires a lot of manual work. You often need to copy error messages into the chat, paste relevant code snippets, and then manually transfer the suggested changes back into your files. This “manual relay” workflow has three major limitations:
- Incomplete context: The AI only sees isolated fragments and struggles to understand how modules depend on one another.
- Slow feedback loop: After changing code, you must run tests yourself, copy the results back, and repeat the process manually.
- Inconsistent results: Manual copying can introduce omissions or mistakes, and changes are difficult to trace.
A terminal-based AI coding assistant behaves more like an AI teammate that can work directly with your repository. It runs in your own terminal and provides capabilities that are difficult to replicate in a web chat:
- Direct file access: It can search and understand the overall project structure instead of relying on pasted snippets.
- Local command execution: It can run tests, builds, and code checks, then adjust its implementation based on real results instead of giving advice without feedback.
- Version-control awareness: It can work with version control systems to review changes, generate commit messages, and keep modifications reviewable and reversible.
- Scriptable integration: Non-interactive mode can be embedded into continuous integration workflows for tasks such as code review or automated fixes.
1.2 Use cases and limitations
This type of tool is especially useful for the following tasks:
- Understanding unfamiliar or legacy code;
- Refactoring and applying broad changes across multiple files;
- Diagnosing and fixing defects based on error output;
- Adding unit tests and API documentation;
- Generating commit messages and changelogs.
At the same time, it is important to recognize the limits. AI-generated code may contain hallucinations, such as inventing APIs or functions that do not exist. It may miss edge cases or introduce security risks. Architecture decisions, core business logic, and any operation that deletes or overwrites data should still be reviewed and controlled by humans.
Setting up this type of tool on Windows generally requires four steps:
- Prepare the base runtime environment.
- Install the command-line coding assistant.
- Configure credentials and the API endpoint.
- Connect it to a project for the first time.
The following sections explain each step.
2. Preparing the Base Environment
2.1 Install Node.js
Most command-line coding assistants are written in JavaScript or TypeScript and distributed through package managers, so Node.js must be installed first. Node.js includes npm, which is needed to install and update the assistant.
For version selection, it is recommended to download the LTS release from the official Node.js website:
For example, you can use Node.js 20.x LTS. LTS versions receive maintenance and security updates for a longer period, offering better stability and compatibility while avoiding unexpected issues that may appear in newer releases.
On Windows, run the installer and accept the default options. The installer will add Node.js and npm to the system PATH automatically.
2.2 Verify the runtime environment
After installation, press Win+X and open Windows PowerShell, then run:
node -vnpm -v
If both commands print version numbers, the environment is ready.
If you see errors such as “not recognized as an internal or external command” or “cannot be recognized as a cmdlet,” there are usually two common causes:
- The installation directory was not added to PATH.
- The terminal was already open before the installation completed.
In that case, reinstall Node.js and make sure the PATH-related option is enabled, or close the terminal and open it again.
If you frequently switch between different runtime versions, you may also consider using version managers such as fnm or nvm-windows.
2.3 Configure Git
It is strongly recommended to install Git. You can download it from the official website:
During installation, accepting the default options is usually sufficient.
Git is important because AI assistants often modify multiple files. You need a reliable way to review and roll back changes. Git provides three key safeguards:
git diffshows exactly what changed in the current round of edits.git stashorgit checkoutcan quickly restore a clean working state if something goes wrong.- Each commit can serve as a separate review unit.
After installation, verify it with:
git --version
Before first use, configure your identity:
git config --global user.name "Your Name"git config --global user.email "you@example.com"
It is also recommended to add a .gitignore file in the project root and exclude dependency directories, build outputs, and credential files from version control.
2.4 Choose a terminal
You can use several types of terminals on Windows:
- A modern terminal application;
- The built-in PowerShell;
- The integrated terminal inside an IDE;
- A Bash-like terminal bundled with version-control tools.
Microsoft Windows Terminal, available through the Microsoft Store, is a good choice. It supports multiple tabs, better Unicode rendering, and quick switching between shells, which is useful when working on several tasks at once.
Whichever terminal you choose, make sure the encoding is set to UTF-8. This is a common issue for developers working with non-English text on Windows. If AI output or file contents appear garbled, check whether chcp 65001 has been used, or enable “Use Unicode UTF-8 for worldwide language support” in Windows Region settings.
If your project uses containerized development, you can also install Docker Desktop so that AI-generated code can be tested in an isolated environment.
3. Installing the Command-Line Coding Assistant
3.1 Install globally with npm
Open a terminal and run:
npm install -g @anthropic-ai/claude-code
After installation, verify it with:
claude --version
If a version number is printed, the installation was successful.
On some managed or company-managed Windows machines, the default global directory may not be writable. In that case, the command may fail with an EACCES error. There are several ways to handle this.
Option 1: Temporarily elevate permissions
Open PowerShell as Administrator and run the installation command again.
Option 2: Change the global npm directory
You can set a user-writable global prefix and make sure its executable directory is included in PATH. For example, in PowerShell you can run:
npm config set prefix "$env:USERPROFILE\.npm-global"
Then add that directory to PATH. The exact steps depend on whether you are using PowerShell, Windows Terminal, or a Bash-like shell.
Option 3: Run without global installation
You can also run Claude Code temporarily with npx, without installing it globally:
npx -y @anthropic-ai/claude-code --version
This approach is suitable for occasional trials or one-time tasks. However, it may download the package repeatedly, which requires a reliable network connection.
If downloads are slow, you can temporarily configure npm to use a faster registry mirror, install the package, and then switch back to the official registry:
npm config set registry https://registry.npmjs.org
Be aware that mirror registries may be out of sync. If you receive an old version or encounter hash verification failures, switch back to the official registry and try again.
3.2 If your network environment is restricted
If your network requires a proxy to access external resources, configure npm to use the proxy, or download the installer in an environment with access and then install it offline.
In enterprise environments, it is often better to use an internal package repository, such as Nexus or Verdaccio. This can improve installation speed and make it easier to scan third-party packages for security issues.
3.3 Post-installation checks
After installation, verify the following:
claude --versionworks from any directory.claude --helpdisplays the help information.- Only one version is installed on the machine, to avoid accidentally calling an older version.
4. Authentication and API Key Configuration
4.1 Authentication options
Claude Code requires authorization before it can call the model. There are two common approaches:
- Sign in with a Claude subscription account.
- Use an Anthropic API key with usage-based billing.
If you do not have an Anthropic account yet, you may obtain an API key from a compatible API provider. The exact onboarding process depends on the provider, but the configuration is generally similar: create an account, create an API key, and then provide the key and endpoint to Claude Code.
4.2 Obtain and configure an API key
If you are using a third-party API provider, the general steps are:
- Create an account and sign in.
- Open the API token or key management page.
- Create a new key.
- Copy the generated key, which usually starts with
sk-.
The full key may only be shown once when it is created. Store it securely and do not commit it to source control or share it in chat messages, screenshots, or issue trackers.
4.3 Three configuration methods
Method 1: Environment variables
Environment variables can be used to configure the key and endpoint.
For the current terminal session:
export ANTHROPIC_AUTH_TOKEN="sk-your-key"export ANTHROPIC_BASE_URL="https://your-api-base-url"
To make the settings persistent, you can add them to a shell configuration file, depending on the shell you use.
On Windows, you can set them temporarily in PowerShell:
$env:ANTHROPIC_AUTH_TOKEN = "sk-your-key"$env:ANTHROPIC_BASE_URL = "https://your-api-base-url"
For user-level environment variables, you can also use setx.
ANTHROPIC_AUTH_TOKEN stores the API key, while ANTHROPIC_BASE_URL specifies the API endpoint.
Method 2: settings.json
Claude Code creates a configuration directory in the user home folder, ~/.claude/. On Windows, this is usually:
C:\Users\YOUR_USERNAME\.claude\
You can configure the key and endpoint in settings.json:
{"env": {"ANTHROPIC_AUTH_TOKEN": "sk-your-key","ANTHROPIC_BASE_URL": "https://your-api-base-url"}}
Method 3: Project-level configuration
A team can create .claude/settings.json in the project root and put common settings such as model preferences and permission policies under version control.
However, secrets should not be stored in this file. API keys should be injected through environment variables or a secret-management service.
4.4 Verify connectivity
After configuration, open a terminal in the project directory and start Claude Code with a simple test request:
claude "Hello, list the files in the current directory."
If Claude Code returns a valid response, the configuration is working.
If you receive a 401 response, the key may be invalid or not loaded correctly. If you receive a 404 response or the connection times out, check whether ANTHROPIC_BASE_URL is correct and whether the network is reachable.
5. First Project Setup and Run
5.1 Start from the project root
Claude Code uses the current directory as its working directory. For this reason, it is recommended to enter the project root before starting it:
cd path/to/your-projectclaude
5.2 Trust and permission prompts
When you first open a project, Claude Code may ask whether you trust the files and commands in that directory.
This is a security precaution. An AI assistant may be able to execute arbitrary commands. If the project contains malicious code or is affected by a prompt-injection attack, it could lead to data leakage or damage. Only continue if you trust the source of the project.
By default, the tool may request confirmation for each write operation or command execution, such as permission rules like Bash(npm run test:*). During the initial phase, it is best to keep per-action confirmation enabled. After you become familiar with the tool, you can relax the rules as needed.
5.3 Improve efficiency with project context files
Creating a CLAUDE.md file in the project root can significantly improve the assistant’s understanding of the project. It can include:
- A short project overview and technology stack;
- A description of the directory structure;
- Common commands for installing dependencies, running tests, building, and linting;
- Coding conventions, including naming style, branching strategy, and commit-message format;
- Important warnings, such as “do not modify generated code.”
5.4 Common interactive commands
Useful commands include:
/help: Show help./clear: Clear the current context, which is useful when switching tasks./compact: Compress the context while keeping key information, reducing slowdown and cost in long sessions.claude -corclaude --continue: Continue the previous session.claude -p "task description": Run a non-interactive single request, suitable for scripts or CI pipelines.claude commit: Automatically generate a commit message and commit changes.
6. Troubleshooting Common Issues
Permission errors during installation
Open PowerShell as Administrator, use a user-writable npm prefix, or run withnpx.Command not found
Confirm that the npm global directory is included in PATH, then reopen the terminal.Slow downloads
Temporarily switch npm to a faster registry mirror or configure a proxy.Invalid key or 401 response
Check whether the key was copied completely, whether it has expired, and whetherANTHROPIC_BASE_URLis correct.Garbled non-English text
Make sure the terminal encoding is UTF-8, for example by usingchcp 65001.Slow responses or high cost
Use/clearor/compactto reduce the context, and avoid bringing unrelated files into the conversation.Accidental file changes
Usegit diffto review modifications. If necessary, roll back changes withgit restoreorgit stash.
7. Conclusion
The overall setup path for Claude Code on Windows can be summarized as follows:
- Install Node.js LTS and Git.
- Install Claude Code globally with npm.
- Configure the API key and endpoint.
- Start Claude Code from the project root and add
CLAUDE.md.
Once these steps are complete, an AI assistant can move beyond being a simple question-answering tool and become a more direct collaborator in development. For safe and reliable use, always treat version control, per-action confirmation, and code review as essential practices.
