How to Use Claude Code Efficiently: 20 Tips for Optimal Token Usage
Claude Code AI Tools Productivity Developer Tips LLM

How to Use Claude Code Efficiently: 20 Tips for Optimal Token Usage

February 22, 2026 14 min read

Learn 20 practical tips to get more done with Claude Code while using fewer tokens. Beginner-friendly guide covering prompts, CLAUDE.md, subagents, /clear, /compact, and more.

If you've just discovered Claude Code — Anthropic's AI-powered coding assistant — you're probably amazed at what it can do. But like any powerful tool, the way you use it makes all the difference. Every message you send, every file you paste, every question you ask costs tokens — the currency that powers Claude's responses.

Think of tokens like mobile data. You have a budget per session, and burning it on unnecessary back-and-forth means you hit the limit before your work is done. The good news? With a few smart habits, you can accomplish significantly more with the same token budget — and your sessions will feel faster, cleaner, and more productive.

Whether you're brand new to AI coding assistants or you've been using Claude Code for a while, these 20 practical tips will help you work smarter, not harder.

🚀 Haven't set up Claude Code yet? Read our guide first: How to Install and Set Up Claude Code →


1. Use /clear Frequently — Start Fresh Between Tasks

Claude remembers everything in your current conversation. That's great when it's relevant — but when you switch from fixing a CSS bug to working on a database migration, all that old context is just dead weight consuming tokens on every new message.

The /clear command wipes the conversation history and gives Claude a clean slate. Think of it like opening a brand new tab in your browser.

✅ Example:

# You finished fixing the login bug. Now you want to work on the API.
/clear
# Now ask your new question — Claude starts fresh with zero baggage
"Create a REST endpoint in HomeController.cs for fetching blog posts by tag."

Rule of thumb: If your next task is unrelated to the last one, use /clear before you start.


2. Be Hyper-Specific in Your Prompts

Vague prompts produce vague (and often incorrect) results. Worse, when Claude gets it wrong, you spend more tokens explaining what you actually wanted. Being specific from the start means fewer correction rounds and fewer tokens wasted.

❌ Vague (costs more tokens to fix later):

"Fix my blog code."

✅ Specific (Claude gets it right the first time):

"Edit the generateSlug() function in blog.js between lines 45–60.
The current slug doesn't strip special characters like & and @.
Strip all non-alphanumeric characters except hyphens, and lowercase the result."

The more context you provide upfront, the less back-and-forth is needed. Include: the file name, the function name, the exact behaviour you want, and any constraints.


3. Reference Files — Don't Paste Them Into Chat

A common beginner mistake is copy-pasting entire files into the chat window. This is one of the fastest ways to burn your token budget. Claude Code can read files directly — you just need to tell it where to look.

❌ Don't do this:

"Here's my entire HomeController.cs: [pastes 300 lines of code]
Now fix the Index() method."

✅ Do this instead:

"Read HomeController.cs and fix the Index() method to handle null TechCategories gracefully."

Claude Code uses tools to read the file itself — only pulling in what it needs. This keeps your token count lean.


4. Use --print / Headless Mode for Repeatable Tasks

If you run the same type of task repeatedly — like generating boilerplate, formatting files, or running checks — you don't need a full interactive session every time. Claude Code's headless mode (using the --print flag) lets you fire off a one-shot command from the terminal and get the result directly, without any back-and-forth dialogue.

✅ Example — generate a model class in one shot:

claude --print "Create a C# record class named ProductRecord with Id (int), Name (string), Price (decimal), and IsActive (bool) properties. Return only the code, no explanation."

Perfect for CI/CD pipelines, scripts, and repetitive code generation tasks. No interactive session = minimal token overhead.


5. Break Work Into Atomic Tasks

It's tempting to throw a massive task at Claude all at once — "Build me a full e-commerce checkout flow with payment integration, order history, email receipts, and admin panel." But large, multi-part instructions lead to longer contexts, more corrections, and more wasted tokens.

Atomic tasks are small, single-purpose, self-contained. One task per session keeps Claude focused and the context lean.

✅ Instead of one giant prompt, break it down:

Session 1: "Create the Order model in Data/PortfolioDbContext.cs."
Session 2: /clear → "Create a POST endpoint in OrderController.cs to create a new order."
Session 3: /clear → "Add email notification logic to the order creation flow in OrderController.cs."

Each session is focused, fast, and efficient.


6. Don't Ask Claude to "Explain as You Go"

Explanations are verbose. If you ask Claude to explain every step while it writes code, you're doubling (or tripling) the token cost of every response. Unless you're learning something new, skip the running commentary.

❌ Token-heavy:

"Write a function to paginate blog posts and explain what each line does."

✅ Token-efficient:

"Write a function to paginate blog posts. Return only the code."

If you later want to understand a specific part, ask about just that part in a follow-up — or use /clear and start a new focused explanation session.


7. Use CLAUDE.md for Persistent Context

Every new session, Claude starts with no memory of your project. Without a CLAUDE.md file, you'll waste tokens re-explaining your stack, conventions, and rules at the start of every session.

A CLAUDE.md file in your project root is automatically read by Claude Code at the start of every session. Put your project context there once, and never repeat yourself again.

✅ Example CLAUDE.md:

# Project: sachith.me

## Stack
- ASP.NET Core 8 MVC (C#)
- SQL Server with Entity Framework Core
- Razor views (no Layout — each view is self-contained)

## Conventions
- Use async/await for all DB operations
- Connection string key: "PortfolioDb"
- All controllers live in /Controllers
- Views match controller names in /Views/{ControllerName}

## Do Not
- Do not add Swagger or API versioning
- Do not create Layout.cshtml — views use Layout = null

This single file saves you from typing the same project overview over and over.


8. Avoid Re-Uploading Unchanged Files

Only bring files into the conversation that are directly relevant to the current task. If you're fixing a bug in BlogController.cs, Claude doesn't need to know about your CSS files, image assets, or unrelated controllers.

✅ Before starting, ask yourself:

  • What is the minimum set of files Claude needs to understand this task?
  • Are any of these files unchanged since last session? (Don't re-add them)
  • Can I describe the relevant parts instead of showing the whole file?

Keeping the active context small keeps responses faster and cheaper.


9. Use /compact to Compress Long Conversations

In long sessions, your conversation history grows and grows. Eventually, old messages are taking up token space even though they're no longer relevant. The /compact command tells Claude to summarize the conversation so far into a compact checkpoint — keeping the key context while dropping unnecessary detail.

✅ When to use it:

# You've been working for 30+ minutes on a complex feature
# and your context is getting long...
/compact
# Claude summarizes what's been done, then you continue cleanly

Think of it as hitting "Save checkpoint" in a video game — you preserve your progress without carrying all the baggage.


10. Chain Tasks in One Prompt

Each message you send has a fixed overhead of tokens just for processing. So sending 4 separate short messages costs more than sending 1 well-structured message that asks for all 4 things at once.

❌ 4 separate messages (4x overhead):

"Create the file."
"Add frontmatter to it."
"Write the introduction."
"Add the export statement."

✅ One chained prompt (1x overhead):

"In /posts/new-post.mdx:
1. Create the file with the correct MDX frontmatter (title, date, tags, slug)
2. Write a 2-paragraph introduction about Claude Code efficiency
3. Add the default export at the bottom
Return only the file content."

One message, four tasks done. Cleaner and cheaper.


11. Use Subagents Wisely

Claude Code supports subagents — specialized agents that handle a focused portion of work independently. Instead of one massive instruction that tries to do everything (and builds up a huge context), you spawn a subagent for each focused sub-task.

✅ Good use of subagents:

"Use a subagent to: find all TODO comments in the /Controllers folder.
Use a separate subagent to: check all Razor views for missing @model declarations.
Report results separately."

Each subagent works in its own lean context. The main agent doesn't get bloated with every detail. This is especially powerful for large codebases.

💡 Want to understand how AI agents work in code? Read: Using AI Agents as Your Code Assistant →


12. Cut the Conversational Filler

This one surprises people, but it's real: words like "please", "can you", "I was wondering if", and "thanks in advance" are not just unnecessary — they cost tokens. Every word in your message is processed and counted.

❌ Polite but wasteful:

"Hi Claude! I was wondering if you could please help me fix the authentication bug in my login controller? Thank you so much!"

✅ Direct and efficient:

"Fix the authentication bug in AuthController.cs — the Login() method returns 401 even with correct credentials."

Claude doesn't have feelings to hurt. Be direct. You'll get better results faster with fewer tokens.


13. Use Diff-Style Edits — Not Full File Rewrites

When you ask Claude to "update my file", a naive response rewrites the entire file — hundreds of lines — when only 5 needed to change. This is massively wasteful on both input and output tokens.

✅ Ask for diffs or targeted edits:

"In HomeController.cs, update only the Index() method to add a null check for TechCategories.
Return only the updated method — not the entire file."

Or even better:

"Show me the exact lines to change in Index() using a before/after format."

You apply the change manually — Claude only shows what needs to change. Fast, cheap, precise.


14. Set Output Format Upfront

Without format instructions, Claude will often include explanatory prose, markdown headers, notes, caveats, and "Here's your code:" preambles. All of that is tokens you didn't ask for.

✅ Format instructions that save tokens:

"Return only the JSON object. No explanation."
"Return only the C# method. No surrounding class, no comments."
"Respond in a single code block. No prose before or after."
"Output only the SQL query. Nothing else."

Adding just one format instruction at the end of your prompt dramatically cuts response length.


15. Avoid Open-Ended Questions — Direct the Approach

Open-ended questions like "What's the best way to do X?" trigger lengthy, exploratory responses that cover multiple options, tradeoffs, and considerations. Great for learning — but terrible for token efficiency.

❌ Open-ended (triggers a long essay):

"What's the best way to handle caching in my ASP.NET Core app?"

✅ Directed (triggers a focused answer):

"Add IMemoryCache to HomeController.cs to cache the blog post list for 5 minutes. Use the constructor injection pattern."

You've already decided the approach — you just need Claude to implement it. That's one short focused response instead of a three-page comparison article.


16. Use .claudeignore to Exclude Irrelevant Files

Just like .gitignore tells Git what to ignore, a .claudeignore file tells Claude Code what files and folders to never include in its context. Without this, Claude might accidentally pull in node_modules, dist folders, build artifacts, or test fixtures — all completely irrelevant to your task.

✅ Example .claudeignore:

node_modules/
dist/
.git/
bin/
obj/
*.min.js
*.min.css
publish/
uploads/
*.log

Place this file in your project root. Claude will respect it and keep your context focused on what actually matters.


17. Reuse Successful Prompt Patterns as Templates

When you find a prompt that works really well — saves tokens, gets accurate results on the first try — save it. Build yourself a personal library of prompt templates for your most common tasks.

✅ Example template library (save in a text file or CLAUDE.md):

## Create a new Controller
"Create [ControllerName]Controller.cs in /Controllers.
Inject PortfolioDbContext via constructor.
Add [action] async action returning IActionResult.
No comments, no XML docs. Return only the code."

## Fix a bug
"Read [filename]. Fix [specific issue] in [method name].
Return only the changed method using before/after diff format."

## Add a new DB model
"Add a new [ModelName] record class to PortfolioDbContext.cs.
Fields: [list fields with types].
Register the DbSet and add ToTable mapping.
Return only the added code."

Templates eliminate redrafting from scratch every time. Fill in the blanks, send, done.


18. Limit Error Context — Paste Only What's Relevant

When something breaks, the instinct is to paste the entire terminal output into the chat. Stack traces can be hundreds of lines long — most of it is framework internals that Claude doesn't need to see.

❌ Wasteful — dumping the whole stack trace:

"Here's my error: [pastes 200 lines of exception stack trace]"

✅ Efficient — paste only the meaningful lines:

"Getting this error on HomeController.cs line 26:
InvalidOperationException: The ConnectionString property has not been initialized.
Connection string key is 'PortfolioDb'. What's wrong?"

The first line of the exception message + the file/line reference is almost always enough for Claude to diagnose the problem.


19. Use Tools Over Conversation

There's a big difference between describing what you want done and telling Claude to do it using its tools. When you use Claude Code's built-in tools (file reads, file writes, shell commands), you skip the conversational overhead of Claude explaining what it's about to do, asking for confirmation, and summarising what it did.

❌ Conversational (verbose):

"Can you look at my project structure and tell me what files I have, and then maybe open the HomeController and check if it has an Error method, and if not explain what I need to add?"

✅ Tool-driven (direct):

"Read HomeController.cs. If there is no Error() action, add it now with the standard IExceptionHandlerPathFeature pattern."

Claude reads the file, checks, and acts — no commentary, no asking permission, no summary. Just results.


20. Plan Before You Prompt

This is arguably the most impactful tip of all. Spend 2 minutes thinking through your task before you type anything. Sketch out what you want, which files are involved, what the expected output is. A clear mental model before you start means a clearer prompt — and a clearer prompt means fewer correction rounds.

✅ Quick planning checklist (before every session):

  • What exact outcome do I need? (not "fix it" — be specific)
  • Which file(s) does this involve?
  • What approach do I want Claude to use?
  • What format should the output be in?
  • What should Claude not do or change?

✅ Example of a well-planned prompt:

"In BlogController.cs, update the Detail() action (currently line 14).
Add a ViewBag.RelatedCount property set to the count of related posts.
Do not change any other logic. Return only the updated Detail() method."

Thirty seconds of planning = one clean prompt = one correct response = zero wasted tokens.


Wrapping Up

Getting great results from Claude Code isn't just about what you ask — it's about how you ask it. These 20 habits aren't complex, but together they can dramatically reduce your token consumption while actually improving the quality of Claude's output.

Start with the easiest wins: use /clear between tasks, be specific in your prompts, set a CLAUDE.md file, and cut conversational filler. Once those feel natural, layer in the more advanced techniques like subagents, diff-style edits, and headless mode.

The goal isn't to talk to Claude less — it's to make every message count. Work smarter, ship faster, and get more done with every session.

🛠️ Ready to dive deeper? Check out these guides on sachith.me:
How to Install and Set Up Claude Code
Using AI Agents as Your Code Assistant


References & Further Reading

Share this article
All Posts
Get In Touch Portfolio