Skip to main content

Claude Code Tutorial (2026) | Complete Beginner's Guide for AI Coding

Introduction

Welcome to the Claude Code tutorial. This guide will take you from zero to productive with Anthropic's agentic coding assistant—teaching you how to install, configure, and use Claude Code in real-world development workflows.

By the end of this tutorial, you'll be able to:

  • Install and authenticate Claude Code on your machine
  • Navigate the CLI and understand core commands
  • Use Claude Code to understand existing codebases
  • Generate new code, tests, and documentation
  • Refactor legacy code safely
  • Debug issues and review code for security and quality

Who this tutorial is for: Software engineers at any level—from junior developers learning the ropes to senior architects optimizing team workflows. No prior experience with AI coding tools is required, though basic terminal and Git familiarity will help.

What you'll need: A terminal, a code project to work with, and a Claude subscription (Pro, Max, Team, or Enterprise), a Claude Console account, or access through a supported cloud provider.

Let's get started.

What You Need Before Getting Started

System Requirements

Claude Code runs on macOS, Windows, and Linux (including WSL).

For native Windows users: Git for Windows is recommended so Claude Code can use the Bash tool. If Git for Windows is not installed, Claude Code uses PowerShell as the shell tool instead. WSL setups do not need Git for Windows.

Prerequisites

Before you begin, make sure you have:

  • A terminal or command prompt open (if you've never used the terminal, check out Claude Code's terminal guide)
  • A code project to work with (start with a small project you know well—it's the fastest way to see what Claude Code can do)
  • A Claude subscription (Pro, Max, Team, or Enterprise), a Claude Console account with pre-paid credits, or access through a supported cloud provider (Amazon Bedrock, Google Cloud's Agent Platform, or Microsoft Foundry)

Network Requirements

By default, Claude Code needs to access claude.ai and Anthropic API endpoints for installation, login, and normal use. For enterprise proxy configuration or third-party provider requirements, see the network configuration documentation.

Installing Claude Code

The native installer is the recommended approach. Native installations automatically update in the background to keep you on the latest version.

macOS, Linux, WSL:

curl -fsSL https://claude.ai/install.sh | bash

Windows PowerShell:

irm https://claude.ai/install.ps1 | iex

Windows CMD:

curl -fsSL https://claude.ai/install.cmd -o install.cmd && install.cmd && del install.cmd

Note: If you see The token '&&' is not a valid statement separator, you're in PowerShell, not CMD. If you see 'irm' is not recognized, you're in CMD, not PowerShell. Your prompt shows PS C:\ when you're in PowerShell and C:\ without the PS when you're in CMD.

Method 2: Homebrew (macOS/Linux)

brew install anthropic/tap/claude-code

Method 3: WinGet (Windows)

winget install Anthropic.ClaudeCode

Method 4: Linux Package Managers

You can also install with apt, dnf, or apk on Debian, Fedora, RHEL, and Alpine.

Method 5: npm (Fallback)

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

Verify Installation

After installation, verify Claude Code is working:

claude --version

Updating Claude Code

Native installations update automatically in the background. To manually update:

claude update

To install a specific version:

claude install 2.1.118

Or use stable or latest:

claude install stable

Authentication and Initial Configuration

Step 1: Log In to Your Account

Claude Code requires an account to use. Start an interactive session:

claude

You'll be prompted to log in on first use. Follow the prompts to complete authentication in your browser.

You can log in using any of these account types:

  • Claude Pro, Max, Team, or Enterprise (recommended)
  • Claude Console (API access with pre-paid credits). On first login, a "Claude Code" workspace is automatically created in the Console for centralized cost tracking.
  • Amazon Bedrock, Google Cloud's Agent Platform, or Microsoft Foundry (enterprise cloud providers)
  • A self-hosted Claude apps gateway

Switching Accounts

To switch accounts later or re-authenticate, type inside a running session:

/login

Or from the command line:

claude auth login

Authentication Commands

CommandDescription
claude auth loginSign in to your Anthropic account
claude auth login --consoleSign in with Anthropic Console for API usage billing
claude auth logoutLog out from your Anthropic account
claude auth statusShow authentication status as JSON (use --text for human-readable output)

Your First Claude Code Session

Step 1: Open a Project

Navigate to a project directory and start Claude Code:

cd your-project
claude

Step 2: Ask Your First Question

Once the session starts, you can ask Claude anything about your codebase. Start with a broad question:

"Explain the architecture of this project"

Or ask about a specific file:

"What does src/main.py do?"

Step 3: Make Your First Code Change

Ask Claude to make a change. For example:

"Add error handling to the fetch_user_data function in src/api/users.py"

Claude will:

  1. Find the relevant file
  2. Understand the existing code
  3. Plan the changes
  4. Edit the file
  5. Show you the diff

Step 4: Review the Changes

Claude shows you what changed. Review the diff carefully before approving. You can:

  • Accept the changes
  • Ask for modifications
  • Reject and try a different approach

Step 5: Use Git with Claude Code

Claude Code understands Git workflows. You can ask:

"Create a new branch called feature/auth-improvements"

"Commit these changes with a descriptive message"

"What changed in this PR?"

Essential Commands for Beginners

CommandWhat It Does
/helpShow available commands
/initGenerate a starter CLAUDE.md file for your project
/clearStart fresh on a new task while keeping project memory
/compactSummarize conversation to free context space
/diffShow what changed in the current session
/statusShow current session status and usage

Pro Tips for Beginners

  • Start with a small project you know well—it's the fastest way to see what Claude Code can do
  • Ask broad questions first, then narrow down to specific areas
  • Use @filename to reference specific files instead of describing where code lives
  • If Claude misunderstands, correct it and ask it to update its memory

Core Claude Code Workflows

Understanding Existing Code

Claude Code excels at helping developers navigate unfamiliar codebases.

Explain architecture:

"Explain the overall architecture of this project. What are the main components and how do they interact?"

Explain a specific function:

"Explain what the authenticate_user function does, step by step"

Find where something is implemented:

"Where is the payment processing logic implemented?"

Understand dependencies:

"What are the key dependencies of this project and what do they do?"

Trace a feature:

"Trace how a user registration flows through the system from the API endpoint to the database"

Writing New Code

Claude Code can generate code across the full stack.

Generate a function:

"Write a function that validates email addresses using regex. Include error handling and unit tests."

Generate a class:

"Create a User class with properties for id, name, email, and created_at. Include methods for validation and serialization."

Generate an API endpoint:

"Create a new REST API endpoint at /api/v2/users/:id/orders that returns all orders for a user. Include authentication, validation, pagination, and tests."

Generate tests:

"Write unit tests for the payment-processor.js file using Jest. Cover the main success path and error cases."

Generate documentation:

"Generate comprehensive JSDoc documentation for all functions in src/utils/helpers.js"

Refactoring Code

Claude Code is particularly strong at refactoring—handling changes that span multiple files.

Improve readability:

"Refactor the payment-processor.js file to use async/await instead of callbacks. Add proper error handling. Don't change the external API."

Remove duplication:

"Find and eliminate duplicate code in the authentication module. Extract common logic into reusable functions."

Simplify logic:

"Simplify the nested if-else statements in the order validation function. Use early returns where appropriate."

Modernize code:

"Update the legacy JavaScript code to use ES6+ features: arrow functions, template literals, destructuring, and const/let."

Debugging

Find a bug:

"I'm getting a 500 error when calling /api/checkout. The logs show 'Cannot read property 'id' of undefined'. Find and fix the issue."

Explain an error:

"Explain this error message and what might be causing it: TypeError: Cannot read property 'map' of undefined"

Improve reliability:

"Review the database connection code for potential issues. Add retry logic and better error handling."

Performance debugging:

"The API endpoint /api/search is slow. Analyze the code and suggest optimizations."

Code Reviews

Claude Code can review code for security, performance, readability, and best practices.

Security review:

"Review the authentication code for security vulnerabilities. Check for SQL injection, XSS, and insecure session handling."

Performance review:

"Review the data processing pipeline for performance issues. Identify bottlenecks and suggest improvements."

Best practices review:

"Review the React components for adherence to React best practices and hooks rules."

PR review:

"Review the changes in this pull request. Identify potential issues and suggest improvements."

Claude Code Best Practices

1. Give Claude a Way to Verify Its Work

Always include a way for Claude to check its own work. For example:

  • "Write tests for the new function"
  • "Run the linter after making changes"
  • "Verify the API still works with the existing integration tests"

2. Explore First, Then Plan, Then Code

Don't ask Claude to write code immediately. Start by exploring:

  1. Explore: "Analyze the current authentication system"
  2. Plan: "Based on your analysis, outline how you'd add two-factor authentication"
  3. Code: "Now implement the plan"

Use plan mode (Shift+Tab or Alt+M) to separate exploration from execution—Claude proposes an implementation plan before writing anything.

3. Provide Specific Context

Reference files with @ instead of describing where code lives:

Instead of:

"Look at the file in the src/api folder called users.js and..."

Use:

"Look at @src/api/users.js and..."

4. Work Incrementally

Don't ask Claude to rewrite your entire codebase in one go. Break large tasks into smaller, manageable steps:

  1. "Analyze the payment module"
  2. "Plan the refactoring approach"
  3. "Refactor the validation logic first"
  4. "Now refactor the business logic"
  5. "Update the tests"

5. Learn from Mistakes

The key practice: anytime Claude does something incorrectly, add it to CLAUDE.md so it knows not to repeat the mistake. After every correction, end with:

"Update your CLAUDE.md so you don't make that mistake again."

6. Use Explicit Constraints

Add measurable limits to your requests:

"Refactor this function but don't modify existing tests."

"Generate a solution in under 50 lines of code."

"Keep the existing API interface unchanged."

7. Be Specific Upfront

Vague requests produce vague results. Be specific about:

  • What you want to achieve
  • What files or modules are involved
  • What constraints apply
  • What success looks like

Practical Claude Code Examples

Example 1: Build a REST API Endpoint

Goal: Create a new REST API endpoint for user orders.

Prompt:

"Create a new REST API endpoint at /api/v2/users/:id/orders that returns all orders for a user. Requirements: - Authentication required (JWT) - Input validation for user ID - Pagination support (limit/offset) - Returns JSON with orders and total count - Error handling for invalid users - Unit tests using Jest - Update API documentation"

Claude's workflow:

  1. Analyzes existing API structure
  2. Creates the new route handler
  3. Adds validation middleware
  4. Implements the database query with pagination
  5. Adds error handling
  6. Writes unit tests
  7. Updates API documentation

Developer review: Review the generated code, test it locally, and provide feedback.

Example 2: Refactor Legacy Java Code

Goal: Modernize a legacy Java class.

Prompt:

"Refactor the OrderProcessor.java class. It currently uses raw JDBC with manual connection management. Replace with Spring Data JPA. Keep the same business logic. Add proper exception handling. Write integration tests."

Claude's workflow:

  1. Analyzes the existing OrderProcessor class
  2. Identifies the JDBC code and business logic
  3. Creates a JPA entity class
  4. Implements a repository interface
  5. Rewrites the processor to use the repository
  6. Adds proper exception handling
  7. Writes integration tests

Example 3: Generate Unit Tests

Goal: Add comprehensive test coverage.

Prompt:

"Write comprehensive unit tests for src/utils/validation.js. Cover:

  • Email validation
  • Password strength validation
  • Phone number validation
  • *Edge cases and error cases
  • Use Jest. Aim for >90% coverage."

Example 4: Document an Existing Codebase

Goal: Generate documentation for an undocumented module.

Prompt:

"Generate comprehensive documentation for the src/services/payment directory. Include:

  • Overview of the payment service architecture
  • API reference for each function
  • Usage examples
  • Configuration options
  • Error handling guide
  • Format as Markdown for a README"

Example 5: Explain a Complex Algorithm

Goal: Understand a complex piece of code.

Prompt:

"Explain the sorting algorithm in src/algorithms/sort.js. Walk through it step by step with an example input. What's the time and space complexity? When would you use this over other sorting algorithms?"

Claude Code Development Workflows by Role

Backend Development

  • API development: Generate REST or GraphQL endpoints with validation and error handling
  • Database: Generate SQL queries, ORM models, and migrations
  • Microservices: Design service boundaries and implement communication
  • Authentication: Implement JWT, OAuth, or session-based auth
  • Caching: Implement Redis or in-memory caching strategies

Example prompt:

"Create a microservice for order processing with: REST API, PostgreSQL database, Redis cache, JWT authentication, and Docker configuration"

Frontend Development

  • React/Vue components: Generate components from requirements
  • State management: Implement Redux, Zustand, or Vuex
  • UI/UX: Implement responsive designs
  • API integration: Generate API client code
  • Testing: Write component and integration tests

Example prompt:

"Create a React component called UserProfile that accepts name, email, and avatarUrl props. Display the avatar as a circle, name in bold, email below. Use Tailwind CSS for styling. Add loading and error states."

DevOps

  • Docker: Generate Dockerfiles and docker-compose configurations
  • Kubernetes: Generate deployment manifests
  • CI/CD: Generate GitHub Actions or GitLab CI pipelines
  • Infrastructure as Code: Generate Terraform or CloudFormation
  • Monitoring: Configure logging and monitoring

Example prompt:

"Create a GitHub Actions workflow that: runs tests on push, builds a Docker image, pushes to Docker Hub, and deploys to a Kubernetes cluster"

Architecture

  • Design review: Analyze and improve architecture
  • Service decomposition: Plan microservice boundaries
  • API design: Design REST or GraphQL APIs
  • Technical documentation: Generate architecture docs
  • Migration planning: Plan large-scale migrations

Example prompt:

"Analyze the current monolithic architecture and propose a migration plan to microservices. Consider: service boundaries, data consistency, communication patterns, and migration strategy."

Claude Code Productivity Tips

1. Run Multiple Sessions in Parallel

The biggest productivity gain is running 3-5 Claude Code sessions in parallel, each in its own git worktree. This allows you to work on multiple features or experiments simultaneously without interference.

2. Use CLAUDE.md for Persistent Memory

CLAUDE.md files are markdown files that give Claude persistent instructions for a project, your personal workflow, or your entire organization.

Create a project-level CLAUDE.md:

# Project: MyApp

## Coding Standards
- Use TypeScript strictly
- Follow ESLint configuration
- Write JSDoc comments for all functions
- Use React functional components with hooks

## Architecture
- Frontend: React + Redux Toolkit
- Backend: Node.js + Express
- Database: PostgreSQL with Prisma ORM

## Common Tasks
- To run tests: `npm test`
- To build: `npm run build`
- To start dev server: `npm run dev`

Global CLAUDE.md (at ~/.claude/CLAUDE.md):

# Personal Preferences

## Coding Style
- Use 2-space indentation
- Use single quotes for strings
- Use semicolons
- Prefer const over let, avoid var

## Workflow
- Always write tests for new features
- Use conventional commits format
- Create a new branch for each feature

3. Use Auto Memory

Claude Code has two complementary memory systems: CLAUDE.md and Auto Memory. Both are loaded at the start of every conversation.

Auto memory lets Claude learn from your corrections without manual effort. When Claude makes a mistake, correct it and ask it to remember:

"Remember that we use 2-space indentation, not 4-space."

4. Use Subagents for Parallel Work

Subagents are self-contained agents that operate with their own context windows. When Claude spawns a subagent, it works independently to read files, explore code, or make changes. When it completes its task, the subagent returns only the relevant results to the main conversation.

Use subagents when:

  • A side task would clutter your main conversation
  • You need to run parallel investigations
  • You want specialized agents for specific task types

5. Use Skills for Repeated Tasks

Skills are reusable workflows that Claude can invoke. Create a skill for frequently repeated tasks like:

  • Writing commit messages
  • Generating PR descriptions
  • Running specific test suites
  • Deploying to specific environments

6. Use Hooks for Automation

Hooks let you run code at key points in Claude Code's lifecycle: format files after edits, block commands before they execute, send notifications when Claude needs input, inject context at session start, and more.

7. Use MCP Servers for External Integration

MCP (Model Context Protocol) servers expose "tools" that Claude can call—things like reading databases, calling APIs, managing files, etc. Connect MCP servers to give Claude access to external tools and data sources beyond its built-in capabilities.

Common Beginner Mistakes

1. Asking Vague Questions

The mistake: "Fix the bug" or "Make this better"

Why it fails: Claude doesn't know which bug or what "better" means.

How to improve: Be specific. "Fix the TypeError in the login function when email is undefined" or "Refactor this function to be more readable and add error handling."

2. Expecting Perfect Code Immediately

The mistake: Asking for a complex feature and expecting it to work perfectly on the first try.

Why it fails: AI-generated code needs review and iteration, just like human-written code.

How to improve: Work iteratively. Ask for a plan first, then implement, then review and refine.

3. Ignoring Context

The mistake: Asking Claude to change code without telling it about the project structure, dependencies, or constraints.

Why it fails: Claude needs context to generate appropriate code.

How to improve: Use @filename to reference specific files. Use CLAUDE.md to provide persistent context.

4. Skipping Testing

The mistake: Accepting generated code without running tests or asking Claude to write tests.

Why it fails: Code might work in isolation but break in the full application.

How to improve: Always ask Claude to write tests. Run the tests before accepting changes.

5. Blindly Accepting AI Suggestions

The mistake: Trusting Claude's output without review.

Why it fails: AI can make mistakes, introduce security vulnerabilities, or generate code that doesn't fit your architecture.

How to improve: Review all generated code. Ask Claude to explain its reasoning. Test thoroughly.

Claude Code Limitations

Context Window Limitations

Claude Code sessions have a context window. When the conversation gets long, use /context to see what's filling the window and /compact to summarize it and free space.

Large Repository Handling

For very large repositories, Claude may need guidance to focus on relevant parts. Use specific file references and narrow questions.

External Dependencies

Claude can't access the internet or external APIs unless you connect MCP servers. For tasks requiring external data, set up MCP servers first.

Human Review Required

Claude Code is a tool that enhances developer productivity, not a replacement for human developers. Human judgment, creativity, and oversight remain essential.

Frequently Asked Questions

Is Claude Code suitable for beginners?

Yes. Claude Code is accessible to beginners. Start with a small project you know well, ask broad questions, and gradually learn more advanced features. The CLI interface has a learning curve, but the desktop app provides a graphical alternative.

Does Claude Code replace developers?

No. Claude Code is a tool that enhances developer productivity, not a replacement for human developers. It handles execution while humans focus on architecture, product thinking, and direction.

Can Claude Code understand existing projects?

Yes. Claude Code reads your entire codebase and understands component connections. It can analyze architecture, trace dependencies, and explain how different parts work together.

Which programming languages work best?

Claude can read code in any language. It's language-agnostic and understands how components connect regardless of the programming language.

Can Claude Code generate tests?

Yes. Claude Code can generate unit tests, integration tests, and end-to-end tests for your code.

Can Claude Code explain legacy systems?

Yes. Claude Code is particularly valuable for understanding legacy codebases—analyzing architecture, explaining complex logic, and planning refactoring strategies.

Can Claude Code improve architecture?

Yes. Claude Code can analyze architecture, identify technical debt, suggest improvements, and help plan large-scale migrations.

Is Claude Code suitable for enterprise development?

Yes. Claude Code is used by enterprises including Stripe, Ramp, Wiz, and Rakuten. Enterprise features include SSO, RBAC, centralized billing, and custom deployment options.

Conclusion

You've now completed the Claude Code tutorial. You've learned:

  • How to install Claude Code on macOS, Windows, and Linux
  • How to authenticate and configure your environment
  • How to start your first session and ask questions
  • Core workflows: understanding code, writing code, refactoring, debugging, and code review
  • Best practices: working iteratively, providing context, and using CLAUDE.md for persistent memory
  • Advanced features: subagents, skills, hooks, and MCP servers
  • Common mistakes to avoid and how to maximize productivity

The key to mastering Claude Code is practice and iteration. Start with small tasks, experiment with different approaches, and gradually take on more complex projects. The more you use Claude Code, the better you'll understand how to get the most out of this powerful tool.

Claude Code is changing how developers work—shifting from writing every line of code to directing an agentic assistant that handles the execution. By learning to use Claude Code effectively, you're positioning yourself at the forefront of this transformation.


Ready to go deeper? Explore the Claude Code Complete Guide for a comprehensive overview, or dive into the Claude Code Prompt Guide for advanced prompting techniques.

For the latest updates, features, and documentation, visit the official Claude Code documentation.