What Is Claude Code
Claude Code is a command-line tool built by Anthropic that runs Claude directly in your terminal. Unlike Cursor or GitHub Copilot — which work inside an editor — Claude Code operates at the filesystem level. It can read, write, and edit files across your entire project, run shell commands, execute tests, and iterate on its own output until the task is complete.
The core difference from other AI coding tools:
| Tool | Where it runs | File access | Runs commands |
|---|---|---|---|
| GitHub Copilot | Inside editor | Current file only | No |
| Cursor | Inside editor | Open files + context | Limited |
| Claude Code | Terminal | Entire filesystem | Yes |
| Windsurf | Inside editor | Project-wide | Limited |
Claude Code is designed for tasks that span multiple files, require running tests, or need shell access — the class of tasks where chat-based tools require too much manual copy-paste.
Prerequisites
- Node.js 18 or higher
- An Anthropic API key (get one here)
- A Unix-like terminal (macOS, Linux, or WSL2 on Windows)
- Basic comfort with the command line
Verify your Node version:
node --version
# Should output v18.0.0 or higher
Installation
Step 1: Install Claude Code globally
npm install -g @anthropic-ai/claude-code
Verify the installation:
claude --version
Step 2: Authenticate
claude
On first run, Claude Code will prompt you to authenticate. You have two options:
Option A — API key directly:
export ANTHROPIC_API_KEY=sk-ant-your-key-here
Add this to your ~/.zshrc or ~/.bashrc to make it permanent:
echo 'export ANTHROPIC_API_KEY=sk-ant-your-key-here' >> ~/.zshrc
source ~/.zshrc
Option B — Interactive login:
Run claude and follow the browser-based OAuth flow. Recommended if you are on a shared machine or prefer not to expose the key in your shell config.
Step 3: Verify authentication
claude --print \"Say hello in one word\"
If you see a response, Claude Code is working correctly.
Core Concepts
Interactive mode vs print mode
Claude Code has two main modes:
Interactive mode — opens a chat-like session in your terminal:
claude
Print mode — runs a single task and exits, useful for scripts:
claude --print \"your task here\"
How Claude Code sees your project
When you run claude inside a project directory, it automatically reads:
- Your directory structure
package.json,pyproject.toml, or equivalent config filesREADME.mdif present- Files you explicitly reference in your prompt
It does not read every file upfront — it fetches files as needed during the task. For large projects this matters: Claude Code explores your codebase progressively rather than loading everything into context at once.
The CLAUDE.md file
Creating a CLAUDE.md file in your project root gives Claude Code persistent context about your project. Think of it as a briefing document:
# Project: AIToolsTutorial
## Stack
- Next.js 16 with App Router
- TypeScript
- Tailwind CSS 4
- Sanity CMS for content
## Conventions
- Components go in app/components/
- UI primitives go in app/components/ui/
- Always use CSS variables from globals.css, never hardcode colors
- All new components need \"use client\" if they use hooks or event handlers
## Commands
- Dev server: npm run dev
- Build: npm run build
- Lint: npm run lint
## Do not touch
- app/studio/ (Sanity Studio)
- app/api/ (backend routes)
Claude Code reads CLAUDE.md automatically at the start of every session. Well-written CLAUDE.md files dramatically reduce the need to re-explain context on every task.
Your First Tasks
Task 1: Understand a codebase
Navigate to any project and run:
cd your-project
claude
Then ask:
Give me a high-level overview of this codebase. What does it do, how is it structured, and what are the most important files?
Claude Code will explore the directory, read key files, and produce a summary. This is useful when joining a new project or returning to code you have not touched in months.
Task 2: Fix a bug
The newsletter signup form at app/components/NewsletterForm.tsx is not validating email format before submission. Add client-side email validation that shows an inline error message below the input field. Match the existing dark styling.
Claude Code will:
- Read the current
NewsletterForm.tsx - Read relevant CSS or style files
- Write the updated component
- Confirm what it changed
Task 3: Add a feature across multiple files
Add a reading progress bar to article pages. It should appear at the top of the viewport, fill left to right as the user scrolls, use color var(--accent), and disappear when the user reaches the bottom of the article.
This task touches at least three files: a new component, the article page, and possibly globals.css. Claude Code handles the coordination automatically.
Task 4: Run tests and fix failures
Run the test suite, identify any failing tests, and fix them. Do not change the test files — only fix the implementation.
Claude Code will execute npm test (or your configured test command), read the output, identify failures, and attempt fixes — iterating until tests pass or it determines it needs more information from you.
Useful Flags and Commands
--print for scripting
# Generate a commit message from staged changes
git diff --staged | claude --print \"Write a conventional commit message for these changes\"
# Review a file before committing
claude --print \"Review app/components/ArticleCard.tsx for potential bugs and accessibility issues\"
--continue to resume a session
claude --continue
Resumes the most recent conversation, preserving all context. Useful when you close the terminal mid-task and want to pick up where you left off.
/clear to reset context
Inside an interactive session:
/clear
Resets the conversation context without closing the session. Use this when switching to a completely different task to avoid context contamination.
/cost to check token usage
/cost
Shows how many tokens the current session has used and the approximate cost. Useful for monitoring spend during long sessions.
Workflows That Save the Most Time
Workflow 1: PR review
git diff main...feature-branch | claude --print \"Review this diff. Identify bugs, suggest improvements, and flag anything that does not follow the project conventions in CLAUDE.md\"
Workflow 2: Documentation generation
claude --print \"Read all files in app/components/ui/ and generate a markdown documentation file that describes each component, its props, and a usage example\"
Workflow 3: Refactor with safety net
Refactor the ArticleFilters component to use useReducer instead of multiple useState calls. Run the dev server after the refactor and tell me if there are any TypeScript errors.
Workflow 4: Database migration
I need to add a 'views' field to the post schema in Sanity. Update the schema file, update all queries that fetch posts to include the views field, and update the TypeScript interfaces that represent a post.
Managing Costs
Claude Code uses Claude Sonnet 4.6 by default, which costs $3/$15 per 1M tokens. Sessions can become expensive for large tasks.
Tips to control costs:
- Write specific prompts — vague prompts cause Claude Code to explore more files than necessary
- Use
CLAUDE.mdto pre-load context so Claude does not have to rediscover it - Use
/costregularly during long sessions - Use
--printfor single tasks instead of long interactive sessions - Break large tasks into smaller, focused steps
A typical bug fix costs $0.05–0.20. A large refactor across many files can cost $1–3. A full codebase analysis costs $0.50–1.50.
Common Issues and Fixes
Claude Code is not finding my files
Make sure you are running claude from your project root, not a subdirectory. Claude Code uses the current working directory as the project root.
Authentication keeps expiring
If you set ANTHROPIC_API_KEY in your shell config, verify it is being loaded:
echo $ANTHROPIC_API_KEY
If it is empty, your shell config change did not load. Run source ~/.zshrc or open a new terminal.
Claude Code is making changes I did not want
Use version control. Always run Claude Code on a clean branch:
git checkout -b claude-task/fix-newsletter-form
claude
# review changes
git diff
# commit or discard
The task is taking too long or seems stuck
Press Ctrl+C to interrupt. Claude Code will stop mid-task. You can then ask it to explain what it was doing or restart with a more specific prompt.
FAQ
Does Claude Code work on Windows?
Natively on WSL2 (Windows Subsystem for Linux). Running directly in PowerShell or CMD is not officially supported. Install WSL2 and run Claude Code inside a Linux environment.
Can Claude Code access the internet?
No. Claude Code operates on your local filesystem only. It cannot fetch URLs, call external APIs, or browse the web during a session.
Is my code sent to Anthropic?
Yes — the files Claude Code reads are sent to Anthropic's API as part of the prompt. Review Anthropic's privacy policy and your organization's data policies before using Claude Code on proprietary codebases.
Which Claude model does Claude Code use?
Claude Sonnet 4.6 by default as of 2026. You can check the current default in the Claude Code documentation.
Can I use Claude Code with a local model?
Not officially. Claude Code is designed specifically for Anthropic's API. For local model inference, tools like Aider with Ollama are the current alternative.
Sources
Next read: Best AI Coding Assistants in 2026: Cursor vs Windsurf vs GitHub Copilot vs Zed