Getting Started
15 minutes
linux
macos
windows

Installing Claude Code

Learn how to install Claude Code, set up your API key, and run your first AI-assisted coding session.

What you'll accomplish

Have Claude Code installed and working, ready to assist with your coding.

Prerequisites

  • Node.js installed (from lesson 3)
  • An Anthropic account with API access
  • A credit card for API billing (pay-per-use)

What is Claude Code?

Claude Code is an AI coding assistant that runs in your terminal. You describe what you want to build, and it helps you write the code.

Imagine you're writing an essay and you have a friend who:

  • Knows everything about writing
  • Can suggest what to write next
  • Fixes your grammar and spelling
  • Explains things when you're confused
  • Does research for you

Claude Code is that friend, but for coding. You type what you want, and it helps you create it.

Before You Start

You'll Need an Anthropic API Key

Claude Code connects to Anthropic's API, which costs money based on usage. You'll need:

  1. An Anthropic account: Sign up at console.anthropic.com
  2. API access: Available after signing up
  3. A payment method: You pay for what you use (typically $5-20/month for casual use)
Note

Cost expectations: For learning and small projects, expect to spend $5-20/month. The cost depends on how much you use it. You can set spending limits in your Anthropic account.

When you ask Claude Code a question, your request goes to Anthropic's servers where powerful computers process it. Running these computers costs money, so Anthropic charges based on usage.

Think of it like electricity - you pay for what you use. More questions = more cost, but the cost per question is quite small (fractions of a cent for short requests).

Installing Claude Code

Claude Code is installed via npm (which you installed with Node.js).

Setting Up Authentication

Claude Code supports several authentication methods. The right choice depends on your setup.

Option 1: Environment Variable (Recommended)

Setting the ANTHROPIC_API_KEY environment variable is the most reliable method and works across all environments, including Docker containers and CI/CD pipelines.

Step 1: Get Your API Key

  1. Go to console.anthropic.com
  2. Sign in (or create an account)
  3. Go to "API Keys" in the left sidebar
  4. Click "Create Key"
  5. Give it a name like "Claude Code"
  6. Copy the key (it starts with sk-ant-)
Warning

Important: You can only see the full key once! Copy it immediately and save it somewhere safe. If you lose it, you'll need to create a new one.

Step 2: Set the Environment Variable

Option 2: Interactive Login

If you don't have an environment variable set, Claude Code will prompt you to authenticate when you first run it. You can either:

  • Paste your API key when prompted
  • Follow the interactive login flow (if available in your region)

This is convenient for getting started quickly, but environment variables are more reliable for ongoing use.

If your organization uses Anthropic's enterprise features, you may authenticate via SSO or use organization-managed credentials. Check with your IT administrator for the specific authentication flow. Enterprise environments may use different endpoints or require additional configuration.

Common enterprise setups include:

  • Organization API keys (provided by your admin)
  • SSO-based authentication flows
  • Custom API base URLs

Your organization's documentation will have specific instructions.

Your API key is like a password - anyone who has it can use your account (and charge you money).

Never:

  • Put it in code files that go to GitHub
  • Share it in screenshots or messages
  • Store it in plain text files in your project

Always:

  • Use environment variables
  • Add .env files to .gitignore
  • Regenerate the key if you accidentally expose it

Your First Claude Code Session

Let's try it out!

Step 1: Create a Test Folder

Claude Code works best with Git repositories. By running git init, you:

  1. Enable Claude Code to track what files exist
  2. Allow yourself to undo changes if something goes wrong
  3. Follow best practices from the start

Step 2: Start Claude Code

bash
claude

You'll see a welcome message and prompt. You're now talking to Claude!

Step 3: Ask It to Do Something

Try typing:

Create a simple HTML file that says "Hello World" with some basic styling

Claude Code will:

  1. Think about what you asked
  2. Propose creating a file
  3. Ask for your permission to create it
  4. Show you the result
Note

Claude Code asks permission before making changes. This is a safety feature - you're always in control.

Step 4: View the Result

After Claude creates the file, you can:

bash
# List files to see what was created
ls

# Open in your IDE
code .  # or: cursor .

Step 5: Exit

Type /exit or press Ctrl + C to leave Claude Code.

Understanding Claude Code's Interface

Commands

Type / to see available commands:

CommandWhat it does
/helpShow help information
/clearClear conversation history
/exitExit Claude Code
/diffShow pending changes
/undoUndo the last change

Permission System

When Claude wants to do something, it asks first:

  • Read files: Usually auto-approved
  • Write files: Asks permission
  • Run commands: Asks permission

You can respond:

  • y or yes to approve
  • n or no to reject
  • Type a different instruction to redirect

You can run Claude Code with automatic approval:

bash
claude --dangerously-skip-permissions

This is only recommended when:

  • Running inside a Docker container
  • Working in a disposable environment
  • You fully trust the task and context

We cover safe usage of this flag in the Claude Code Advanced track.

Tips for Better Results

Be Specific

❌ "Make a website" ✅ "Create a landing page with a hero section, three feature cards, and a contact form"

Provide Context

❌ "Fix the bug" ✅ "The login form submits but the user isn't redirected. Look at src/auth/login.ts"

Iterate

Don't expect perfection on the first try. Refine your request:

  1. "Create a button component"
  2. "Make the button larger and add a hover effect"
  3. "Change the color to blue and add an icon"

Ask Questions

Claude Code isn't just for writing code. Ask it to:

  • Explain existing code
  • Suggest improvements
  • Debug problems
  • Review your code

Common Issues

Frequently Asked Questions

Make sure the installation completed successfully:

bash
npm install -g @anthropic-ai/claude-code

If using nvm, make sure a Node.js version is active:

macOS/Linux:

bash
nvm use --lts

Windows (nvm-windows uses different syntax):

powershell
nvm use lts

On Windows, also try opening a NEW PowerShell window after installation.

  1. Check that your key starts with sk-ant-
  2. Make sure you copied the entire key
  3. Verify the key is active in console.anthropic.com
  4. Create a new key if the old one isn't working

You've made too many requests too quickly. Wait a minute and try again.

If this happens often, check your Anthropic account for usage limits.

This is intentional! Claude Code is designed to keep you in control.

If you find it tedious for safe operations, you can configure automatic approvals in settings. See the Claude Code Advanced track for details.

Check your usage at console.anthropic.com.

To control costs:

  • Set spending limits in your Anthropic account
  • Be concise in your requests
  • Use /clear between unrelated tasks

Verify Your Understanding

You've completed this lesson if you can:

0/5

Next: Final verification - let's make sure all your tools work together properly.