Claude Code is the most powerful AI coding tool available today. But most developers use maybe 20% of what it can do. They type a prompt, get code back, and move on.
This article shows you the other 80%. The patterns, commands, and workflows that separate casual users from power users.
If you have not set up Claude Code yet, start with the Claude Code Setup Guide. This article assumes you can already run claude in your terminal and have used it for basic tasks.
Model Switching: Your Biggest Cost Lever
Claude Code gives you access to multiple models. The default is usually Opus (the most capable), but Sonnet is faster and cheaper.
The strategy: Use Sonnet for 80% of your work. Switch to Opus for the hard stuff.
Sonnet is great for:
- Writing boilerplate code
- Simple bug fixes
- Generating tests
- File creation and scaffolding
- Documentation
Opus is worth the cost for:
- Architecture decisions across large codebases
- Complex debugging that requires understanding multiple files
- Refactoring with tricky dependencies
- Code that needs deep reasoning about edge cases
You can switch models mid-conversation. When you hit a hard problem and Sonnet keeps giving wrong answers, switch to Opus for that one question, then switch back.
This simple habit can cut your Claude Code costs by 50-70% without reducing quality.
/init — The First Thing You Should Run
When you open Claude Code in a new project, run /init before doing anything else.
/init
This command tells Claude Code to scan your project and generate a CLAUDE.md file. It looks at your file structure, programming languages, build tools, and patterns. Then it creates a context file that helps Claude understand your project in every future session.
Before /init: Claude Code guesses about your project. It might use the wrong build command, the wrong test framework, or the wrong file structure.
After /init: Claude Code knows your project. It runs the right commands, follows your patterns, and makes fewer mistakes.
The generated CLAUDE.md is a starting point. Review it and add your own details. More on that in the Context Engineering article.
/compact — Managing Long Sessions
Every message you send to Claude Code uses tokens. In a long session, the conversation history grows and eventually hits the context limit. When that happens, Claude starts forgetting earlier parts of the conversation.
The /compact command summarizes the conversation and clears the old messages. This gives you a fresh context window while keeping the important information.
When to compact:
- After finishing a major task and starting a new one
- When Claude starts repeating mistakes it already fixed
- When you see the context usage indicator getting high
- Before starting a complex task that needs maximum context
What to keep in mind:
- After compacting, Claude loses the specific code it saw earlier. It keeps the summary but not the details.
- If you need Claude to reference specific code from earlier, mention the file path again after compacting.
- Compact between tasks, not during them. Compacting in the middle of a refactor can cause Claude to lose track of what it already changed.
/memory — Persistent Knowledge
The /memory command lets Claude Code remember things across sessions. Unlike the conversation history (which is lost when you close the terminal), memory persists.
/memory
This opens a memory file where you can add notes that Claude will read at the start of every session. Use it for:
- Personal preferences: “I prefer functional style over class-based.”
- Common corrections: “Always use pnpm, not npm.”
- Project shortcuts: “The main database is at ./db/main.sqlite.”
Memory is different from CLAUDE.md. CLAUDE.md is project-specific and lives in the repository. Memory is personal and follows you across all projects.
CLAUDE.md Deep Dive
CLAUDE.md is the single most impactful feature in Claude Code. It is a file at the root of your project that tells Claude everything it needs to know.
Here is a real CLAUDE.md structure that works well:
# Project Name
## Tech Stack
- Language, framework, key libraries
## Commands
- Build: `npm run build`
- Test: `npm test`
- Lint: `npm run lint`
## Architecture
- Brief description of how the project is structured
- Where different types of code live
## Coding Standards
- Patterns to follow
- Patterns to avoid
- Naming conventions
## Common Mistakes
- Things Claude gets wrong in this project
- Corrections that need to be repeated
Key insight: The “Common Mistakes” section is the most valuable. Every time Claude makes a mistake you have to correct, add it to this section. Over time, Claude stops making those mistakes.
For a full guide on writing context files, read CLAUDE.md and AGENTS.md Guide.
Permission Model and Trust Levels
Claude Code asks for permission before making changes. This is good for safety but slow for experienced users.
There are three levels of trust:
Ask mode (default): Claude asks before every file edit, every terminal command. Safe but slow.
Auto-edit mode: Claude edits files without asking but still asks before running commands. Good for trusted projects.
Full-auto mode: Claude edits files and runs commands without asking. Fast but use only on projects where you trust the outcomes.
You can also use --allowedTools to give specific permissions:
claude --allowedTools "Edit,Read,Bash(npm run test)"
This lets Claude edit files and run tests without asking, but it still needs permission for other commands. It is the sweet spot for most workflows.
Practical tip: Start in ask mode when you begin a new project. As you build trust with how Claude handles the codebase, gradually increase permissions. Use full-auto only for well-tested projects with a good CI pipeline.
Multi-File Editing Patterns
Claude Code shines at changes that span multiple files. Here are the patterns that work best.
Pattern 1: The Feature Request
Give Claude a complete feature description and let it figure out which files to change:
Add email notification support. When a user creates a new task,
send an email to all team members. Use the existing nodemailer
setup in src/utils/email.ts. Add a notification preferences
table to the database. Create a migration file.
Claude reads the existing code, identifies the files that need changes, and makes all edits in one pass. This is where it is far better than chat-based tools.
Pattern 2: The Refactor
When you need to change a pattern across many files:
Refactor all API endpoints to use the new error handling
middleware. Currently each endpoint has its own try/catch.
Replace with the asyncHandler wrapper from src/middleware/async.ts.
There are about 25 endpoint files in src/routes/.
Claude finds all the files, understands the current pattern, and applies the new pattern consistently.
Pattern 3: The Migration
When you need to update a dependency or change an interface:
The User interface changed — "name" is now split into
"firstName" and "lastName". Update every file that references
user.name. Check the database model, API endpoints, frontend
components, and tests. Do not change the database yet — just
the TypeScript code.
Claude traces the usage through the codebase and updates all references. This kind of change would take an hour manually — Claude does it in minutes.
Git Integration
Claude Code has deep git integration. Here are the commands that save the most time:
Committing with context:
Commit everything with a descriptive commit message based on
what we just changed.
Claude looks at the diff, understands the intent behind the changes, and writes a meaningful commit message. No more “fix stuff” commits.
Creating branches:
Create a new branch called feature/email-notifications
and commit the current changes there.
Reviewing diffs:
Show me what changed in the last 3 commits and explain
each change.
Handling merge conflicts:
There are merge conflicts in src/api/users.ts. Resolve them
keeping our changes for the authentication logic but their
changes for the response format.
This last one is surprisingly useful. Claude understands both sides of the conflict and makes intelligent choices about what to keep.
Subagents: Focused AI Workers
Claude Code can spawn subagents — smaller AI instances focused on a specific task. The main Claude coordinates while subagents handle individual pieces.
This happens automatically when Claude decides a task is complex enough. You will see messages like “Spawning agent to analyze test coverage…” in the output.
You can also guide this:
For each API endpoint in src/routes/, check if it has
corresponding tests. Create missing tests. Work on one
endpoint at a time.
Claude may use subagents to analyze each endpoint independently, then combine the results.
Headless Mode: CI/CD and Automation
One of Claude Code’s most unique features is headless mode. You can run it without an interactive terminal — in CI/CD pipelines, scripts, and automation.
Example: Automated PR review in GitHub Actions:
- name: Review PR with Claude
run: |
echo "Review this PR. Check for bugs, security issues,
and style problems. Post a summary as a PR comment." |
claude --headless --output-format json
Example: Automated code fixes:
# Fix all linting errors automatically
echo "Fix all ESLint errors in the project. Run npm run lint
after each fix to verify." | claude --headless
Example: Generate documentation:
echo "Generate JSDoc comments for all exported functions in
src/utils/ that don't have documentation yet." | claude --headless
Headless mode turns Claude Code from a development tool into an automation tool. You can build entire workflows around it.
Cost Management
Claude Code charges based on tokens — input tokens (what Claude reads) and output tokens (what Claude writes). Large projects with many files can get expensive.
Tips for controlling cost:
Use Sonnet for simple tasks. Opus costs significantly more. Only switch to Opus when you need it.
Compact regularly. Long conversations accumulate tokens. Compact between tasks.
Be specific. “Fix the bug in src/api/users.ts line 42” is cheaper than “find and fix all bugs” because Claude reads fewer files.
Use .claudeignore. Create a
.claudeignorefile (like .gitignore) to exclude files Claude should not read — node_modules, build outputs, large data files.Monitor per-session cost. Claude Code shows token usage in the terminal. Watch it and compact when it gets high.
Set spending limits. Use your Anthropic account settings to set daily and monthly spending caps.
A typical coding session costs a few dollars. A heavy refactoring session on a large codebase can cost more. Monitoring helps you stay in control.
Claude Code + VS Code
There are two ways to use Claude Code with VS Code:
Option 1: Terminal inside VS Code. Open the integrated terminal in VS Code and run claude. Claude Code runs in the terminal panel while you see the file changes in the editor. This is the most common setup.
Option 2: Claude Code VS Code extension. Anthropic offers a VS Code extension that integrates Claude Code into the editor UI. It provides a chat panel, inline suggestions, and tighter integration with the editor.
Most power users prefer Option 1. The terminal gives you full control and all the commands. The extension is more convenient for quick tasks.
Real Session: Refactoring a Module
Here is a condensed transcript of a real session. I needed to refactor an authentication module from callback-based to async/await.
Me: Refactor src/auth/ from callbacks to async/await. There are
6 files in that directory. Keep the same public API — just change
the internal implementation. Run the tests after each file change.
Claude: I'll analyze the auth module first...
[reads all 6 files, identifies callback patterns]
[refactors auth/login.ts — runs tests — passes]
[refactors auth/register.ts — runs tests — passes]
[refactors auth/verify.ts — runs tests — 1 failure]
The test failure is in verify.test.ts line 34. The test was
checking for a callback argument that no longer exists.
I'll update the test.
[updates test — runs tests — all pass]
[continues with remaining 3 files...]
[all files refactored, all tests pass]
Done. Refactored 6 files from callbacks to async/await.
Updated 3 test files. All 47 tests pass.
This took 4 minutes. Doing it manually would have taken 30-45 minutes with high risk of breaking something.
Key Takeaways
- Use Sonnet for 80% of tasks, Opus for complex reasoning. This cuts costs significantly.
- Run
/initon every new project to generate a CLAUDE.md. Then customize it. - Use
/compactbetween tasks to keep your context window fresh. - Start with ask mode permissions, then increase trust as you learn the project.
- Claude Code excels at multi-file edits — features, refactors, and migrations are its sweet spot.
- Headless mode makes Claude Code an automation tool for CI/CD, not just a development tool.
What’s Next?
In the next article, we cover Cursor Mastery — advanced patterns for the most popular AI code editor, including Composer, Agent mode, and .cursorrules.
For a quick reference on Claude Code commands, check the AI Coding Tools Cheat Sheet.
This is part 5 of the Vibe Coding series.