Tutorials
Practical examples and patterns for effectively using Claude Code in your development workflow.
This guide provides step-by-step tutorials for common workflows with Claude Code. Each tutorial includes clear instructions, example commands, and best practices to help you get the most from Claude Code.
Table of contents
- Resume previous conversations
- Understand new codebases
- Fix bugs efficiently
- Refactor code
- Work with tests
- Create pull requests
- Handle documentation
- Work with images
- Use extended thinking
- Set up project memory
- Set up Model Context Protocol (MCP)
- Use Claude as a unix-style utility
- Create custom slash commands
- Run parallel Claude Code sessions with Git worktrees
Resume previous conversations
Continue your work seamlessly
When to use: You’ve been working on a task with Claude Code and need to continue where you left off in a later session.
Claude Code provides two options for resuming previous conversations:
--continue
to automatically continue the most recent conversation--resume
to display a conversation picker
Continue the most recent conversation
This immediately resumes your most recent conversation without any prompts.
Continue in non-interactive mode
Use --print
with --continue
to resume the most recent conversation in non-interactive mode, perfect for scripts or automation.
Show conversation picker
This displays an interactive conversation selector showing:
- Conversation start time
- Initial prompt or conversation summary
- Message count
Use arrow keys to navigate and press Enter to select a conversation.
How it works:
- Conversation Storage: All conversations are automatically saved locally with their full message history
- Message Deserialization: When resuming, the entire message history is restored to maintain context
- Tool State: Tool usage and results from the previous conversation are preserved
- Context Restoration: The conversation resumes with all previous context intact
Tips:
- Conversation history is stored locally on your machine
- Use
--continue
for quick access to your most recent conversation - Use
--resume
when you need to select a specific past conversation - When resuming, you’ll see the entire conversation history before continuing
- The resumed conversation starts with the same model and configuration as the original
Examples:
Understand new codebases
Get a quick codebase overview
When to use: You’ve just joined a new project and need to understand its structure quickly.
Navigate to the project root directory
Start Claude Code
Ask for a high-level overview
Dive deeper into specific components
Tips:
- Start with broad questions, then narrow down to specific areas
- Ask about coding conventions and patterns used in the project
- Request a glossary of project-specific terms
Find relevant code
When to use: You need to locate code related to a specific feature or functionality.
Ask Claude to find relevant files
Get context on how components interact
Understand the execution flow
Tips:
- Be specific about what you’re looking for
- Use domain language from the project
Fix bugs efficiently
Diagnose error messages
When to use: You’ve encountered an error message and need to find and fix its source.
Share the error with Claude
Ask for fix recommendations
Apply the fix
Tips:
- Tell Claude the command to reproduce the issue and get a stack trace
- Mention any steps to reproduce the error
- Let Claude know if the error is intermittent or consistent
Refactor code
Modernize legacy code
When to use: You need to update old code to use modern patterns and practices.
Identify legacy code for refactoring
Get refactoring recommendations
Apply the changes safely
Verify the refactoring
Tips:
- Ask Claude to explain the benefits of the modern approach
- Request that changes maintain backward compatibility when needed
- Do refactoring in small, testable increments
Work with tests
Add test coverage
When to use: You need to add tests for uncovered code.
Identify untested code
Generate test scaffolding
Add meaningful test cases
Run and verify tests
Tips:
- Ask for tests that cover edge cases and error conditions
- Request both unit and integration tests when appropriate
- Have Claude explain the testing strategy
Create pull requests
Generate comprehensive PRs
When to use: You need to create a well-documented pull request for your changes.
Summarize your changes
Generate a PR with Claude
Review and refine
Add testing details
Tips:
- Ask Claude directly to make a PR for you
- Review Claude’s generated PR before submitting
- Ask Claude to highlight potential risks or considerations
Handle documentation
Generate code documentation
When to use: You need to add or update documentation for your code.
Identify undocumented code
Generate documentation
Review and enhance
Verify documentation
Tips:
- Specify the documentation style you want (JSDoc, docstrings, etc.)
- Ask for examples in the documentation
- Request documentation for public APIs, interfaces, and complex logic
Work with images
Analyze images and screenshots
When to use: You need to work with images in your codebase or get Claude’s help analyzing image content.
Add an image to the conversation
You can use any of these methods:
- Drag and drop an image into the Claude Code window
- Copy an image and paste it into the CLI with cmd+v (on Mac)
- Provide an image path claude “Analyze this image: /path/to/your/image.png”
Ask Claude to analyze the image
Use images for context
Get code suggestions from visual content
Tips:
- Use images when text descriptions would be unclear or cumbersome
- Include screenshots of errors, UI designs, or diagrams for better context
- You can work with multiple images in a conversation
- Image analysis works with diagrams, screenshots, mockups, and more
Use extended thinking
Leverage Claude’s extended thinking for complex tasks
When to use: When working on complex architectural decisions, challenging bugs, or planning multi-step implementations that require deep reasoning.
Provide context and ask Claude to think
Claude will gather relevant information from your codebase and use extended thinking, which will be visible in the interface.
Refine the thinking with follow-up prompts
Tips to get the most value out of extended thinking:
Extended thinking is most valuable for complex tasks such as:
- Planning complex architectural changes
- Debugging intricate issues
- Creating implementation plans for new features
- Understanding complex codebases
- Evaluating tradeoffs between different approaches
The way you prompt for thinking results in varying levels of thinking depth:
- “think” triggers basic extended thinking
- intensifying phrases such as “think more”, “think a lot”, “think harder”, or “think longer” triggers deeper thinking
For more extended thinking prompting tips, see Extended thinking tips.
Claude will display its thinking process as italic gray text above the response.
Set up project memory
Create an effective CLAUDE.md file
When to use: You want to set up a CLAUDE.md file to store important project information, conventions, and frequently used commands.
Bootstrap a CLAUDE.md for your codebase
Tips:
- Include frequently used commands (build, test, lint) to avoid repeated searches
- Document code style preferences and naming conventions
- Add important architectural patterns specific to your project
- CLAUDE.md memories can be used for both instructions shared with your team and for your individual preferences.
Use Claude as a unix-style utility
Add Claude to your verification process
When to use: You want to use Claude Code as a linter or code reviewer.
Steps:
Add Claude to your build script
Pipe in, pipe out
When to use: You want to pipe data into Claude, and get back data in a structured format.
Pipe data through Claude
Control output format
When to use: You need Claude’s output in a specific format, especially when integrating Claude Code into scripts or other tools.
Use text format (default)
This outputs just Claude’s plain text response (default behavior).
Use JSON format
This outputs a JSON array of messages with metadata including cost and duration.
Use streaming JSON format
This outputs a series of JSON objects in real-time as Claude processes the request. Each message is a valid JSON object, but the entire output is not valid JSON if concatenated.
Tips:
- Use
--output-format text
for simple integrations where you just need Claude’s response - Use
--output-format json
when you need the full conversation log - Use
--output-format stream-json
for real-time output of each conversation turn
Create custom slash commands
Claude Code supports custom slash commands that you can create to quickly execute specific prompts or tasks.
Create project-specific commands
When to use: You want to create reusable slash commands for your project that all team members can use.
Create a commands directory in your project
Create a Markdown file for each command
Use your custom command in Claude Code
Tips:
- Command names are derived from the filename (e.g.,
optimize.md
becomes/project:optimize
) - You can organize commands in subdirectories (e.g.,
.claude/commands/frontend/component.md
becomes/project:frontend:component
) - Project commands are available to everyone who clones the repository
- The Markdown file content becomes the prompt sent to Claude when the command is invoked
Add command arguments with $ARGUMENTS
When to use: You want to create flexible slash commands that can accept additional input from users.
Create a command file with the $ARGUMENTS placeholder
Use the command with an issue number
This will replace $ARGUMENTS with “123” in the prompt.
Tips:
- The $ARGUMENTS placeholder is replaced with any text that follows the command
- You can position $ARGUMENTS anywhere in your command template
- Other useful applications: generating test cases for specific functions, creating documentation for components, reviewing code in particular files, or translating content to specified languages
Create personal slash commands
When to use: You want to create personal slash commands that work across all your projects.
Create a commands directory in your home folder
Create a Markdown file for each command
Use your personal custom command
Tips:
- Personal commands are prefixed with
/user:
instead of/project:
- Personal commands are only available to you and not shared with your team
- Personal commands work across all your projects
- You can use these for consistent workflows across different codebases
Run parallel Claude Code sessions with Git worktrees
Use worktrees for isolated coding environments
When to use: You need to work on multiple tasks simultaneously with complete code isolation between Claude Code instances.
Understand Git worktrees
Git worktrees allow you to check out multiple branches from the same repository into separate directories. Each worktree has its own working directory with isolated files, while sharing the same Git history. Learn more in the official Git worktree documentation.
Create a new worktree
This creates a new directory with a separate working copy of your repository.
Run Claude Code in each worktree
In another terminal:
Manage your worktrees
Tips:
- Each worktree has its own independent file state, making it perfect for parallel Claude Code sessions
- Changes made in one worktree won’t affect others, preventing Claude instances from interfering with each other
- All worktrees share the same Git history and remote connections
- For long-running tasks, you can have Claude working in one worktree while you continue development in another
- Use descriptive directory names to easily identify which task each worktree is for
- Remember to initialize your development environment in each new worktree according to your project’s setup. Depending on your stack, this might include:
- JavaScript projects: Running dependency installation (
npm install
,yarn
) - Python projects: Setting up virtual environments or installing with package managers
- Other languages: Following your project’s standard setup process
- JavaScript projects: Running dependency installation (
Next steps
Claude Code reference implementation
Clone our development container reference implementation.