Claude Code Tips
Double Your Productivity, Halve Your Token Usage
Claude Code is Anthropic's AI coding assistant that lives in your terminal — writing code, fixing bugs, and refactoring projects. But used poorly, it wastes tokens and delivers mediocre results. Here are the practical tips compiled from daily use to help you get the most out of Claude Code.
// Be Specific
1. Be Specific with Your Requests
80% of Claude Code's quality depends on how you describe what you need.
❌
Optimize this functionToo vague. Claude Code doesn't know what to optimize — performance? Readability? Memory? Compatibility?
✅
Optimize this function's performance:
- Currently processes 10,000 records in 3 seconds, target is under 500ms
- Don't change the function signature or return type
- Prefer algorithm optimization over cachingThe 5W1H Framework
| Element | ||
| What to Include | ||
| Example | ||
| What | What to do | Optimize the sort function |
| Why | The reason | Currently takes 3s, too slow |
| Where | Which file | src/utils/sort.ts |
| When | In what context | When processing large datasets |
| Which | Constraints | Don't change the function signature |
| How | Expected outcome | Under 500ms |
The more specific your description, the more accurate the result — and fewer back-and-forth rounds means fewer tokens wasted.
// @References
2. Master the @ Syntax for Context
Claude Code supports @ references to point it at exactly the right files.
Common @ Commands
@file.ts # Reference a single file
@src/utils/ # Reference an entire directory
@package.json # Reference a config file
@git diff # Reference Git diff
@git log -5 # Reference last 5 commitsWhy This Saves Tokens
- No need to copy-paste code into the conversation
- Claude Code only reads referenced files, not the entire project
- Avoids misunderstandings from insufficient context
@src/api/user.ts Add pagination to this module,
following the same pattern as @src/api/order.ts// One Task
3. One Task at a Time
This is the most overlooked token-saving technique.
❌
Help me:
1. Add pagination to user module
2. Write unit tests
3. Optimize API response speed
4. Update the frontend list component
5. Update docsToo many tasks at once — Claude Code will likely miss requirements, produce inconsistent code, generate lots of unnecessary code, and burn through tokens.
✅
Step 1: Add pagination to user module, 20 items per page, with page number navigationStep 2: Write unit tests for the pagination feature we just built💡 One task at a time. Confirm completion before moving on. Better quality, fewer tokens.
// CLAUDE.md
4. Use CLAUDE.md for Project Memory
Claude Code reads a CLAUDE.md file in your project root for persistent context.
What to Put in CLAUDE.md
# Project Overview
- Tech stack: Next.js 14 + TypeScript + Prisma + PostgreSQL
- Code style: ESLint + Prettier, single quotes, 2-space indent
- Naming: PascalCase for components, camelCase for functions
- Test framework: Vitest
- API style: RESTful, response format: { code, data, message }
- Don't modify migration files
- Commit format: feat/fix/docs: descriptionWhy This Matters
- Claude Code reads CLAUDE.md automatically every session
- No need to repeat project conventions each time
- Generated code stays consistent
- Significantly reduces back-and-forth token usage
// Slash Commands
5. Use Built-In Slash Commands
Claude Code includes slash commands that save time and tokens.
| Command | ||
| Purpose | ||
| Token-Saving Benefit | ||
| /compact | Compress conversation history | Reduces context length for subsequent requests |
| /clear | Clear conversation history | Fresh start, removes irrelevant context |
| /bug | Auto-diagnose bugs | More precise than manual descriptions |
| /review | Code review | Auto-checks your recent changes |
| /init | Initialize CLAUDE.md | Auto-generates project config |
When to Use /compact
When the conversation gets long and Claude Code starts "forgetting" earlier agreements, run /compact. It compresses history while keeping key information, dramatically reducing token consumption for future requests.
// Plan First
6. Let Claude Code Plan Before Coding
A common mistake: asking Claude Code to write code immediately.
✅
First, review @src/api/user.ts and @src/types/user.d.ts
to understand the existing user module structure.
Then tell me how you plan to implement pagination.
I'll confirm before you start coding.- Avoids code that doesn't match expectations
- Reduces "write, discard, rewrite" token waste
- You catch misaligned thinking early
💡 Align understanding first, then code. This alone saves ~30% of wasted tokens.
// Model Selection
7. Choose the Right Model
| Model | ||
| Best For | ||
| Token Cost | ||
| Claude Sonnet | Daily development, code gen, bug fixes | Medium |
| Claude Opus | Complex architecture, large refactors | Higher |
| Claude Haiku | Simple edits, formatting, quick Q&A | Lowest |
Cost Strategy
- Haiku for simple tasks: Rename a variable, format code, write a simple function
- Sonnet for daily work: Feature development, bug fixes, write tests
- Opus for complex tasks only: Architecture design, large-scale refactoring, complex algorithms
Switch models: /model claude-3-haiku-20240307
// Avoid Waste
8. Avoid Common Token Wastes
1. Don't Repeatedly Explain the Same Things
Write project conventions in CLAUDE.md (see Section 4) instead of repeating them every conversation.
2. Don't Ask Claude Code to Do What It's Bad At
Claude Code excels at writing code, but struggles with: running large test suites (run locally instead), handling very long files (split files over 500 lines first), and making design decisions (you decide, it executes).
3. Don't Paste Large Code Blocks in Chat
Use @ to reference files. Pasted code wastes tokens by duplicating content already on disk.
4. Clean Up Conversations Regularly
After 20+ exchanges, use /compact to compress or /clear to start fresh.
// Prompt Templates
9. Ready-to-Use Prompt Templates
Here are battle-tested prompt templates you can copy directly:
📝 Building a New Feature
In @src/api/user.ts, add a function to look up users by email.
Requirements:
- Function name: getUserByEmail
- Parameter: email: string
- Return: User | null
- Return null if user doesn't exist, don't throw
- Follow the style of the existing getUserById function🐛 Fixing a Bug
The createOrder function at line 45 in @src/api/order.ts
produces duplicate inserts under concurrent calls.
Investigate and fix this issue.
Only modify the minimum necessary code, don't refactor anything else.🧪 Writing Tests
Write unit tests for validateEmail and validatePhone in @src/utils/validate.ts.
Requirements:
- Use Vitest
- Cover normal cases and edge cases
- Place the test file in the same directory as validate.test.ts👀 Code Review
Review my recent changes @git diff.
Focus on:
1. Security vulnerabilities (SQL injection, XSS)
2. Performance issues
3. Compliance with project code standards
Only list genuine issues, don't nitpick.// Token Comparison
10. Token Usage Comparison
Same requirement, three different approaches:
| Approach | ||
| Token Usage | ||
| Code Quality | ||
| Vague description + multiple tasks at once | ⭐⭐⭐⭐⭐ | ⭐⭐ |
| Specific description + one task at a time | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| Specific + @references + CLAUDE.md | ⭐⭐ | ⭐⭐⭐⭐⭐ |
💡 Invest time upfront in context management, and you'll reduce token usage by 50%+ over time.
// Summary
Summary
Claude Code efficiency comes down to three things:
01
Be Specific
Tell it exactly what you want, don't make the AI guess
02
Manage Context
Leverage @references and CLAUDE.md
03
Break Tasks Down
One task at a time, confirm before proceeding
Build these habits and your productivity (and token efficiency) will improve dramatically.
Need Reliable Claude Code Relay?
Compare 10+ relay platforms on price and stability
View Claude Code Setup Guide