Guide to installing Claude Code and basic usage
Claude Code is an official CLI (Command Line Interface) AI coding tool developed by Anthropic. You can write, edit, and analyze code by conversing with AI directly in your terminal.
Unlike web-based AI chat, Claude Code integrates directly into your local development environment, allowing you to access the file system, execute terminal commands, explore your codebase, and more—all using natural language.
Before installing Claude Code, verify that you meet the following requirements.
| Item | Requirement |
|---|---|
| Node.js | 18.0 or higher (20.x LTS recommended) |
| OS | macOS, Linux, Windows (WSL2 required) |
| Memory | Minimum 4GB RAM |
| Network | Internet connection for API calls |
| Terminal | Standard shell such as bash, zsh, fish |
On Windows, WSL2 (Windows Subsystem for Linux 2) is required. Running directly in the native Windows Command Prompt or PowerShell is not supported.
# Install WSL2 (run in Administrator PowerShell)
wsl --install
# Install Node.js inside WSL2
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejsnpm install -g @anthropic-ai/claude-codeOnce installed, the claude command will be available globally.
claude --versionnpm update -g @anthropic-ai/claude-codeNavigate to your project directory and type claude.
cd ~/my-project
claudeOn first run, you need to configure your Anthropic API key. There are two ways to do this.
An API key is like a unique password for using the Claude AI service. Just as you need an account to watch Netflix, you need an API key to use Claude Code.
How to get an API key:
sk-ant-api03-...) and store it somewhere safeAlternatively, you can use the Max Plan or Pro Plan. Follow the on-screen instructions when you first launch Claude Code to log in with your Anthropic account, and you can start using it without an API key. In this case, you'll be charged on a monthly subscription basis.
Never share your API key with anyone. If someone else uses your key, you will be billed for their usage.
Method 1: Set an Environment Variable
export ANTHROPIC_API_KEY="sk-ant-api03-..."For a permanent setting, add it to ~/.bashrc or ~/.zshrc.
echo 'export ANTHROPIC_API_KEY="sk-ant-api03-..."' >> ~/.bashrc
source ~/.bashrcMethod 2: Interactive Input on First Run
When you run claude, a prompt will automatically appear to guide you through entering your API key.
You can also execute a single command without entering interactive mode.
claude -p "Explain the structure of this project"Running claude enters interactive REPL mode. Type your requests in natural language and Claude will respond.
> Find and clean up unused imports in this project
Claude explores the files and finds and removes unnecessary imports.
Claude Code can directly modify files. Before making changes, it always shows a diff and waits for your approval.
> Add a loading state prop to src/components/Button.tsx
Claude reads the file, shows the changes as a diff, and applies them once you approve.
Claude Code supports multiple Claude models. Choose the one that fits your task.
A model is like a "brain version" of Claude AI. Just as people have different levels of experience, AI models differ in capability.
If you're on the Max Plan or Pro Plan, you don't need to worry much about model selection. Just use the default settings.
| Item | Details |
|---|---|
| Use Case | Best for agentic tasks, the most powerful model |
| Context | 1M tokens (approximately 1 million tokens) |
| Strengths | Complex multi-step reasoning, large-scale refactoring, architecture design |
| Cost | Highest |
| Item | Details |
|---|---|
| Use Case | Everyday coding, general-purpose tasks |
| Context | 200K tokens |
| Strengths | Fast response time, cost-efficient, well-balanced performance |
| Cost | Medium |
| Item | Details |
|---|---|
| Use Case | Sub-agents, code exploration |
| Context | 200K tokens |
| Strengths | Low cost, fast responses, optimal for exploration tasks |
| Cost | Lowest |
# Start with a specific model
claude --model claude-opus-4-6Claude Code uses multiple layers of configuration files.
Configuration files are like a notepad that tells Claude Code "here's how to work in this project." For example, if you write down things like "this project uses TypeScript" or "run tests this way," Claude can handle things automatically without asking every time. You don't need to worry about this at first—just configure things one by one as you get comfortable.
Global settings that apply to all projects.
{
"permissions": {
"allow": ["Bash(npm test)", "Read"],
"deny": ["Bash(rm -rf)"]
},
"env": {
"CLAUDE_MODEL": "claude-sonnet-4-6"
}
}Located at the project root, it provides project context to Claude.
# Project Rules
- Use TypeScript strict mode
- Write tests with Vitest
- Commit messages follow Conventional Commits formatStores project-specific settings, agents, and commands.
.claude/
settings.json # Project settings (shared with team)
settings.local.json # Local-only settings (excluded from Git)
agents/ # Custom sub-agents
commands/ # Custom slash commands
Key shortcuts available in interactive mode.
| Shortcut | Function |
|---|---|
| Tab | Auto-complete (filenames, commands) |
| Ctrl+C | Cancel current response |
| Ctrl+D | End session |
| Alt+P | Switch model |
| Shift+Enter | Multi-line input |
| / | Slash commands |
| Command | Description |
|---|---|
/help | Show help |
/model | Select model |
/fast | Toggle Fast Mode |
/compact | Compress context |
/clear | Reset conversation |
/status | Check current status |
/permissions | Manage permissions |
/config | Open settings |
/agents | Manage sub-agents |
/cost | Check costs |
Here are common issues and solutions that you may encounter while installing and using Claude Code.
Claude Code requires Node.js 18.0 or higher. It will not run if an older version is installed.
# Check current Node.js version
node --version
# Install the latest LTS version with nvm (recommended)
nvm install 20
nvm use 20
nvm alias default 20
# If nvm is not installed, install it first
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.0/install.sh | bashSymptoms: error: Unsupported engine or SyntaxError: Unexpected token messages appear
Solution: Upgrade to Node.js 20.x LTS. Using nvm (Node Version Manager) makes it easy to manage multiple versions.
Network connection errors that Windows users may experience in the WSL2 environment.
# Check DNS settings
cat /etc/resolv.conf
# Manually configure DNS if it's not working
sudo bash -c 'echo "nameserver 8.8.8.8" > /etc/resolv.conf'
# Reset WSL2 network (run in Administrator PowerShell)
# wsl --shutdown
# Then restart WSLSymptoms: Network-related errors such as ETIMEDOUT, ENOTFOUND, getaddrinfo failed
Solution: Check the DNS settings in WSL2. If the issue persists, run wsl --shutdown and restart. If you're using a corporate VPN, WSL2 network settings may conflict—consider contacting your IT department.
This happens when the API key is not set correctly or has expired.
# Check the environment variable
echo $ANTHROPIC_API_KEY
# If the key is empty, set it again
export ANTHROPIC_API_KEY="sk-ant-api03-..."
# Quick test to verify the key works
claude -p "hello"Symptoms: 401 Unauthorized, Invalid API Key, Authentication failed errors
Solution Checklist:
sk-ant-api03-source ~/.bashrc)This occurs when you lack access permissions for files or directories.
# Check npm global directory permissions
ls -la $(npm config get prefix)/lib/node_modules/
# Change ownership to the current user
sudo chown -R $(whoami) $(npm config get prefix)/lib/node_modules/
sudo chown -R $(whoami) $(npm config get prefix)/bin/
# Or change the npm global path to a user directory (recommended)
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrcSymptoms: EACCES: permission denied, Error: EACCES errors
Solution: Running npm with sudo is not recommended. Instead, it's safer to change npm's global installation path to a user directory.
Permission issues that occur when installing npm global packages.
# Method 1: Use nvm (most recommended)
# Node.js installed via nvm goes in the user directory, so there are no permission issues
nvm install 20
# Method 2: Run temporarily with npx (use without installing)
npx @anthropic-ai/claude-code
# Method 3: Change the npm global directory
mkdir -p ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
npm install -g @anthropic-ai/claude-codeSymptoms: npm ERR! code EACCES, npm WARN checkPermissions Missing write access
Solution: Using nvm installs Node.js and npm in your home directory, fundamentally solving permission issues. Even if Node.js is already installed on your system, adopting nvm is recommended.
Using Claude Code requires a paid plan or an API key. The cost structure varies depending on how you use it.
Recommended order for beginners:
What are tokens? Tokens are the units AI uses to process text. Roughly, 1 Korean character equals 1-2 tokens, and 1 English word is about 1 token. The phrase "Hello there" is approximately 2 tokens.
| Item | Max Plan ($100/mo) | Max Plan ($200/mo) | Pro Plan ($20/mo) | Direct API Usage |
|---|---|---|---|---|
| Claude Code Usage | Unlimited (fair use policy) | Unlimited (higher limits) | Limited | Pay as you go |
| Default Model | Opus / Sonnet | Opus / Sonnet | Sonnet | Your choice |
| Pricing Structure | Monthly flat rate | Monthly flat rate | Monthly flat rate | Per-token usage |
| Best For | Daily-use developers | Heavy users, team leads | Light usage | Automation, CI/CD |
| Pros | Predictable costs | Most generous limits | Low entry cost | Fine-grained cost control |
| Cons | Rate limits on excessive use | High monthly cost | Limited Opus access | Unpredictable costs |
| Model | Input Tokens (per 1M) | Output Tokens (per 1M) | Notes |
|---|---|---|---|
| Claude Opus 4.6 | $15.00 | $75.00 | Most powerful but highest cost |
| Claude Sonnet 4.6 | $3.00 | $15.00 | Good balance of performance and cost |
| Claude Haiku 4.5 | $0.80 | $4.00 | Cheapest, suitable for simple tasks |
Note: Token prices are subject to change. Check the Anthropic website for the latest pricing.
These are rough monthly cost estimates based on usage patterns. Actual costs will vary depending on task complexity and codebase size.
| Usage Pattern | Description | Monthly Cost (Sonnet) | Monthly Cost (Opus) |
|---|---|---|---|
| Light | 5-10 queries/day, simple code edits | $10-30 | $50-150 |
| Moderate | 20-30 queries/day, including file edits | $30-80 | $150-400 |
| Heavy | 50+ queries/day, large-scale refactoring, multi-agent | $80-200+ | $400-1,000+ |
Cost-Saving Tips:
/cost command/compact command to reduce token usageNow that you've completed installation and basic setup, explore these topics next.