Claude Code Mastery: My Complete Workflow
Claude Code is the single tool that changed my development velocity the most. Not Copilot, not ChatGPT, not Cursor’s agent mode — Claude Code. A terminal-based AI agent that reads your entire codebase, edits files, runs commands, and iterates on errors autonomously. I’ve used it to ship PromptLib, build features for MetaLabs, and handle complex refactors at Weel that would have taken days by hand. This is the complete guide to how I work with it — the mental models, the configuration, the patterns, and the hard-won lessons from hundreds of hours of usage.Why Claude Code Over the Alternatives
Every AI coding tool occupies a different niche. Here’s where Claude Code sits and why I reach for it. Cursor is my IDE. I live there for day-to-day coding — tab completions, inline edits, quick chat questions. But Cursor’s agent mode operates within the IDE’s constraints: it’s great for editing a handful of files, less great for cross-cutting changes that touch 30 files and require running test suites to verify. ChatGPT / Claude.ai are conversation tools. They’re excellent for design discussions, brainstorming, and one-off code generation. But they can’t see your codebase, can’t run your tests, can’t iterate. Claude Code is the power tool. It’s a full agent running in your terminal with access to your filesystem, your shell, and your git history. It reads files, writes files, runs commands, and loops until the task is done. For complex, multi-file tasks that require understanding your codebase holistically, nothing else comes close. The mental model: Cursor for editing, Claude Code for engineering.Setting Up CLAUDE.md: Your Project’s Brain
The single most impactful thing you can do with Claude Code is write a goodCLAUDE.md file. This file lives in your project root and gives Claude Code persistent context about your project — architecture, conventions, patterns, and constraints.
Without CLAUDE.md, Claude Code guesses. With it, Claude Code operates like a team member who’s read your contributing guide, your architecture docs, and your style guide.
My CLAUDE.md Template
What Makes a Good CLAUDE.md
The key is specificity over verbosity. Don’t describe what TypeScript is. Tell Claude Code exactly how your project uses it. Reference example files. Instead of writing paragraphs about your coding style, point to a file: “Seesrc/actions/prompts.ts for the server action pattern.” Claude Code will read that file and replicate the patterns.
Include commands. Claude Code needs to know how to run your tests, start your dev server, and check types. If it doesn’t know pnpm test, it can’t verify its own work.
List anti-patterns. “No barrel exports” saves you from undoing Claude Code’s well-intentioned refactoring toward a pattern you don’t use.
Nested CLAUDE.md Files
For monorepos or complex projects, use nestedCLAUDE.md files in subdirectories. Claude Code merges them hierarchically — the root file provides global context, and subdirectory files add local specifics.
Custom Slash Commands
Claude Code supports custom slash commands that you define in.claude/commands/. These are reusable prompts for tasks you do repeatedly.
Setting Up Commands
/add-feature user preferences with email notification settings and get a structured, multi-step implementation.
Commands I Use Daily
| Command | Purpose |
|---|---|
/add-feature | Scaffold and implement a new feature end-to-end |
/review | Code review of uncommitted changes |
/test-gen | Generate tests for a specific file or function |
/fix | Diagnose and fix a bug from an error message |
/refactor | Refactor a specific module with constraints |
/migrate | Database migration for a schema change |
/document | Generate documentation for a module |
The “Architect Then Implement” Pattern
This is the workflow pattern that most improved my output quality with Claude Code. Instead of asking Claude Code to implement a feature directly, I split the work into two phases.Phase 1: Architect
Phase 2: Implement
Multi-File Refactors
This is where Claude Code truly shines. Refactors that touch dozens of files and require maintaining consistency across all of them.Example: Migrating from Express to Hono
Example: Adding TypeScript Strict Mode
The Key to Good Refactors
Be explicit about constraints. “Don’t change the public API” or “maintain backward compatibility” prevents Claude Code from making sweeping changes that break consumers. Specify the verification step. “Run tests after each file” ensures Claude Code catches regressions incrementally rather than creating a mess that’s hard to debug. Order of operations matters. “Start with leaf modules” prevents cascading type errors that make the refactor feel impossible.Code Review and Bug Hunting
Claude Code is an excellent code reviewer because it can actually read and run the code, not just look at diffs.Using Claude Code for Reviews
Bug Hunting
When a bug report comes in, I paste the reproduction steps into Claude Code:.max(10) in the Zod schema that someone added months ago, and identifies the root cause in minutes.
Test Generation Workflows
My test generation workflow with Claude Code follows a specific pattern that produces better tests than “write tests for this file.”Conversation Management
Knowing when to start a fresh conversation versus continuing an existing one is an underappreciated skill.Start Fresh When
- You’re switching to a completely different task
- The conversation has accumulated errors or wrong assumptions
- Claude Code seems confused about the current state of files (it made changes but is referring to old versions)
- You’ve made significant manual changes that Claude Code doesn’t know about
- The context window is getting full (you’ll notice slower responses and more mistakes)
Continue When
- You’re iterating on the same feature
- Claude Code needs to remember decisions from earlier in the conversation (“use SSE, not WebSocket”)
- You’re in a debug loop — context about what’s been tried is valuable
- The review/implementation cycle is ongoing
The “Checkpoint” Technique
For long sessions, I periodically create checkpoints:Claude Code + Git Workflows
Claude Code understands git natively. I use this extensively.Branch-Per-Feature with Claude Code
Pre-PR Cleanup
Handling Merge Conflicts
Dealing with Context Limits
Claude Code has a large context window, but it’s not infinite. Here’s how I work within the limits. Scope your requests. “Refactor the entire codebase” will exhaust context. “Refactor the authentication module” won’t. Use file references, not pastes. Claude Code can read files itself. Don’t paste entire files into the conversation — tell it which files to read. Summarize previous work. If a conversation is getting long, summarize what’s been done and start a new conversation with that summary. Break large tasks into subtasks. Instead of one conversation that implements an entire feature, use separate conversations for architecture, implementation, testing, and review.Integration with CI/CD
Claude Code output should flow through the same quality gates as human-written code.Real Examples from Shipping
PromptLib: Building the Prompt Version History
I used the architect-then-implement pattern: Architect phase: Claude Code analyzed the existing prompt schema, proposed aprompt_versions table with a foreign key to prompts, designed the server action for creating versions, and identified that the UI needed a diff viewer component.
Implement phase: Over a 45-minute session, Claude Code created the migration, updated the schema, wrote server actions for creating and fetching versions, built a version history sidebar component, added a simple diff view, wrote tests, and made 6 atomic commits.
I spent my time reviewing diffs and testing the UI manually. Total wall-clock time: about 90 minutes for what would have been a full day of work.
MetaLabs: API Rate Limiter Refactor
The existing rate limiter was per-route with duplicated logic. I asked Claude Code to extract it into a configurable middleware. It read all 23 route files, identified the rate limiting patterns, designed a unified middleware with per-route configuration, migrated every route, and updated the tests. Zero regressions.Tips Nobody Tells You
Start with a warm-up. Before asking Claude Code to implement anything, ask it to read key files first: “ReadCLAUDE.md, src/db/schema.ts, and src/actions/prompts.ts. Then tell me what patterns you see.” This loads context before the real work begins.
Be specific about what not to change. “Implement notifications but don’t modify the existing Prompt type or change any existing API endpoints” prevents scope creep.
Use Claude Code to write CLAUDE.md. Ask it to read your codebase and generate a CLAUDE.md file. Then edit it. This is faster than writing from scratch and catches conventions you’ve internalized but never documented.
Check Claude Code’s shell commands. Before approving destructive commands (rm, database operations), read them carefully. Claude Code is generally cautious, but mistakes happen.
Pair Claude Code with Cursor. I use Claude Code in a terminal pane inside Cursor. Claude Code makes the big changes, and I use Cursor’s inline editing for quick touch-ups on Claude Code’s output. Best of both worlds.
Common Pitfalls
Over-scoping. “Refactor the entire application to use a new state management approach” is too much. Break it into modules. Under-specifying. “Add auth” could mean anything. “Add GitHub OAuth with NextAuth.js, protected routes via middleware, and a session provider in the root layout” gets good results. Not reviewing output. Claude Code is good, not perfect. Review every change, especially security-sensitive code, database migrations, and deletion operations. Ignoring the test suite. If Claude Code generates code that passes the type checker but you don’t have tests, you’re flying blind. The power of Claude Code is the feedback loop: implement → test → fix → verify. Without tests, it’s just implement → hope. Fighting the tool. If Claude Code’s approach is fundamentally different from what you want, don’t try to steer it incrementally through 10 corrections. Start a new conversation with clearer instructions.Claude Code is a force multiplier, not a replacement for engineering judgment. The developers who get the most out of it are the ones who know exactly what they want built and use Claude Code to build it faster — not the ones who ask Claude Code to make architectural decisions for them.
CLAUDE.md and custom commands, is the fastest way I’ve ever shipped software.