Hello Claude Code
Installation
Claude Code requires Node.js 18+ and an Anthropic API key.
npm install -g @anthropic-ai/claude-codeSet 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 --versionClaude 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
claudeThis 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
| Command | What it does |
|---|---|
/help | List all commands |
/compact | Summarize conversation to free up context window |
/clear | Clear conversation history |
/cost | Show token usage and cost for this session |
/model | Switch 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 responsestream-json- newline-delimited JSON, streamed as it's generated
# Stream JSON for real-time processing
claude -p "analyze this codebase" --output-format stream-jsonKey CLI flags
| Flag | Purpose |
|---|---|
claude -p "prompt" | Non-interactive single prompt |
claude -c | Continue last conversation |
claude -c -p "prompt" | Continue last conversation non-interactively |
claude --resume name | Resume a named session |
claude --model claude-sonnet-4-6 | Use a specific model |
claude --max-turns 3 | Limit agentic loop iterations |
claude --output-format json | Structured output |
claude --permission-mode plan | Start 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 madeFor non-interactive continuation:
claude -c -p "did that refactor break any tests?"Name sessions for easy recall:
claude --resume auth-refactorYour first Claude Code session
Part 1: Interactive mode
- Navigate to any project directory (or create a simple one with a few files)
- Run
claudeto start an interactive session - Ask: "What files are in this directory and what do they do?"
- Ask: "What improvements would you suggest for this project?"
- Run
/costto see how many tokens you've used - Exit with
Ctrl+C
Part 2: Non-interactive mode
- Run:
claude -p "what files are in this directory?" - Run:
claude -p "what files are in this directory?" --output-format json - Compare the two outputs
Part 3: Piping
- Run:
ls -la | claude -p "explain what these files are" - Run:
git log --oneline -10 | claude -p "summarize recent project activity"
mkdir test-project && cd test-project && npm init -y && echo "console.log('hello')" > index.js--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.
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-6In interactive mode, use /model to switch mid-session.
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.
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.