What this lesson is about
Claude Code is installed, but it cannot do anything yet. This lesson explains how authentication works, how to set it up correctly, and how to choose the right version of Claude for different types of work.
Why does Claude Code need authentication?
When you use Claude through the website, you log in with your email and password. Claude Code works differently — it connects to Anthropic’s servers using something called an API key.
Think of an API key like a key card for a building. Instead of showing ID at reception every time, you tap your key card and the door opens automatically. The key card is linked to your account so the building knows who you are. An API key works the same way — Claude Code presents it automatically every time it connects. Your API key is private. Anyone who has it can use Claude on your account. Treat it like a password.
Step 1: Get your API key
- Go to console.anthropic.com and sign in
- Click API Keys in the left sidebar
- Click Create Key
- Give it a name — something like “Claude Code on my laptop”
- Copy the key that appears — it will look like
sk-ant-api03-...
Important: This key is shown only once. Copy it immediately and save it in a password manager. If you close the window without copying it, you will need to create a new key.
Step 2: Give the key to Claude Code
Open your terminal and type the following, replacing your-key-here with your actual key:
export ANTHROPIC_API_KEY=your-key-here
This works for your current session only. To make it permanent, add it to your shell profile.
On Mac or Linux:
echo 'export ANTHROPIC_API_KEY=your-key-here' >> ~/.zshrc
On Windows PowerShell:
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY","your-key-here","User")
After this, close your terminal, open a new one, and run claude — it should connect without asking for a key.
Step 3: Choose the right model
Claude comes in three versions. Think of it like hiring a contractor:
Haiku is a fast, efficient assistant. Great for simple, repetitive tasks — quick questions, formatting text, summarising short documents. Costs very little.
Sonnet is a skilled professional. This is what you will use for most of your work — writing, analysis, research, explaining complex topics. It balances quality and cost well.
Opus is a specialist consultant. The most capable, the most expensive, and the slowest. Use it only when you have a genuinely complex problem that Sonnet is struggling with.
In practice, 90% of your work will be done with Sonnet.
How to switch models
Type /model inside a Claude Code session to see a list of available models and select one. You can also set a default model in your CLAUDE.md file (covered in Lesson 3).
Practical Exercise
- Go to console.anthropic.com and create an API key — name it clearly
- Copy the key and save it in a password manager or secure note
- Set the key permanently using the shell profile method above
- Open a new terminal window and run
claude— confirm it connects without asking for a key - Inside a Claude session, type
/modeland look at the options available - Ask Claude the same question on Haiku and then on Sonnet — notice the difference in depth
Common problems and how to fix them
“Authentication error” or “Invalid API key” — You either miscopied the key or it was not saved correctly. Create a new key and follow the steps again carefully.
Claude works in one terminal but not another — You set the key with export but did not add it to your shell profile. It only lasted for that one session. Follow the permanent setup steps above.
“Insufficient credits” error — Your Anthropic account needs credit. Go to console.anthropic.com → Billing and add a payment method.
What you have learned in this lesson
- An API key identifies you automatically so Claude Code can connect without manual login
- Your API key is private — treat it like a password
- Setting the key permanently in your shell profile means you never have to set it again
- Claude has three models: Haiku (fast, simple), Sonnet (daily work), Opus (complex problems)
- You can switch models any time with
/model