Module 3 · Page 5 of 7 · 5 minutes

Log in to Claude Code

Claude Code needs to know who you are before it will do any work. Two ways to connect it: log in with a Claude account, or use an API key billed by usage.

Two options

There are two options for accessing Claude Code. Option A is recommended for this course.

Option A: Log in with a Claude account

In Terminal (Mac) or PowerShell (Windows), run:

claude

The first time you run it, Claude Code opens a browser window and asks you to log in — or create an account, if you don't have one — at claude.ai. Approve the request there, then return to your terminal; it's now connected.

A terminal running Claude Code v2.1.233, showing the model line 'Sonnet 5 · Claude Pro' and the result of running /login: 'Login successful'.
What a successful login looks like — the model line confirms which account and plan Claude Code is connected to.

Claude Code isn't available on the Free plan — you'll need at least a Pro plan for this option. For this course, Pro is the recommended choice: it covers everything the exercises ask of you without the extra cost of Max.

Tip Once you're logged in, run /model inside Claude Code to switch between models — for example, a smaller, faster model for quick edits and a larger one for harder problems. Pick from the list that appears, or run /model again anytime to switch back.

Option B: Use an API key instead

An API key bills per request instead of a flat subscription rate — useful if you'd rather pay only for what you use.

Get a key:

  1. Go to console.anthropic.com and sign in — or create an account, if you don't have one.
  2. In the left sidebar, click API Keys.
  3. Click Create Key, give it any name you'll recognize later (e.g. "my laptop"), and confirm.
  4. Copy the key it shows you. It starts with sk-ant- — you won't be able to see it again after you leave this page, so copy it now.

Claude Code reads the key from an environment variable — a value your terminal keeps in memory and hands to any program that asks for it, including Claude Code. There are two ways to set it: for just your current terminal window, or permanently, so it's there every time you open a new one.

Quick version (Mac or Windows, this window only): Paste this into Terminal or PowerShell, with your real key in place of the placeholder, and press Enter. It only lasts until you close the window.

Mac (Terminal):

export ANTHROPIC_API_KEY="sk-ant-your-key-here"

Windows (PowerShell):

$env:ANTHROPIC_API_KEY="sk-ant-your-key-here"

Permanent version, Mac (recommended if you're using an API key):

  1. Open Terminal.
  2. ~/.zshrc is a hidden configuration file in your home folder that Terminal automatically runs every time you open a new window — this is where permanent settings like this one live. You don't need to find or open it yourself; the command below appends a line to it for you. Copy the command exactly, replace sk-ant-your-key-here with your real key, then paste it into Terminal and press Enter:
    echo 'export ANTHROPIC_API_KEY="sk-ant-your-key-here"' >> ~/.zshrc
  3. Close Terminal completely and reopen it — the file only gets read when a new window starts.
  4. Verify it worked:
    echo $ANTHROPIC_API_KEY
    It should print the key back to you.

Permanent version, Windows:

  1. Open PowerShell.
  2. Replace sk-ant-your-key-here with your real key, then paste this into PowerShell and press Enter. This saves it as a permanent setting on your account, similar to how the Mac version writes to a config file:
    [System.Environment]::SetEnvironmentVariable('ANTHROPIC_API_KEY', 'sk-ant-your-key-here', 'User')
  3. Close PowerShell completely and reopen it.
  4. Verify it worked:
    echo $env:ANTHROPIC_API_KEY
    It should print the key back to you.
Treat this like a password Never share an API key or commit it to a file an agent might upload, email, or push to GitHub. Anyone with the key can spend against your account.

Which should you use?

For this course, Option A is simpler: a flat, predictable cost with no billing setup. Option B is for your future reference.

Next · Page 6 of 7
Using Claude Code in VS Code