Vibe coding with AI course Β· Module 15: Claude Code CLI

Meet Claude Code - Your AI in the Terminal

13 min read
In this lesson10

Welcome aboard the final module! Captain Redbeard saved the most powerful compass in the whole fleet for last: Claude Code - the official CLI tool from Anthropic that turns your terminal into an agentic coding crewmate.

What is Claude Code?

Claude Code is an agentic command-line tool (CLI - Command Line Interface) built by Anthropic. It is not an ordinary chat window - Claude Code can read and edit the files in your project on its own, run commands in your terminal and carry out complex tasks across many files at once.

That is worth saying plainly, because tutorials muddle it: Claude Code is not a browser extension, not a frontend library for building interfaces, and certainly not an operating system for servers. It is a program you launch from the command line, and it works on your real codebase.

Think of the difference between a treasure map and a living navigator who actually sails the ship where it needs to go.

Claude Code vs Cursor

Both crews sail the same AI sea, but each one steers differently:

Cursor:

  • An AI-powered code editor with a graphical interface (GUI), built as a fork of VS Code
  • Inline edits, Tab autocomplete, Agent/Composer mode, @-mentions
  • Great for writing code live, right inside the editor

Claude Code:

  • An agentic command-line tool (CLI) and SDK
  • Lives in the terminal
  • Great for autonomous multi-file changes, automation, CI/CD and composing with other shell commands
  • Works with any editor you like (plus extensions for VS Code and JetBrains)

These are not the same tool, and neither replaces the other - they complement each other, so you can sail with BOTH at once!

Installing Claude Code

Requirements

  • System: macOS 13+, Windows 10 (1809+), Ubuntu 20.04+, Debian 10+ or Alpine 3.19+, with at least 4 GB of RAM
  • Account: a Claude subscription (Pro, Max, Team or Enterprise) or an Anthropic Console account with API credits
  • Node.js only if you install through npm: version 22 or newer (check it with node --version)

Anthropic recommends the native installer: one command downloads a ready-made program that then keeps itself up to date. Pick the line for your system:

# macOS, Linux, WSL
curl -fsSL https://claude.ai/install.sh | bash

# Windows PowerShell
irm https://claude.ai/install.ps1 | iex

When it finishes, open a new terminal window and type claude --version. If the terminal does not know the claude command, the install directory is not on your PATH yet - the Claude Code documentation has a separate page about installation problems. On a Mac you can also use Homebrew (brew install --cask claude-code), and on Windows WinGet (winget install Anthropic.ClaudeCode).

Install with npm

Claude Code also ships as an npm package. Watch the package name closely - it is scoped, @anthropic-ai/claude-code, never a bare claude or claude-code. It installs with npm - pip belongs to a different ocean entirely:

# Install with npm (needs Node.js 22 or newer)
npm install -g @anthropic-ai/claude-code

# Then start Claude Code inside your project directory
claude

The -g flag is what makes the install global: the claude command becomes available in every directory, not just this one. Do not put sudo in front of npm install - that is the shortest route to permission trouble.

You can also run Claude Code without installing anything globally, straight through npx:

npx @anthropic-ai/claude-code

This downloads the package on demand, for a single voyage (it also needs Node.js 22 or newer) - handy when you are testing the tool on a borrowed machine, but for daily work pick the native installer or the global install.

Signing in

The first time you launch it, Claude Code asks you to sign in. Type this command inside the session:

/login

That opens an OAuth flow in your browser - sign in with a Claude Pro/Max subscription, or with an Anthropic Console account backed by API credits. Note what /login does not do: it does not create a GitHub account for you, it does not log you out of your operating system, and it installs no dependencies. It signs you in to Claude, nothing more.

If you would rather authenticate with an API key from the Anthropic Console, set it in the ANTHROPIC_API_KEY environment variable. Claude Code does not read keys from a .env file in your project - if anything, such a file is worth protecting from Claude, because it can read your project files. Here is how to set the variable:

# macOS/Linux - add this line to ~/.zshrc or ~/.bashrc
export ANTHROPIC_API_KEY="sk-ant-..."

# Windows PowerShell - save the variable permanently for your account
[Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", "sk-ant-...", "User")

The key belongs in the environment - never in package.json, never in some committed config.json. Those files sail straight into your repository, and a leaked key is a leaked treasure chest. After saving the variable, open a new terminal: from then on the key loads by itself in every session, and on the first launch Claude Code asks whether it should use it.

The first voyage

With the install done and the articles signed, you are ready to call your first mate for real:

# Start an interactive session (REPL) in the terminal
claude

# Or jump straight in with an opening prompt
claude "Explain what TypeScript is"

Both lines start Claude Code in the current directory, which becomes the project it can see. The second form simply saves you a step by handing over the first question immediately.

Claude models

Claude Code runs on the Claude family of models, and each one suits a different kind of voyage. The easiest way to pick one is by its short name (alias), which always points at the current version:

  • fable - the most capable, for the biggest and longest tasks (today Claude Fable 5.1; on some plans it bills to usage credits)
  • opus - a very strong model for complex work, and the default on the Pro, Max, Team and Enterprise plans (today Claude Opus 5.5)
  • sonnet - a balanced model for everyday coding (today Claude Sonnet 5.5)
  • haiku - the fastest, for simple questions (today Claude Haiku 4.5)

Most of the time you switch models in one of two ways: with the /model command inside a session, or with the --model flag when you launch:

# Launch with a specific model
claude --model sonnet

The short name is all you need - sonnet, opus, haiku or fable. To make the choice permanent, use the model field in a settings file or the ANTHROPIC_MODEL environment variable. What you will not find is a /temperature command or a temperature setting to tune. The second dial is the effort level: the --effort flag or the /effort command, with low, medium, high, xhigh or max, decides how long the model thinks about each step (on models that support it).

Running modes

Claude Code has two main modes: interactive mode, claude (also with an opening prompt: claude "question"), and non-interactive, one-shot mode, claude -p "question", which answers once and exits. You will not find a "GUI mode" in the CLI: the graphical versions of Claude Code (the desktop app and the editor extensions you will meet at the end of this module) are separate apps and extensions, not a way of launching the CLI.

Interactive mode (REPL)

This is the default: a genuine conversation in the terminal, where Claude remembers everything said so far.

# Start a session in the terminal
claude

# Or with an opening prompt
claude "Help me build a login form"

Inside this session Claude keeps the context of the whole conversation, so you can refine your request step by step - "now add validation", "now write the tests" - without repeating yourself.

Non-interactive mode (-p / --print)

The -p flag (or its full name, --print) makes Claude print the answer and exit - exactly what you want in scripts and pipes. The "p" stands for printing to the terminal, not for a paper printer, and nothing gets deleted along the way:

# Ask a question, get the answer, done
claude -p "Explain what React hooks are"

# The same thing with the full flag name
claude --print "Summarize how useEffect works"

Because the process ends as soon as the answer is out, you can put these commands in a shell script, a Makefile or a CI pipeline and treat Claude like any other command-line tool.

Continuing conversations

Sessions are saved automatically - there is no --save flag to remember and nothing to restore by hand:

# Continue the most recent conversation in this directory
claude -c

# Pick an earlier conversation to resume
claude -r

Use -c when you closed the terminal mid-task and want to pick the thread straight back up, and -r when you want to browse the list of past sessions and choose one.

Working with files - the @ reference

Here is a truth worth tattooing on your forearm: Claude Code has no separate flag for attaching files. You point at a file inside the prompt itself, with the @ symbol, and Claude reads it on its own:

# Claude reads src/auth.ts and reviews it
claude -p "Review @src/auth.ts"

# You can point at several files at once
claude -p "Compare @src/old-api.ts and @src/new-api.ts"

Notice how the @ sits right in the prompt text, as part of the sentence you are writing. Claude can also search and read files by itself using its own tools, so you rarely need to list them all - name the ones that matter and let it find the rest. To give it access to a directory outside the project, use the --add-dir flag. Mind the order: --add-dir takes several paths at once and treats everything after it as more directories. So the quoted prompt goes before the flag: claude, the prompt, --add-dir, and the directory path last:

claude "Review the shared code" --add-dir ../shared-library

Now the shared library is part of the map: Claude may read and edit files there too, which is exactly what you need in a monorepo or when two projects share a package.

Piping data in

Because Claude Code lives in the terminal, you can chain it to any other command with a pipe (|), letting the output of one program become Claude's input:

# Pipe a file in for review
cat src/index.ts | claude -p "Review this code"

# Pipe a Git diff in for a summary
git diff | claude -p "Summarize these changes"

This replaces a trick that haunts old tutorials: instead of claude --file X "Y", which attaches nothing, write cat X | claude -p "Y" or claude -p "Y @X". It is also how an automated code review works in practice - a small code-review.sh script pipes the staged files into claude -p and reports bugs, security issues and best-practice violations before the commit ever lands.

The captain's toolbelt - the real flags

A handful of flags cover almost everything you will do from the command line, and they are worth learning as a set:

# Pick the model
claude --model sonnet

# Add a directory to the context
claude --add-dir ./packages

# Control how permissions are granted
claude --permission-mode plan

# Restrict which tools Claude may use
claude --allowedTools "Read,Edit"

# Change the output format (great for scripts and CI)
claude -p "review @src/app.ts" --output-format json

Those are genuine. Beware the kraken of invented flags: guides on the web cheerfully show a "temperature" flag, a "max-tokens" flag, an "output" flag or a "file" flag for attaching files - none of them works that way. If a tutorial sails by that map, it will run you aground.

Slash commands - commands inside a session

Once you are inside an interactive session (claude), you steer with slash commands - commands that begin with /. These are the real ones:

  • /help - the list of available commands and help
  • /clear - wipe the context and start fresh
  • /compact - summarize the conversation so far and carry on, saving context
  • /init - generate a CLAUDE.md file for the project
  • /model - switch the Claude model
  • /config - settings
  • /login - sign in
  • /usage - show the session cost and your plan's usage limits (/cost is an alias)
  • /context - show how much context the conversation takes up
  • /code-review (alias /review) - review the changes on your branch, or a Pull Request by its number
  • /mcp - manage MCP servers
  • /memory - edit the CLAUDE.md file

Your own skills appear here too, as /<skill-name> - a skill called deploy runs as /deploy.

Watch out: the /file and /save commands do not exist in Claude Code - if you met them in an older guide, someone made them up. You point at files with @, you manage context with /clear and /compact, and /context shows you how much of it you are using.

CLAUDE.md - the project memory

CLAUDE.md is a markdown file in the root of your project, where you write down your conventions, your architecture and the commands the crew uses daily. Claude Code loads it automatically in every session, so your first mate knows the ship from the very first message instead of asking the same questions again.

# Generate CLAUDE.md automatically
# (type this command inside a claude session)
/init

The /init command inspects the project and drafts the file for you - then you edit it by hand to add the rules only you know. You can also keep a global ~/.claude/CLAUDE.md that applies to every project, plus nested CLAUDE.md files inside subdirectories for rules that are local to one part of the codebase.

Summary

Claude Code - an agentic CLI from Anthropic (reads and edits files, runs commands) Install - the native installer (curl -fsSL https://claude.ai/install.sh | bash, on Windows irm https://claude.ai/install.ps1 | iex) or npm install -g @anthropic-ai/claude-code, then claude Sign in - /login (Claude Pro/Max or Console) or the ANTHROPIC_API_KEY variable Modes - interactive (claude) vs one-shot and non-interactive (claude -p "...") Files - point with @file, chain with a pipe (cat file | claude -p "...") Slash commands - /help, /clear, /compact, /init, /model, /code-review CLAUDE.md - the project memory, generated by /init

Open the editor below and study the example commands - every one of them is a real form you have just learned. In the next exercise you will put a genuine Claude Code workflow to sea!

See you on deck, sailor!

Code for this lesson: example-usage.sh
#!/bin/bash
# Example: Real Claude Code usage

# 0) Install once - the native installer is recommended (macOS, Linux, WSL)
curl -fsSL https://claude.ai/install.sh | bash
# ...or with npm (needs Node.js 22 or newer)
npm install -g @anthropic-ai/claude-code

# 1) Interactive REPL
claude

# 2) Interactive with an initial prompt
claude "Explain React hooks"

# 3) Non-interactive (print and exit) - for scripts and pipes
claude -p "List the npm scripts in this project"

# 4) Continue the latest session / resume a past one
claude -c
claude -r

# Pick a model (fable | opus | sonnet | haiku)
claude \
  --model sonnet

# Reference a file with @ (no flag attaches local files)
claude -p "explain @src/auth.ts"

# Pipe data straight into Claude
cat src/api/users.ts | claude -p "summarize this module"
git diff | claude -p "find potential bugs in this diff"

# Add an extra directory to context
claude \
  --add-dir ../shared-lib

# Headless output for CI/scripts
claude -p "review @src/payment.ts" --output-format json

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. Main difference between Claude Code and Cursor?

  2. 2. What is Claude Code?

These are 2 of 10 questions for this lesson. Solve the rest in the game.

Hands-on tasks in the game

  • Click in order

    Click the elements in order to build the command for installing Claude Code globally:

  • Click in order

    Click the elements in order to run Claude Code without a global install:

  • Horizontal ordering

    Arrange the command that pipes a file to Claude Code for review:

  • Horizontal ordering

    Arrange the command that asks a question in non-interactive (print) mode:

  • Click in order

    Click the elements in order to type the command that lists available commands and help:

  • Click in order

    Click the elements in order to build a command that reviews a file via an @ reference:

  • Code editor

    In commands.sh write the code-review.sh script: get the staged changes (git diff --cached), pipe them into claude -p and ask it to point out bugs and security issues.

  • Click in order

    Click the elements in order to run Claude with the Sonnet model:

  • Horizontal ordering

    Arrange the command that gives Claude access to an additional directory:

Useful articles