ASK KNOX
beta
LESSON 41

Installing Claude Code

Node.js, an API key, one npm command, and you're running. This lesson walks every step of the installation with the exact commands and what to expect when each succeeds.

7 min read·Getting Started with Claude Code

Installation is the smallest possible barrier between you and your first Claude Code session. Four steps, one terminal window, under five minutes. This lesson walks each step with the exact commands and what to expect when things go right.

Installing Claude Code

Step 1: Verify Node.js

Claude Code requires Node.js version 18 or higher. It is distributed as an npm package, so Node.js is a hard dependency.

Check what you have:

node --version

If you see v18.x.x, v20.x.x, or higher — you are ready. If you see v16.x.x or lower, or if node is not found, you need to install or upgrade.

Installing Node.js: Visit nodejs.org and download the current LTS (Long Term Support) release. The LTS version is always 18+ and is the recommended option for most users. If you are on macOS, Homebrew also works: brew install node.

After installation, close and reopen your terminal, then run node --version again to confirm.

Step 2: Get Your Anthropic API Key

Claude Code connects to Anthropic's API to access the Claude model. You need an API key to authenticate.

  1. Go to console.anthropic.com and create an account (or sign in).
  2. Navigate to API Keys in the left sidebar.
  3. Click Create Key, give it a name (e.g., "claude-code-local"), and copy the key.

Your key starts with sk-ant-api.... Store it somewhere safe — Anthropic shows it once.

API costs: Claude Code is billed per token. A typical session costs $0.05–$0.50 for simple tasks, $1–5 for complex multi-file work. Anthropic's pricing page has current rates. Set a monthly spend limit in the console under Billing → Usage Limits to stay in control.

Step 3: Set the API Key in Your Environment

Claude Code reads your API key from the environment variable ANTHROPIC_API_KEY. You can set it for the current session:

export ANTHROPIC_API_KEY=sk-ant-api...your-key-here

To make this permanent (so you never have to set it again), add it to your shell profile. For macOS/Linux with zsh:

echo 'export ANTHROPIC_API_KEY=sk-ant-api...your-key-here' >> ~/.zshrc
source ~/.zshrc

For bash:

echo 'export ANTHROPIC_API_KEY=sk-ant-api...your-key-here' >> ~/.bashrc
source ~/.bashrc

After this, every new terminal session will have the key set automatically.

Alternative: Interactive authentication. When you first run claude, it will prompt you to authenticate if no API key is found in the environment. You can enter your key interactively and Claude Code will store it in ~/.claude/ for future sessions. Either approach works.

Step 4: Install Claude Code

One command:

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

The -g flag installs it globally, meaning the claude command becomes available anywhere on your system. Installation takes about 10–30 seconds depending on your connection.

When it finishes, you should see something like:

added 1 package in 12s

Verify the installation:

claude --version

This prints the installed version. If you see a version number, installation succeeded.

Step 5: Run Claude for the First Time

Navigate to a project directory — or create a new one:

mkdir my-first-project
cd my-first-project
claude

Claude Code launches an interactive session in your terminal. If your API key is configured, you will see a welcome message and a prompt. If it needs to authenticate, follow the interactive prompts.

Type your first message:

> What files are in this directory?

Claude will use the Bash tool to run ls and report back. That is your first agentic interaction.

Troubleshooting Common Issues

"claude: command not found" — The global npm bin directory is not in your PATH. Run npm bin -g to find where global packages install, and add that directory to your PATH. On macOS with Homebrew Node, this is typically /opt/homebrew/bin.

"Invalid API key" — Double-check that your key starts with sk-ant-api and that there are no extra spaces. Re-export it in your current terminal session even if it is in your profile, then try again.

"Unexpected token" or JS errors on launch — Your Node.js version is too old. Run node --version to confirm, then update to v18+.

Slow first launch — Claude Code downloads some assets on first run. Subsequent launches are faster.

The Configuration Directory

Claude Code stores its configuration at ~/.claude/. This includes:

  • Authentication credentials — your API key if entered interactively
  • Global settings — default model, permission mode, UI preferences
  • Session history — recent sessions for reference

You can edit ~/.claude/settings.json directly to change defaults. The available settings are documented in claude --help settings.

Lesson 41 Drill

Confirm you are fully set up by running through this checklist in your terminal:

node --version        # should be v18+
npm --version         # should be v8+
claude --version      # should show installed version
echo $ANTHROPIC_API_KEY | head -c 20  # should show sk-ant...

Then create a test directory and start your first session:

mkdir ~/claude-test && cd ~/claude-test
claude

Type: Create a file called hello.txt with the text "Claude Code is running." — Claude should create the file. Run cat hello.txt to verify.

Bottom Line

Installation is four steps: Node.js 18+, Anthropic API key, npm install -g @anthropic-ai/claude-code, and claude in your terminal. There is no IDE plugin, no browser extension, no account on a third-party platform. Once configured, you run it from any project directory and start working immediately.

Lesson 42 covers your first real session — how to give Claude tasks, read its tool calls, and understand what is happening as it works.