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
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:
npm install -g @anthropic-ai/claude-code
# Verify the installation:
claude --version
# Should output: claude-code/X.X.X
# 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
- Go to
console.anthropic.comand sign in - Click API Keys in the left sidebar
- Click Create Key
- Name it something like "Claude Code Local"
- Copy the key - it starts with
sk-ant-
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.
# 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:
# 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:
> 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:
# 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:
# 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
- Ctrl+C - cancel current operation
- ↑ - recall previous prompt
/help- show all commands/clear- clear conversation history/exitor Ctrl+D - exit Claude Code/compact- compress long conversations to save tokens