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:
- An Anthropic account: Sign up at console.anthropic.com
- API access: Available after signing up
- 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
- Go to console.anthropic.com
- Sign in (or create an account)
- Go to "API Keys" in the left sidebar
- Click "Create Key"
- Give it a name like "Claude Code"
- 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
.envfiles 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:
- Enable Claude Code to track what files exist
- Allow yourself to undo changes if something goes wrong
- Follow best practices from the start
Step 2: Start Claude Code
bashclaude
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:
- Think about what you asked
- Propose creating a file
- Ask for your permission to create it
- 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:
| Command | What it does |
|---|---|
/help | Show help information |
/clear | Clear conversation history |
/exit | Exit Claude Code |
/diff | Show pending changes |
/undo | Undo 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:
yoryesto approvenornoto reject- Type a different instruction to redirect
You can run Claude Code with automatic approval:
bashclaude --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:
- "Create a button component"
- "Make the button larger and add a hover effect"
- "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:
bashnpm install -g @anthropic-ai/claude-code
If using nvm, make sure a Node.js version is active:
macOS/Linux:
bashnvm use --lts
Windows (nvm-windows uses different syntax):
powershellnvm use lts
On Windows, also try opening a NEW PowerShell window after installation.
- Check that your key starts with
sk-ant- - Make sure you copied the entire key
- Verify the key is active in console.anthropic.com
- 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
/clearbetween unrelated tasks
Verify Your Understanding
You've completed this lesson if you can:
Next: Final verification - let's make sure all your tools work together properly.