Claude Code Common Workflows Guide
This article introduces common workflows for using Claude Code. Each task includes clear explanations, example commands, and best practices to help better utilize Claude Code.
1️⃣ Understanding New Codebases
1.1 Quick Codebase Overview
Suppose you just joined a new project and need to quickly understand its structure.
Navigate to project root directory
bashcd /path/to/project
Start Claude Code
bashclaude
Request high-level overview
> give me an overview of this codebase > explain the main architecture patterns used here > what are the key data models? > how is authentication handled?
💡 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 terminology
1.2 Finding Relevant Code
Suppose you need to locate code related to a specific feature.
Have Claude find relevant files
> find the files that handle user authentication
Understand how components interact
> how do these authentication files work together?
Understand execution flow
> trace the login process from front-end to database
💡 Tips:
- Be specific about what you're looking for
- Use domain language from the project
2️⃣ Efficient Bug Fixing
Suppose you encountered an error message and need to find and fix its source.
Share the error with Claude
> I'm seeing an error when I run npm test
Request fix suggestions
> suggest a few ways to fix the @ts-ignore in user.ts
Apply the fix
> update user.ts to add the null check you suggested
💡 Tips:
- Tell Claude the command to reproduce the issue and get stack traces
- Mention any steps to reproduce the error
- Let Claude know if the error is intermittent or persistent
3️⃣ Code Refactoring
Suppose you need to update legacy code to use modern patterns and practices.
Identify legacy code that needs refactoring
> find deprecated API usage in our codebase
Get refactoring suggestions
> suggest how to refactor utils.js to use modern JavaScript features
Safely apply changes
> refactor utils.js to use ES2024 features while maintaining the same behavior
Validate refactoring
> run tests for the refactored code
💡 Tips:
- Have Claude explain the benefits of modern approaches
- Request changes that maintain backward compatibility when needed
- Refactor in small, testable increments
4️⃣ Handling Tests
Suppose you need to add tests for uncovered code.
Identify untested code
> find functions in NotificationsService.swift that are not covered by tests
Generate test scaffolding
> add tests for the notification service
Add meaningful test cases
> add test cases for edge conditions in the notification service
Run and validate tests
> run the new tests and fix any failures
💡 Tips:
- Request tests that cover edge cases and error conditions
- Request both unit tests and integration tests when appropriate
- Have Claude explain the testing strategy
5️⃣ Creating Pull Requests
Suppose you need to create a well-documented pull request for your changes.
Summarize your changes
> summarize the changes I've made to the authentication module
Use Claude to generate PR
> create a pr
Review and enhance
> enhance the PR description with more context about the security improvements
Add testing details
> add information about how these changes were tested
💡 Tips:
- Have Claude create the PR directly for you
- Review Claude-generated PRs before submitting
- Have Claude highlight potential risks or considerations
6️⃣ Handling Documentation
Suppose you need to add or update documentation for your code.
Identify undocumented code
> find functions without proper JSDoc comments in the auth module
Generate documentation
> add JSDoc comments to the undocumented functions in auth.js
Review and enhance
> improve the generated documentation with more context and examples
Validate documentation
> check if the documentation follows our project standards
💡 Tips:
- Specify the documentation style you want (JSDoc, docstrings, etc.)
- Request examples in documentation
- Request documentation for public APIs, interfaces, and complex logic
7️⃣ Handling Images
Suppose you need to work with images in your codebase and want Claude to help analyze image content.
Adding Images to Conversation
You can use any of these methods:
- Drag and drop image files into the Claude Code window
- Copy an image and paste it into the CLI using
ctrl+v
(don't usecmd+v
) - Provide image path to claude:
"Analyze this image: /path/to/your/image.png"
Have Claude Analyze Images
> What does this image show?
> Describe the UI elements in this screenshot
> Are there any problematic elements in this diagram?
Use Images for Context
> Here's a screenshot of the error. What's causing it?
> This is our current database schema. How should we modify it for the new feature?
Get Code Suggestions from Visual Content
> Generate CSS to match this design mockup
> What HTML structure would recreate this component?
💡 Tips:
- Use images when text descriptions are unclear or cumbersome
- Include error screenshots, UI designs, or diagrams for better context
- You can use multiple images in a conversation
- Image analysis works for diagrams, screenshots, mockups, etc.
8️⃣ Using Extended Thinking
Suppose you're working on complex architectural decisions, challenging bugs, or multi-step implementation planning that requires deep reasoning.
Provide Context and Let Claude Think
> I need to implement a new authentication system using OAuth2 for our API.
Think deeply about the best approach for implementing this in our codebase.
Claude will gather relevant information from your codebase and use extended thinking, which will be visible in the interface.
Refine Thinking with Follow-up Prompts
> think about potential security vulnerabilities in this approach
> think harder about edge cases we should handle
💡 Tips for Maximum Value:
Extended thinking is most valuable for complex tasks like:
- Planning complex architectural changes
- Debugging complex issues
- Creating implementation plans for new features
- Understanding complex codebases
- Evaluating tradeoffs between different approaches
Thinking Depth Control:
"think"
triggers basic extended thinking"think more"
,"think a lot"
,"think harder"
or"think longer"
trigger deeper thinking
Claude will display its thinking process in italicized gray text above the response.
9️⃣ Resuming Previous Conversations
Suppose you've been working with Claude Code on a task and need to continue from where you left off in a later session.
Claude Code provides two options to resume previous conversations:
--continue
automatically continues the most recent conversation--resume
shows a conversation selector
Continue Recent Conversation
claude --continue
This immediately resumes your most recent conversation without any prompts.
Continue in Non-Interactive Mode
claude --continue --print "Continue with my task"
Use --print
with --continue
to resume the most recent conversation in non-interactive mode, perfect for scripts or automation.
Show Conversation Selector
claude --resume
This displays an interactive conversation selector showing:
- Conversation start time
- Initial prompt or conversation summary
- Number of messages
Navigate with arrow keys and press Enter to select a conversation.
💡 Tips:
- Conversation history is stored on your local machine
- Use
--continue
for quick access to your most recent conversation - Use
--resume
when you need to choose a specific past conversation - When resuming, you'll see the entire conversation history before continuing
- Resumed conversations start with the same model and configuration as the original
🔧 How it Works:
- Conversation Storage: All conversations are automatically saved locally with complete message history
- Message Deserialization: When resuming, the entire message history is restored to maintain context
- Tool State: Tool usage and results from previous conversations are preserved
- Context Recovery: All previous context is maintained when conversations resume
📝 Examples:
# Continue most recent conversation
claude --continue
# Continue most recent conversation with specific prompt
claude --continue --print "Show me our progress"
# Show conversation selector
claude --resume
# Continue most recent conversation in non-interactive mode
claude --continue --print "Run the tests again"
🔟 Running Parallel Claude Code Sessions with Git worktrees
Suppose you need to work on multiple tasks simultaneously and want complete code isolation between Claude Code instances.
Understanding Git worktrees
Git worktrees allow you to check out multiple branches of the same repository into separate directories. Each worktree has its own working directory and isolated files, while sharing the same Git history. Learn more in the official Git worktree documentation.
Create New Worktree
# Create new worktree with new branch
git worktree add ../project-feature-a -b feature-a
# Or create worktree with existing branch
git worktree add ../project-bugfix bugfix-123
This creates a new directory containing a separate working copy of your repository.
Run Claude Code in Each Worktree
# Navigate to your worktree
cd ../project-feature-a
# Run Claude Code in this isolated environment
claude
Run Claude in Another Worktree
cd ../project-bugfix
claude
Manage Your Worktrees
# List all worktrees
git worktree list
# Remove worktree when done
git worktree remove ../project-feature-a
💡 Tips:
- Each worktree has its own independent file state, perfect for parallel Claude Code sessions
- Changes made in one worktree don'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 continuing development in another
- Use descriptive directory names to easily identify what each worktree is used for
⚙️ Environment Initialization: Remember to initialize your development environment in each new worktree according to your project's setup. Depending on your tech stack, this might include:
- JavaScript projects: Running dependency installation (npm install, yarn)
- Python projects: Setting up virtual environments or using package managers for installation
- Other languages: Following your project's standard setup process
1️⃣1️⃣ Using Claude as Unix-style Utility
11.1 Add Claude to Your Validation Process
Suppose you want to use Claude Code as a linter or code reviewer.
Add Claude to your build scripts:
// package.json
{
"scripts": {
"lint:claude": "claude -p 'you are a linter. please look at the changes vs. main and report any issues related to typos. report the filename and line number on one line, and a description of the issue on the second line. do not return any other text.'"
}
}
💡 Tips:
- Use Claude in your CI/CD pipeline for automated code reviews
- Customize prompts to check for specific issues relevant to your project
- Consider creating multiple scripts for different types of validation
11.2 Pipe Input, Pipe Output
Suppose you want to pipe data into Claude and get data back in structured format.
Pipe data through Claude:
cat build-error.txt | claude -p 'concisely explain the root cause of this build error' > output.txt
💡 Tips:
- Use pipes to integrate Claude into existing shell scripts
- Combine with other Unix tools for powerful workflows
- Consider using --output-format for structured output
11.3 Control Output Format
Suppose you need Claude's output in a specific format, especially when integrating Claude Code into scripts or other tools.
Using Text Format (default)
cat data.txt | claude -p 'summarize this data' --output-format text > summary.txt
This outputs only Claude's plain text response (default behavior).
Using JSON Format
cat code.py | claude -p 'analyze this code for bugs' --output-format json > analysis.json
This outputs a JSON array of messages including metadata like cost and duration.
Using Stream JSON Format
cat log.txt | claude -p 'parse this log file for errors' --output-format stream-json
This outputs a series of JSON objects in real-time as Claude processes the request. Each message is a valid JSON object, but the overall output is not valid JSON if concatenated.
💡 Tips:
- Use
--output-format text
for simple integrations where you only need Claude's response - Use
--output-format json
when you need complete conversation logs - Use
--output-format stream-json
for real-time output per conversation turn
1️⃣2️⃣ Creating Custom Slash Commands
Claude Code supports custom slash commands that you can create to quickly execute specific prompts or tasks.
12.1 Create Project-Specific Commands
Suppose you want to create reusable slash commands for your project that all team members can use.
Create commands directory in your project
bashmkdir -p .claude/commands
Create Markdown files for each command
bashecho "Analyze the performance of this code and suggest three specific optimizations:" > .claude/commands/optimize.md
Use your custom command in Claude Code
> /project:optimize
💡 Tips:
- Command names come 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
12.2 Add Command Arguments with $ARGUMENTS
Suppose you want to create flexible slash commands that can accept additional input from users.
Create command file with $ARGUMENTS placeholder
bashecho "Find and fix issue #\$ARGUMENTS. Follow these steps: 1.Understand the issue described in the ticket 2. Locate the relevant code in our codebase 3. Implement a solution that addresses the root cause 4. Add appropriate tests 5. Prepare a concise PR description" > .claude/commands/fix-issue.md
Use the command with issue number In your Claude session, use the command with arguments.
> /project:fix-issue 123
This will replace $ARGUMENTS with "123" in the prompt.
💡 Tips:
- $ARGUMENTS placeholder is replaced by any text after the command
- You can place $ARGUMENTS anywhere in your command template
- Other useful applications: generating test cases for specific functions, creating documentation for components, reviewing code in specific files, or translating content to specified languages
12.3 Create Personal Slash Commands
Suppose you want to create personal slash commands that work across all your projects.
Create commands directory in your home folder
bashmkdir -p ~/.claude/commands
Create Markdown files for each command
bashecho "Review this code for security vulnerabilities, focusing on:" > ~/.claude/commands/security-review.md
Use your personal custom command
> /user:security-review
💡 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 maintaining consistent workflows across different codebases
🎯 Summary
By mastering these workflows, you can fully leverage Claude Code's powerful capabilities:
- Understanding Codebases - Quickly get project overviews and find relevant code
- Efficient Debugging - Systematically fix bugs and issues
- Code Refactoring - Safely modernize and improve code
- Test Coverage - Add comprehensive test cases
- Documentation Management - Create and maintain quality documentation
- Image Processing - Utilize visual content to enhance understanding
- Deep Thinking - Handle complex architectural decisions
- Session Management - Effectively resume and manage conversations
- Parallel Work - Handle multiple tasks using Git worktrees
- System Integration - Integrate Claude into development toolchains
- Custom Commands - Create reusable workflow commands
These workflows will help you use Claude Code more efficiently and boost development productivity.