Claude Code: From Install to First Command
A complete guide to installing Claude Code CLI — the tool that lets you chat with Claude directly in your terminal to read, edit, and generate code. From Node.js setup to authentication to your first command, everything is covered. Takes about 15-20 minutes if you already have Node.js.
What you will build
By the end of this guide, you will have Claude Code installed and authenticated, ready to analyze, modify, and generate code in any project folder. You will also know the essential commands (/help, /compact, etc.) to work efficiently.
Before you start
- A computer (Windows, Mac, or Linux)
- Internet connection
- Basic terminal usage — cd, ls, etc.
Problem
Required Tools
The runtime required to run Claude Code. Download the LTS version from nodejs.org.
Anthropic's official CLI tool, installed via npm. Run it with the claude command in your terminal.
Solution Steps
Step 1: Verify Node.js Installation
~3 minClaude Code runs on top of Node.js. First, check whether Node.js is already installed on your system. [Open your terminal] - Windows: Search for "PowerShell" and open it - Mac: Press Cmd+Space, type "Terminal", and open it - Linux: Press Ctrl+Alt+T or open your terminal app [Check your version] Type the command below and press Enter. If you see v18.x.x or higher, Node.js is already installed — skip to Step 2. [If you need to install Node.js] If you get "command not found" or a version below 18: 1. Go to nodejs.org in your browser 2. Click the "LTS" (Long Term Support) download button 3. Run the downloaded installer and follow the prompts 4. After installation, close and reopen your terminal, then check again with node -v
Pro Tip
Pro Tip
Warning
Success!
# Check Node.js version
node -v
# Expected output: v22.13.1 (or similar)
# Also verify npm is available
npm -v
# Expected output: 10.9.2 (or similar)Step 2: Install Claude Code
~2 minUse npm (Node.js package manager) to install Claude Code globally. A global install means you can run the claude command from any folder on your system. Paste the command below into your terminal and press Enter. The download and installation takes about 1-2 minutes.
Pro Tip
Warning
Warning
Success!
# Install Claude Code globally
npm install -g @anthropic-ai/claude-code
# Verify the installation
claude --versionStep 3: Set Up Authentication
~3 minWhen you run Claude Code for the first time, you need to authenticate with your Anthropic account. Choose one of two authentication methods. [Option 1: Browser OAuth Login (Recommended)] Best for Claude Pro or Max subscribers. 1. Type claude in your terminal and press Enter 2. A browser window opens automatically with the Anthropic login page 3. Log in with your Claude account 4. Once authenticated, you will see a confirmation message in the terminal 5. Your session stays authenticated going forward [Option 2: API Key] For developers who want to use an API key with usage-based billing. 1. Go to console.anthropic.com → API Keys → create a new key 2. Set the environment variable in your terminal (see code below) 3. Run claude — it will use the API key automatically
Pro Tip
Pro Tip
Warning
Success!
# Option 1: Browser login (just run claude)
claude
# → Browser opens automatically to login page
# → After login, you're ready to use Claude Code
# Option 2: Set API key as environment variable
# Mac/Linux:
export ANTHROPIC_API_KEY="sk-ant-xxxxx"
# Windows PowerShell:
$env:ANTHROPIC_API_KEY="sk-ant-xxxxx"
# Make it permanent (Mac/Linux — add to ~/.bashrc or ~/.zshrc)
echo 'export ANTHROPIC_API_KEY="sk-ant-xxxxx"' >> ~/.zshrc
source ~/.zshrcStep 4: Start in Your Project Folder
~2 minClaude Code can read and modify files in your current directory. So you need to navigate to your project folder before running claude. [If you have an existing project] Navigate to that folder and run claude. [If you are starting a new project] Create an empty folder, navigate into it, and run claude. You can then ask Claude to set up the project for you. When Claude Code starts, it scans the folder structure and, if a CLAUDE.md file exists, automatically loads project-specific rules and conventions.
Pro Tip
Pro Tip
Success!
# Navigate to an existing project
cd ~/my-project
claude
# Or create a new project folder
mkdir my-new-app
cd my-new-app
claudeStep 5: Send Your First Command
~5 minNow let's send an actual command to Claude Code. Just type in natural language — English or any language Claude supports. Claude Code can read files, edit files, create new files, and run terminal commands. Before modifying files or running commands, it will ask for your approval. Here are three prompt examples for different scenarios. Pick the one that matches your situation and type it in.
Pro Tip
Pro Tip
Pro Tip
Success!
# Example 1: Understand an existing project
> Explain the overall structure and key files in this project
# Example 2: Modify existing code
> Add a function to src/utils/format.ts that formats dates as "January 1, 2025"
# Example 3: Start a new project from scratch
> Set up a Next.js + TypeScript + Tailwind CSS project in this folder
# When Claude Code wants to modify a file or run a command,
# it shows an "Allow?" prompt.
# Type y to approve, n to deny.Step 6: Essential Commands to Know
~3 minBesides natural language chat, Claude Code has built-in slash commands that help you work more efficiently. These are typed directly into the Claude Code prompt.
Pro Tip
Pro Tip
Pro Tip
Success!
# Help — list all available commands
/help
# Clear conversation — start fresh on a new topic
/clear
# Check session cost
/cost
# Compact context — compress long conversations to save tokens
/compact
# Stop current response — if Claude is going on too long
Ctrl+C
...Core Code
Follow these 6 steps to go from zero to your first Claude Code command. After this, you can freely ask Claude to analyze, edit, and generate code using natural language.
# === Claude Code Quickstart — Full Flow Summary ===
# 1. Verify Node.js
node -v # Must be v18 or higher
# 2. Install Claude Code
npm install -g @anthropic-ai/claude-code
# 3. Authenticate (choose one)
claude # Browser OAuth login
# OR
export ANTHROPIC_API_KEY="sk-ant-xxxxx"
# 4. Start in your project folder
cd my-project
...Common Mistakes
Running npm install without Node.js installed
Claude Code runs on Node.js. Install the LTS version from nodejs.org first. After installation, restart your terminal and verify with node -v.
Getting "permission denied" on Mac/Linux and not knowing how to fix it
Run sudo npm install -g @anthropic-ai/claude-code to install with admin privileges. Alternatively, use nvm to manage Node.js — it allows global installs without sudo.
Running claude without authentication and getting auth errors
Claude Code requires authentication. Complete either the browser login (Pro/Max subscription) or set the ANTHROPIC_API_KEY environment variable before running claude.
Running claude in the home directory (~) instead of a project folder
Claude Code operates on files in the current directory. Always cd into your project folder first. Running from the home directory may cause Claude to scan irrelevant files.