How to Use Claude Code: A Practical Guide for 2026
Claude Code is Anthropic's terminal-based agentic coding tool. It can read your codebase, run shell commands, edit files, and work through multi-step tasks end-to-end. This is a practical setup and usage guide — what to install, how to configure it, and how to actually get work done with it.
What Claude Code does
Claude Code runs in your terminal, not in an editor. You give it a task in plain language — "refactor this module to use the new API", "add tests for this function", "find all the places we're logging user email and remove them" — and it reads the relevant files, reasons about what needs to change, edits the files, and runs commands to verify.
It's built for tasks that require multi-file understanding: refactors, migrations, debugging complex issues, adding features that touch several parts of the codebase. For single-line inline completions, a tool like Cursor or Copilot is faster. Claude Code's advantage is the agentic loop — it keeps working until the task is done, not just until it fills the current line.
Installation
Install via npm
Claude Code requires Node.js 18 or later.
npm install -g @anthropic-ai/claude-code
Verify the install:
claude --version
Set your Anthropic API key
You need an Anthropic account and an API key from console.anthropic.com. New accounts include free credits.
export ANTHROPIC_API_KEY=sk-ant-api03-...
To persist across terminal sessions, add it to your shell profile (~/.zshrc or ~/.bashrc):
echo 'export ANTHROPIC_API_KEY=sk-ant-api03-...' >> ~/.zshrc
source ~/.zshrc
Navigate to your project and start Claude Code
cd /path/to/your/project
claude
Claude Code opens an interactive session. Type your task in plain language and press Enter.
Your first real task
Once Claude Code is running, you interact by describing what you want. Some examples that work well out of the box:
> What does this codebase do? Give me a 3-paragraph summary.
> Find all the TODO comments in the src/ directory and list them.
> Add input validation to the createUser function in auth/user.go.
> Run the test suite and fix any failing tests.
Claude Code will read files, show you what it's doing, ask for confirmation before making changes (depending on your settings), and execute shell commands when needed.
Setting up CLAUDE.md for better results
CLAUDE.md is a project-level context file that Claude Code reads at the start of every session. Without it, Claude Code has to figure out your project structure from scratch each time. With it, you're getting a warm start — Claude Code already knows your stack, conventions, and what to avoid.
Create a CLAUDE.md in your project root:
touch CLAUDE.md
A minimal effective CLAUDE.md:
# Project context
## Stack
- Go 1.22, Postgres 15, Redis
- Deployment: Fly.io
- Frontend: None — API-only service
## Key files
- main.go — entry point + HTTP router
- db/migrations/ — schema migrations (use goose)
- internal/auth/ — auth + JWT logic
## Conventions
- All errors returned, not panicked
- Context passed as first argument to every function
- No ORM — raw SQL with pgx
## What to avoid
- Don't modify db/migrations/ directly — create new migration files
- Don't add dependencies without asking first
The more specific, the better. Context that tells Claude Code what NOT to do is as valuable as context about what your stack looks like.
~/.claude/CLAUDE.md for preferences that apply across all projects — preferred coding style, banned patterns, personal workflow notes. Project CLAUDE.md takes precedence on conflicts.
Useful commands during a session
Claude Code has several slash commands you'll use regularly:
/compact— Compress conversation history to save context space. Use this every 30–60 minutes on long sessions. Without it, context bloat will slow things down and eventually break the session./clear— Reset the conversation completely. Use when you're switching to an unrelated task./model— Switch the active model tier. Useful if you want to drop to Sonnet for routine work and save cost./cost— Shows token usage and estimated cost for the current session./help— List all available commands.
Controlling what Claude Code can touch
By default, Claude Code asks for permission before writing files or running shell commands. You can adjust this:
- Auto-approve file edits in a known safe project:
claude --allow-edits - Auto-approve shell commands:
claude --allow-shell - Fully autonomous mode:
claude --dangerously-skip-permissions— use this only in sandboxed environments or when you trust the task completely.
For the first few sessions in any new project, keep permissions at the default (ask each time). Once you understand how Claude Code behaves with your codebase, you can open up more autonomy.
Task types where Claude Code excels
- Large refactors. Moving a module, renaming a type across 20 files, updating an API contract everywhere it's used — tasks that require holding the whole codebase in mind.
- Codebase exploration. "Where does this variable come from?" / "What calls this function?" / "What does the authentication flow look like?" — Claude Code is fast at navigating an unfamiliar codebase.
- Debugging. Describe the symptom, let Claude Code trace through the code and form a hypothesis. Better than grepping if the issue involves multiple interacting components.
- Writing tests. Generate tests for existing functions. Claude Code can read the implementation and write meaningful assertions, not just boilerplate.
- Shell scripting and automation. Ask it to write a script, run it, debug it, and iterate until it works.
Where Claude Code struggles
- Inline completions. If you want to complete the current line as you type, use Cursor or Copilot. Claude Code isn't designed for that latency.
- Very long sessions. Context limits are real. Sessions longer than a few hours start to degrade as the context window fills up. The fix is
/compactand session portability. - Novel frameworks it hasn't seen. If your stack is very new or internal-only, Claude Code may make incorrect assumptions. CLAUDE.md context and explicit correction help, but there's a ceiling.
The context limit problem
This is the most common frustration with Claude Code. In a long session, the conversation history and open file contents fill the context window. When it's full, either the session degrades (older context gets dropped silently) or it errors out entirely and you have to restart.
The practical mitigations:
- Use
/compactevery 30–60 minutes on long sessions - Keep CLAUDE.md tight — only include context that's actively relevant
- Break large tasks into independent sessions with clear hand-off state
- Use a session harness to export working state and reimport it after a reset
Working with MCP servers
Claude Code supports the Model Context Protocol (MCP), which lets you connect it to external tools and data sources. If you have an MCP server — a database connector, a Slack integration, an internal knowledge base — you can wire it into Claude Code so it has access during sessions.
Add MCP servers to your Claude Code config:
# ~/.claude/config.json
{
"mcpServers": {
"postgres": {
"command": "npx",
"args": ["@modelcontextprotocol/server-postgres", "postgresql://localhost/mydb"]
}
}
}
Once configured, Claude Code can query your database directly, search your docs, or call your internal APIs as part of solving tasks. The MCP ecosystem is growing fast — check the MCP registry for available servers.
Practical workflow tips
- Be specific about scope. "Fix the bug in the login flow" is harder than "The login endpoint at /auth/login returns 500 when the password has a special character. Fix it." The more context you provide upfront, the fewer clarifying loops.
- Ask for a plan first. For big tasks: "Before making any changes, show me your plan for what you'd do." Review it, redirect if needed, then say "go ahead." This avoids surprises in large refactors.
- Use the session for a whole task, not one command. Claude Code builds up context within a session. If you're refactoring a module, do it all in one session rather than opening and closing sessions for each file.
- Keep a CHANGELOG in CLAUDE.md. Logging recent significant decisions ("2026-05-05: migrated auth from JWT to sessions; don't re-introduce JWT") gives Claude Code institutional memory that survives context resets.