Best Practices for Claude Code
A tutorial by Anthropic. Featured in the OTF curated resource library.
Project Setup
Proper project setup is the foundation for productive Claude Code sessions.
Create a CLAUDE.md file
Add a CLAUDE.md file to your project root that describes your tech stack, coding conventions, and project structure. Claude Code reads this automatically to understand your project context.
Keep your project organized
Well-organized projects with clear directory structures and consistent naming conventions produce significantly better results. Claude Code uses file paths as context signals.
Use version control
Always work in a git repository. Claude Code can review diffs, and you can easily revert changes if needed.
Effective Prompting
Be specific about scope
Instead of 'fix the bug', reference specific files and describe the expected vs actual behavior.
Provide examples
When asking for new code, reference existing patterns in your codebase: 'Follow the same pattern as UserCard component'.
Think in tasks, not lines
Describe what you want to accomplish at a high level. Claude Code is an agent — let it plan the implementation details.
Use /compact for long sessions
If your conversation gets long, use the /compact command to summarize the context and free up the context window.
Multi-File Workflows
Claude Code excels at coordinating changes across multiple files. When describing a feature that spans several files, mention the full dependency chain — from database schema through API endpoints to frontend components.
Use checkpoints by asking Claude to run the type checker or tests after each significant change. This prevents cascading errors across files.
For large refactors, break the work into phases and verify each phase compiles before moving to the next.
Debugging Tips
Claude Code is effective at debugging when given the right context.
Share the exact error
Copy and paste the full error message, including stack traces. Claude Code can often identify the root cause from the error alone.
Describe what you expected
Tell Claude what the code should do vs what it actually does. This narrows the search space significantly.
Let Claude investigate
Say 'investigate this error and propose a fix' rather than guessing at the solution. Claude Code can read related files and trace the issue.