Claude Code is an npm package: @anthropic-ai/claude-code. One global install command gives you Anthropic's terminal-based coding agent. This guide covers the npm installation path specifically, including prerequisites, permission fixes, version management, and post-install configuration.
Prerequisites
The npm installation requires two things: Node.js and a paid Anthropic account.
Node.js 18.0+
The package is distributed as an ES module. Node.js versions below 18 will install the package without errors but fail at runtime with a syntax error. Always verify your version first:
Check Node.js and npm versions
node --version # Must be v18.0.0 or higher
npm --version # Any recent npm works (v8+)If your Node.js is too old, use nvm to install a current version:
Install Node.js via nvm
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
# Install and use Node.js 22 (LTS)
nvm install 22
nvm use 22
# Verify
node --version # v22.x.xAnthropic Account
Claude Code requires a paid account. Any of these work: Claude Pro ($20/month), Claude Max ($100-200/month), Claude Teams, Claude Enterprise, or an Anthropic Console account with API credits. The free Claude.ai plan does not include Claude Code access.
Install Command
One command installs Claude Code globally and makes the claude CLI available everywhere:
Install Claude Code via npm
npm install -g @anthropic-ai/claude-codeAfter installation, verify it worked:
Verify installation
claude --version # Should print the installed version
which claude # Shows the install locationPackage details
The package name is @anthropic-ai/claude-code, published under Anthropic's npm scope. It's roughly 56 MB unpacked and includes platform-specific optional dependencies for image processing (Sharp library) across Linux, macOS, and Windows on both x64 and ARM architectures.
Global vs Local Install
Global Install (Recommended)
The -g flag installs Claude Code system-wide. The claude command becomes available in every terminal session, in every directory.
Global install
npm install -g @anthropic-ai/claude-code
# Available everywhere
cd ~/project-a && claude # works
cd ~/project-b && claude # worksLocal Install (Per-Project)
You can install Claude Code as a project dependency. This is useful for locking the version per-project or for monorepo setups where different teams need different versions.
Local install
# Install as a dev dependency
npm install --save-dev @anthropic-ai/claude-code
# Run via npx from the project root
npx claude
# Or add to package.json scripts
# "scripts": { "claude": "claude" }
npm run claude| Global Install | Local Install | |
|---|---|---|
| Command | npm install -g @anthropic-ai/claude-code | npm install --save-dev @anthropic-ai/claude-code |
| Available in | Any directory | Only the project directory |
| Version control | Single version system-wide | Version pinned per project |
| Best for | Daily development use | CI/CD pipelines, team standardization |
| Run command | claude | npx claude |
Fixing Permission Errors
EACCES permission errors are the most common npm installation issue. They happen when npm tries to write to a directory your user doesn't own (typically /usr/local/lib/node_modules).
Never use sudo with npm
Running sudo npm install -g creates files owned by root in your npm directory. This causes cascading permission problems for every future global install. Always fix the underlying permission issue instead.
Fix 1: Change npm's Default Directory
Reconfigure npm global directory
# Create a new directory for global packages
mkdir -p ~/.npm-global
# Tell npm to use it
npm config set prefix '~/.npm-global'
# Add to your shell profile (~/.zshrc, ~/.bashrc, or ~/.profile)
export PATH=~/.npm-global/bin:$PATH
# Reload your shell
source ~/.zshrc # or source ~/.bashrc
# Now install without permission issues
npm install -g @anthropic-ai/claude-codeFix 2: Use nvm (Recommended)
nvm installs Node.js in your home directory, so global npm installs never need elevated permissions.
Install via nvm (avoids all permission issues)
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bash
# Install Node.js
nvm install 22
# Install Claude Code (no permission issues)
npm install -g @anthropic-ai/claude-codeVersion Management
Install a Specific Version
Pin to a specific version
# Install exact version
npm install -g @anthropic-ai/claude-code@2.1.74
# Check available versions
npm view @anthropic-ai/claude-code versions --json
# Check latest version
npm view @anthropic-ai/claude-code versionUpdate to Latest
Update Claude Code
# Update to latest
npm update -g @anthropic-ai/claude-code
# Or reinstall to force latest
npm install -g @anthropic-ai/claude-code@latest
# Check current version
claude --versionDowngrade
If a new version introduces a regression, pin back to a working release:
Downgrade to a previous version
npm install -g @anthropic-ai/claude-code@2.1.70npm vs native installer for updates
The native installer auto-updates in the background. npm installations require manual updates with npm update -g. If you want automatic updates without thinking about it, the native installer is the better choice. Use npm when you need explicit version control.
Alternative Package Managers
npx (Run Without Installing)
npx downloads and runs the package in one step. No global install, no cleanup needed.
Run with npx
# Run latest version without installing
npx @anthropic-ai/claude-code
# Run a specific version
npx @anthropic-ai/claude-code@2.1.74bunx (Bun)
If you use Bun as your JavaScript runtime, bunx is the equivalent of npx:
Run with Bun
# Run without installing
bunx @anthropic-ai/claude-code
# Or install globally with Bun
bun install -g @anthropic-ai/claude-codeyarn
Install with Yarn
# Yarn 1.x global install
yarn global add @anthropic-ai/claude-code
# Yarn 2+ (Berry) - use dlx for one-off execution
yarn dlx @anthropic-ai/claude-codepnpm
Install with pnpm
# Global install
pnpm add -g @anthropic-ai/claude-code
# One-off execution
pnpm dlx @anthropic-ai/claude-codenpm / yarn / pnpm
Use for permanent global installs. The claude command stays available across terminal sessions. Best for daily development where you use Claude Code regularly.
npx / bunx / dlx
Use for one-off execution or testing specific versions. Downloads, runs, and cleans up. Best for CI pipelines or trying Claude Code before committing to a global install.
Post-Install Setup
Step 1: Authenticate
Run claude in any project directory. On first launch, it opens your browser for OAuth authentication.
First launch and authentication
cd your-project
claude
# Browser opens -> authorize Claude Code -> token stored locallyFor headless environments (CI, SSH, containers), set an API key instead:
Headless authentication
export ANTHROPIC_API_KEY=sk-ant-...
claude # Skips browser auth, uses API key directlyStep 2: Generate CLAUDE.md
CLAUDE.md is the most important post-install configuration. It gives Claude persistent context about your project: build commands, conventions, architecture decisions.
Generate CLAUDE.md
# Inside Claude Code, run:
/init
# This analyzes your codebase and generates a CLAUDE.md with:
# - Detected build system and commands
# - Test framework configuration
# - Code style patterns
# - Project structure overviewStep 3: Verify Everything Works
Quick verification
# Check version
claude --version
# Check health
claude doctor
# Check authentication
claude whoamiInstalling MCP Servers Alongside Claude Code
MCP (Model Context Protocol) servers extend Claude Code with external tools. After installing Claude Code via npm, you can add MCP servers that give Claude access to search, databases, GitHub, and other services.
Add MCP servers
# Add WarpGrep for RL-trained code search
claude mcp add warpgrep -- npx -y warpgrep-mcp@latest
# Add GitHub integration
claude mcp add github -- npx -y @modelcontextprotocol/server-github
# Add an HTTP-based MCP server
claude mcp add notion --transport http https://mcp.notion.com/mcp
# List all configured servers
claude mcp listWarpGrep MCP
RL-trained code search that runs in its own context window. Finds precise file and line ranges without flooding Claude's main context. Built by Morph.
GitHub MCP
Create PRs, manage issues, review code, and interact with repos directly from the terminal. No browser switching.
Postgres MCP
Query databases, inspect schemas, and run migrations. Claude reads your data to inform its code edits.
MCP servers are npm packages too
Most MCP servers are distributed as npm packages and run via npx. Claude Code manages them automatically after you add them with claude mcp add. No separate installation step needed.
Common Errors and Fixes
npm ERR! EACCES: permission denied
npm is trying to write to a root-owned directory. See the Permission Errors section above. Never use sudo.
SyntaxError: Cannot use import statement outside a module
Your Node.js version is below 18. The package uses ES module syntax that older Node versions don't support.
Fix: upgrade Node.js
node --version # Check current version
nvm install 22 # Install Node 22
nvm use 22 # Switch to it
npm install -g @anthropic-ai/claude-code # Reinstallnpm ERR! code ENOENT or network errors behind a proxy
Corporate proxies and firewalls can block npm registry access. Configure npm to use your proxy:
Configure npm proxy
npm config set proxy http://proxy.company.com:8080
npm config set https-proxy http://proxy.company.com:8080
# If using a custom registry
npm config set registry https://registry.company.com/
# Then retry
npm install -g @anthropic-ai/claude-codeclaude: command not found after npm install
The npm global bin directory isn't in your PATH. Find it and add it:
Fix PATH for npm global binaries
# Find npm's global bin directory
npm bin -g
# Add it to your PATH in ~/.zshrc or ~/.bashrc
export PATH=$(npm bin -g):$PATH
# Reload shell
source ~/.zshrcnpm WARN deprecated warnings during install
Deprecation warnings from transitive dependencies are harmless. The package will still install and work correctly. These warnings come from sub-dependencies, not from Claude Code itself.
WSL: Node.js installed on Windows but not in WSL
If you're using WSL, you need Node.js installed inside the WSL environment, not just on the Windows side. Install nvm inside WSL and set up Node.js there.
npm Install vs Native Installer
Anthropic offers multiple installation methods. Here's when to use npm vs the alternatives:
| npm install | Native Installer | Homebrew | |
|---|---|---|---|
| Command | npm install -g @anthropic-ai/claude-code | curl -fsSL https://claude.ai/install.sh | bash | brew install --cask claude-code |
| Node.js required | Yes (18+) | No | No |
| Auto-updates | No (manual npm update) | Yes | No (manual brew upgrade) |
| Version pinning | Yes (append @version) | No | No |
| Best for | CI/CD, version control | Daily development | Homebrew users |
| Package size | ~56 MB | Native binary | Native binary |
| Uninstall | npm uninstall -g @anthropic-ai/claude-code | Installer handles it | brew uninstall claude-code |
For most developers, the native installer is the better default. Use npm when you have a specific reason: pinning versions in CI, standardizing on npm across your team, or installing as a local project dependency.
Frequently Asked Questions
What is the npm command to install Claude Code?
npm install -g @anthropic-ai/claude-code. This installs the claude CLI globally. Requires Node.js 18.0 or newer.
Do I need Node.js to use Claude Code?
Only for the npm installation method. The native installer and Homebrew methods have zero dependencies. Use those if you don't want to manage a Node.js installation.
How do I fix EACCES permission errors?
Never use sudo. Either reconfigure npm's global directory (npm config set prefix '~/.npm-global') or use nvm, which installs Node.js in your home directory and avoids permission issues entirely.
Can I use npx instead of installing globally?
Yes. npx @anthropic-ai/claude-code downloads and runs Claude Code in one step without a permanent install. bunx @anthropic-ai/claude-code works the same way for Bun users.
How do I update Claude Code installed via npm?
Run npm update -g @anthropic-ai/claude-code. Or force the latest: npm install -g @anthropic-ai/claude-code@latest. Check your current version with claude --version.
Should I use npm or the native installer?
The native installer is better for daily use: zero dependencies, auto-updates. Use npm if you need version pinning (CI/CD), per-project installs, or your team standardizes on npm for CLI tool management.
What Node.js version does Claude Code require?
Node.js 18.0 or newer. The package is an ES module; older Node versions fail at runtime with syntax errors. Use node --version to check, and nvm to upgrade.
What is the exact npm package name?
@anthropic-ai/claude-code. It's published under Anthropic's npm scope (@anthropic-ai). The full install command is npm install -g @anthropic-ai/claude-code.
Related Guides
Supercharge Claude Code with WarpGrep
After installing Claude Code via npm, add WarpGrep as an MCP server. It gives Claude RL-trained code search in its own context window, so your main session stays clean. One command to add: claude mcp add warpgrep -- npx -y warpgrep-mcp@latest