The Landscape

Hello Claude Code

Hands-on15 min

Installation

Claude Code requires Node.js 18+ and an Anthropic API key.

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

Set your API key:

export ANTHROPIC_API_KEY="sk-ant-..."

Add that export to your shell profile (~/.zshrc, ~/.bashrc) so it persists across sessions.

Verify the install:

claude --version
API key required

Claude Code connects directly to the Anthropic API. You need a funded account at console.anthropic.com. There is no free tier for Claude Code - you pay per token used.

Interactive mode

Start Claude Code in any project directory:

cd your-project
claude

This opens an interactive session. Type natural language requests, and Claude reads your project, proposes changes, runs commands, and iterates.

Try these in your first session:

> What files are in this project and what does it do?

> Find all TODO comments in the codebase

> What dependencies does this project use?

Type /help to see available slash commands. Type exit or press Ctrl+C twice to quit.

Useful slash commands

CommandWhat it does
/helpList all commands
/compactSummarize conversation to free up context window
/clearClear conversation history
/costShow token usage and cost for this session
/modelSwitch the model mid-session

Non-interactive mode

The -p flag runs a single prompt and exits. This is where Claude Code's terminal-native nature shines.

# Ask a question about your project
claude -p "what framework does this project use?"
 
# Get structured output
claude -p "list all API endpoints" --output-format json
 
# Pipe input to Claude
cat package.json | claude -p "what are the main dependencies?"

The --output-format flag accepts three values:

  • text - plain text (default)
  • json - structured JSON response
  • stream-json - newline-delimited JSON, streamed as it's generated
# Stream JSON for real-time processing
claude -p "analyze this codebase" --output-format stream-json

Key CLI flags

FlagPurpose
claude -p "prompt"Non-interactive single prompt
claude -cContinue last conversation
claude -c -p "prompt"Continue last conversation non-interactively
claude --resume nameResume a named session
claude --model claude-sonnet-4-6Use a specific model
claude --max-turns 3Limit agentic loop iterations
claude --output-format jsonStructured output
claude --permission-mode planStart in plan-only mode

Continuing and resuming sessions

Claude Code remembers your previous session. Use -c to pick up where you left off:

# Start a session, do some work, exit
claude
> refactor the auth module
> exit
 
# Later, continue where you left off
claude -c
> now add tests for the changes you made

For non-interactive continuation:

claude -c -p "did that refactor break any tests?"

Name sessions for easy recall:

claude --resume auth-refactor
Ex

Your first Claude Code session

Part 1: Interactive mode

  1. Navigate to any project directory (or create a simple one with a few files)
  2. Run claude to start an interactive session
  3. Ask: "What files are in this directory and what do they do?"
  4. Ask: "What improvements would you suggest for this project?"
  5. Run /cost to see how many tokens you've used
  6. Exit with Ctrl+C

Part 2: Non-interactive mode

  1. Run: claude -p "what files are in this directory?"
  2. Run: claude -p "what files are in this directory?" --output-format json
  3. Compare the two outputs

Part 3: Piping

  1. Run: ls -la | claude -p "explain what these files are"
  2. Run: git log --oneline -10 | claude -p "summarize recent project activity"
If you don't have a project handy, create a quick one: mkdir test-project && cd test-project && npm init -y && echo "console.log('hello')" > index.js
The --output-format json output includes a result field with the response text and a cost_usd field with the cost.

Expected output for Part 2 (JSON format):

{
  "result": "This directory contains the following files:\n- package.json: ...",
  "cost_usd": 0.003,
  "duration_ms": 1200,
  "num_turns": 1
}

For Part 3, piping works because Claude Code reads from stdin when combined with -p. The pipe content becomes additional context for the prompt.

Ex

Explore model selection

Claude Code defaults to Claude Sonnet. Try switching models:

# Use Sonnet (faster, cheaper)
claude -p "explain this project" --model claude-sonnet-4-6
 
# Use Opus (more capable, slower)
claude -p "explain this project" --model claude-opus-4-6

In interactive mode, use /model to switch mid-session.

Sonnet is the best default for most tasks. Use Opus for complex reasoning, architecture decisions, or when Sonnet's output isn't good enough.

Model choice is a cost/quality tradeoff. Sonnet is roughly 5x cheaper than Opus. Start with Sonnet, upgrade to Opus when you need deeper reasoning. You can also set a default in your settings.

Terminal layout tip

Split your terminal: Claude Code on the left, your editor on the right. Or use tmux/Zellij panes. Claude Code works alongside your editor, not inside it - lean into that.