How to Use Claude Code: A Complete Step-by-Step Tutorial
From first install to shipping real features — everything you need to get Claude Code working in your project today.
Install Claude Code
Claude Code installs as a global CLI tool. Pick the method that matches your OS. Native installs auto-update — no manual version management required.
The commands below (curl, npm) look intimidating if you've never touched a terminal, but you're only ever copy-pasting one line and pressing Enter — you don't need to understand what it does. On Mac, open the Terminal app (search for it with Spotlight); on Windows, install Git for Windows first (see the callout below) and use its Bash terminal. This guide later has you configure a real backend stack (TypeScript, Prisma, PostgreSQL) — that part is Claude's job, not yours. You're driving by describing what you want in plain English; Claude writes and runs the actual code.
macOS & Linux
curl -fsSL https://claude.ai/install.sh | bash
Windows — PowerShell
irm https://claude.ai/install.ps1 | iex
Windows — Command Prompt
curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd
npm (any OS)
npm install -g @anthropic-ai/claude-code
Git for Windows is strongly recommended. It provides a Bash shell that gives Claude Code access to Unix-style file tools. Download it at gitforwindows.org.
The native installer (curl/PowerShell) handles updates automatically. The npm install requires manual npm update -g @anthropic-ai/claude-code when new versions ship.
Verify the install by running claude --version. If you see a version number, you're ready for Step 2.
Log In
Run claude for the first time. It will prompt you to authenticate before doing anything else.
$ claude
No active session found. Opening login...
A browser window opens to complete OAuth. Once you authenticate, your credentials are stored locally and you won't be asked again.
Supported account types
- Claude Pro / Max / Team / Enterprise — claude.ai subscription
- Anthropic Console — pay-per-token API access at console.anthropic.com
- Amazon Bedrock — Claude hosted in AWS
- Google Cloud Vertex AI — Claude hosted in GCP
- Microsoft Azure AI Foundry — Claude hosted in Azure
Inside any Claude Code session, type /login to log out and re-authenticate with a different account or provider.
Start Your First Session
Always navigate to your project directory first. Claude Code reads your files from the working directory — context is everything.
$ cd /path/to/your/project
$ claude
Claude Code v1.4.0
Model: claude-sonnet-4-5
Directory: /path/to/your/project
Type /help for commands, /exit to quit
claude>
The startup screen confirms three things: the version, the model in use, and the working directory. If the directory is wrong, exit and cd to the right place.
Essential session commands
/help— list all available slash commands/resume— continue a previous session with its full message history/clear— wipe context and start fresh within the same session/exit— quit Claude Code
Ask Your First Question
Start by having Claude understand your project. It reads files automatically — no manual copy-pasting, no context loading. Just ask.
- what does this project do?
- what technologies does this project use?
- where is the main entry point?
- explain the folder structure
Claude will scan package.json, README.md, config files, and source directories to build an accurate answer. It tells you which files it reads, so you can see exactly what it's working from.
Unlike chat interfaces where you paste code snippets, Claude Code directly accesses your filesystem. It finds the relevant files itself. Ask naturally, as if talking to a senior engineer who just cloned the repo.
Because Claude reads files automatically to build context, it can waste tokens scanning huge, irrelevant directories — node_modules, dist, build, lockfiles, generated assets. Create a .claudeignore file in your project root (same syntax as .gitignore) listing these directories so Claude skips them. On a large project, this is the single biggest lever for keeping token usage — and API cost, if you're on pay-per-token — under control.
Example exchange:
claude> what technologies does this project use?
Reading package.json... src/index.ts... tsconfig.json...
This is a TypeScript Node.js API using:
• Express 4.18 for HTTP routing
• Prisma 5.x as the ORM, connected to PostgreSQL
• Zod for request validation
• Jest for testing (see jest.config.ts)
• Docker Compose for local DB setup (docker-compose.yml)
Entry point is src/index.ts, which bootstraps Express and
registers routes from src/routes/.
Make Your First Code Change
Ask Claude to write something small and concrete. The "hello world" pattern is a reliable way to see the full approval workflow in action.
- add a hello world function to the main file
Here's what happens next — Claude runs through a three-step loop before touching anything:
- Finds the file — locates
src/index.ts(or wherever main lives in your stack) - Shows the diff — displays exactly what it intends to add or change
- Asks for approval — waits for your "yes" before writing anything
Claude Code never silently modifies files. Every edit is shown as a diff and requires your explicit approval. You can review, reject, or ask for changes before anything is written to disk.
The same approval gate applies to shell commands, not just file edits. Anything state-changing — npm run build, a database migration, git push, deleting a file — prompts for your permission the first time in a session before it runs. You can grant blanket approval for a specific command type if you're going to run it repeatedly, but Claude Code will not silently execute destructive commands on your machine without you seeing them first.
Accept all mode
If you trust Claude for a session and want to skip approval on each edit, type accept all or press the corresponding key when prompted. This applies for the duration of the session only.
Use Git with Claude Code
Claude Code has native git awareness. Ask in plain English — it translates to the correct git commands without you needing to remember flags.
- what files have I changed?
- commit my changes with a descriptive message
- create a new branch called feature/quickstart
- show me the last 5 commits
- help me resolve merge conflicts
Example — commit workflow:
claude> commit my changes with a descriptive message
Running: git status
M src/index.ts
M src/routes/users.ts
Running: git diff (reading changes...)
Proposed commit message:
"feat: add helloWorld function and update server startup log"
Shall I commit with this message? (y/n)
When you hit a merge conflict, you don't need to find or paste the file path yourself. Because Claude Code is natively git-aware, just type resolve my current merge conflicts — it runs git status to find the blocked files automatically, reads both branches, understands the intent of each change, and proposes a resolution as a diff for your approval.
Fix a Bug or Add a Feature
This is Claude Code's core use case. Describe what's broken or what you want, and Claude locates the relevant code, understands the context, and implements a solution.
- add input validation to the user registration form
- there's a bug where users can submit empty forms — fix it
What Claude does internally:
1. Locates the registration form component
2. Reads the current validation logic (or notes the absence of it)
3. Checks existing patterns in your codebase (Zod, Yup, native HTML, etc.)
4. Implements validation consistent with your stack
5. Runs existing tests to verify nothing broke
6. Shows a diff for your approval
For bugs, describe the symptom rather than the cause. "Users can submit empty forms" is more useful than "the validation function returns true incorrectly" — Claude will find the cause.
After making a change, Claude will offer to run your test suite. If tests fail, it analyzes the failure output and proposes a fix — all within the same session without you leaving the terminal.
Common Workflows
Once you're comfortable with the basics, these are the four workflows you'll use daily:
Prompt: refactor the authentication module to use async/await
Claude audits callback patterns/promises, rewrites to async/await, preserves error logic, and displays the diff before applying.
Prompt: write unit tests for the calculator functions
Claude analyzes your test suite framework (Jest, PyTest, etc.) and writes assertions covering happy paths and edge cases.
Prompt: update the README with installation instructions
Claude parses setup scripts, configs, and dependencies to generate accurate, zero-boilerplate README guides.
Prompt: review my changes and suggest improvements
Claude inspects your git diff, analyzes correctness and style, and outputs suggestions as structured comments.
Commands Reference
Two categories: shell commands you run before starting a session, and slash commands you use inside one.
Shell commands
| Command | What it does |
|---|---|
claude | Start an interactive session in the current directory |
claude "task" | Start a session with an initial task pre-loaded |
claude -p "query" | One-shot: run a single query, print output, exit — no interactive session |
claude -c | Continue the most recent session |
claude -r | Resume a past session (shows a list to pick from) |
Session commands (inside Claude)
| Command | What it does |
|---|---|
/clear | Clear message history and start a fresh context window |
/help | List all available slash commands and keyboard shortcuts |
/exit | Quit Claude Code and return to the shell |
/login | Log out and re-authenticate (switch accounts or providers) |
/resume | Pick up a previous session with full conversation history |
Advanced Features and Interfaces
The basics get you 80% of the value. These features unlock the rest — especially for teams and complex projects.
CLAUDE.md
CLAUDE.md file in your project root acts as persistent memory for Claude. Put your tech stack, coding conventions, environment setup, and key constraints here. Claude reads it at the start of every session — automatically, no prompting required.Plan Mode
use plan mode for this.MCP — Model Context Protocol
Skills & Hooks
Available interfaces
Claude Code isn't only a terminal tool. The same agent runs across multiple surfaces:
For CI/CD use cases, claude -p "..." in non-interactive mode integrates cleanly into pipelines. See the official quickstart docs for GitHub Actions YAML examples.
AI Coding Agent Myths vs. Truths
.claudeignore prevents scanning massive dependency/build folders, keeping costs minimal.