Setup Claude Code

Install Claude Code in under 10 minutes. Step-by-step for Windows, Mac, and Linux - from zero to your first working AI coding session.

Beginner 10 min setup Lesson 2 of 20

Requirements

Before installing Claude Code you need:

  • Node.js 18+ - download from nodejs.org (includes npm)
  • A terminal - Command Prompt or PowerShell on Windows, Terminal on Mac/Linux
  • An Anthropic account - free to create at console.anthropic.com
Check if Node.js is installed
node --version
# Should output: v18.0.0 or higher (e.g. v22.1.0)

npm --version
# Should output: 8.0.0 or higher

Install Claude Code

Claude Code is installed as a global npm package. Run this in your terminal:

Install (all platforms)
npm install -g @anthropic-ai/claude-code

# Verify the installation:
claude --version
# Should output: claude-code/X.X.X
If you get a permission error (Mac/Linux)
# Option 1: use sudo
sudo npm install -g @anthropic-ai/claude-code

# Option 2 (recommended): fix npm permissions first
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.bashrc
source ~/.bashrc
npm install -g @anthropic-ai/claude-code

Get Your API Key

  1. Go to console.anthropic.com and sign in
  2. Click API Keys in the left sidebar
  3. Click Create Key
  4. Name it something like "Claude Code Local"
  5. Copy the key - it starts with sk-ant-
Save your API key somewhere safe

The key is only shown once. Store it in a password manager or a secure note. Do not put it in your code files or commit it to Git. If you lose it, you can generate a new one, but old keys cannot be recovered.

Set your API key as environment variable
# Mac/Linux - add to ~/.bashrc or ~/.zshrc:
export ANTHROPIC_API_KEY="sk-ant-your-key-here"
source ~/.bashrc

# Windows PowerShell - set for current session:
$env:ANTHROPIC_API_KEY = "sk-ant-your-key-here"

# Windows - set permanently (System Properties):
# Control Panel -> System -> Advanced -> Environment Variables
# Add new: ANTHROPIC_API_KEY = sk-ant-your-key-here

Your First Session

Navigate to any project folder (or create a test folder) and run claude:

Start your first session
# Create a test project folder:
mkdir my-first-ai-project
cd my-first-ai-project

# Start Claude Code:
claude

# You will see:
# Welcome to Claude Code!
# > (prompt waiting for your input)

Try typing your very first prompt:

First prompts to try
> Create a simple PHP file that displays "Hello, AI Coding!" in the browser

> Write a Python script that prints the current date and time

> What files are in my current directory?

> Create an index.html with a basic webpage structure

Claude Code will ask for permission before creating or modifying files. Press Y to allow, N to deny. You can also type /permissions to configure what is auto-approved.

Create Your First CLAUDE.md

CLAUDE.md is a plain text file in your project root that tells Claude Code about your project. Create it now so the agent always has context:

CLAUDE.md - starter template
# My Project

## What this project is
[Describe your project in 1-2 sentences]
Example: A PHP website for a restaurant to show their menu and accept reservations.

## Technology stack
- Language: PHP 8.2
- Database: MySQL 8
- Frontend: Bootstrap 5
- Server: Apache (XAMPP locally)

## Project structure
- /index.php - homepage
- /config/ - database and app config
- /pages/ - individual page files
- /assets/ - CSS, JS, images

## Important rules
- Use PDO for all database queries (never raw mysqli)
- No inline CSS - use /assets/css/style.css
- Keep PHP and HTML separate where possible

## How to run locally
Open XAMPP, start Apache + MySQL, visit http://localhost/my-project/

Verify Everything Works

Run these checks to confirm your setup is complete:

Verification checklist
# 1. Check Claude Code version:
claude --version
# Expected: claude-code/X.X.X

# 2. Check API key is set:
echo $ANTHROPIC_API_KEY   # Mac/Linux
echo $env:ANTHROPIC_API_KEY  # Windows PowerShell
# Expected: sk-ant-...

# 3. Start a session and ask a simple question:
claude
> What is 2 + 2?
# Expected: Claude responds "4" or similar

# 4. Test file creation:
> Create a file called test.txt with the text "Setup complete!"
# Expected: Claude creates the file (after your permission)
cat test.txt   # or open it in a text editor
Useful Claude Code keyboard shortcuts
  • Ctrl+C - cancel current operation
  • - recall previous prompt
  • /help - show all commands
  • /clear - clear conversation history
  • /exit or Ctrl+D - exit Claude Code
  • /compact - compress long conversations to save tokens

Frequently Asked Questions

Claude Code has two pricing modes. (1) Subscription: flat monthly fee from Anthropic - good for heavy daily use. (2) API (pay-per-use): you pay for the tokens you use via the Anthropic API. For learning, a small API credit ($5-20) lasts a long time. Check the Anthropic website for current pricing as rates change.

Yes. Claude Code supports OAuth login with your Anthropic account for subscription-based access. You do not need a separate API key if you have a Claude Code subscription. During setup, choose "Login with Anthropic" instead of entering an API key.

Yes. Always navigate to your project folder before running claude. Claude Code reads CLAUDE.md and uses the current directory as the project root. Running it from the wrong directory means the agent has no project context and will ask you what to work on.

The most common first-run errors: (1) Node.js not installed - install from nodejs.org, (2) API key incorrect or expired - check the Anthropic console, (3) Permission errors on Linux/Mac - run sudo npm install -g @anthropic-ai/claude-code. For Windows, run the terminal as Administrator for the install step.