How I Cut My Claude Code Bill by 60% Without Losing Productivity

Published: (February 22, 2026 at 02:16 AM EST)
7 min read
Source: Dev.to

Source: Dev.to

Ethan Nguyen

My first full month using Claude Code on a Kotlin Multiplatform project cost me $340. My second month? $127. Same project, same velocity, same output quality. The difference was understanding where tokens actually go — and stopping the bleeding at the source.

This isn’t about using Claude Code less. It’s about using it smarter. Below are the strategies that made the difference, with real numbers from my workflow.

The Hidden Cost: Context Window Bloat

The biggest cost driver isn’t how many prompts you send. It’s how much context you carry in each one. Every message in a Claude Code session includes the full conversation history. By message 30 in a session you’re sending 30 previous exchanges plus your new prompt — and paying for every token.

I tracked my sessions for a week. The pattern was clear:

Session LengthAvg Cost Per PromptTotal Session Cost
1‑10 messages$0.08$0.50
11‑25 messages$0.35$6.50
26‑50 messages$0.90$28.00
50+ messages$1.80$72.00+

The cost per prompt increases exponentially because context accumulates. A 50‑message session doesn’t cost 5× a 10‑message session — it costs 50× or more.

Strategy 1: The 15‑Message Rule

Start a new session every 15 messages—no exceptions. Before resetting, write a quick summary of what you’ve accomplished and what’s next, then start fresh with a focused prompt.

Before: One marathon session (47 messages) → $34
After:  Three focused sessions (15+15+12) → $9

The /compact command helps too—it compresses your context when things get long. But starting fresh is even better because you can re‑frame the problem with only the relevant context.

The workflow

  1. Work for ~15 messages.
  2. Run /cost to check your spend.
  3. If the context is getting heavy, note your progress.
  4. Start a new session with a focused prompt that includes only what’s needed.

Strategy 2: Stop Dumping Entire Files

My worst habit was pasting whole files. “Look at this file” → 500 lines → Claude reads everything, burning tokens on imports, boilerplate, and irrelevant code.

Before

Read src/shared/data/repository/UserRepository.kt and fix the caching bug

Result: The entire 400‑line file goes into context; ~350 lines are irrelevant.

After

In src/shared/data/repository/UserRepository.kt, the getCachedUser()
function (around line 45‑60) returns stale data when the cache TTL expires.
The issue is in the timestamp comparison. Fix the cache invalidation logic.

Result: Claude knows exactly where to look, reads only the relevant section, and produces a faster, cheaper, more accurate response.

Savings: ~40 % reduction in input tokens per file‑editing task.

Strategy 3: Use One‑Shot Mode for Simple Tasks

Interactive mode is great for exploration and multi‑step work, but for simple, well‑defined tasks one‑shot mode (claude -p) is dramatically cheaper.

Interactive mode (simple task)

claude
> "Add a debug log in processPayment() before the API call"
# Minimum cost: ~$0.15 even for a one‑liner

One‑shot mode

claude -p "Add console.log('Processing payment:', amount) before
the fetch call in src/api/payments.ts:42"
# Cost: ~$0.03

I now use one‑shot mode for:

  • Adding log statements
  • Simple find‑and‑replace operations
  • Generating boilerplate (interfaces, data classes)
  • Quick explanations (“what does this regex do?”)

Rule of thumb: If you can describe the task in one sentence and don’t need back‑and‑forth, use -p.

Strategy 4: CLAUDE.md as a Cost Weapon

A well‑written CLAUDE.md file reduces costs in a way most people don’t realize. When Claude Code understands your project structure, conventions, and patterns upfront, it asks fewer clarifying questions and makes fewer wrong guesses.

Without CLAUDE.md

Prompt: "Add a new API endpoint for user preferences"
Claude: *reads 12 files to understand your project structure*
Claude: *asks 3 follow‑up questions about your patterns*
Claude: *generates code using wrong conventions*
You: "No, we use repository pattern, not direct DB calls"
Claude: *regenerates everything*
Total: 8 messages, $4.20

With CLAUDE.md

Prompt: "Add a new API endpoint for user preferences"
Claude: *reads CLAUDE.md, knows your patterns*
Claude: *generates correct code on first try*
Total: 2 messages, $0.45

Key things to include in CLAUDE.md

  • Project structure and architecture patterns
  • Naming conventions
  • File‑organization rules
  • Common patterns (error handling, logging, testing)
  • Dependencies and their usage patterns

The 30 minutes you spend writing CLAUDE.md pays for itself in the first week.

Instead of making one change per prompt, batch related changes together. Each prompt has a base cost (the context window), so fewer prompts = lower total cost.

Expensive approach (5 separate prompts)

1. "Add email field to User model"
2. "Update UserRepository to handle email"
3. "Add validation for email in the UI"
4. "Write unit tests for email handling"
5. "Update API docs for the new field"

Cost: 5 × base + context ≈ $2.50

Batch approach (single prompt)

"Add an email field to the User model, update UserRepository,
add UI validation, write unit tests, and update API docs."

Cost: 1 × base + slightly larger context ≈ $0.80

Batching reduces the number of context reloads and cuts the overall spend dramatically.

Bottom Line

  • Trim context: reset every ~15 messages, use /compact, and avoid full‑file dumps.
  • Pick the right mode: one‑shot for simple tasks, interactive for complex, multi‑step work.
  • Invest in project metadata: a concise CLAUDE.md pays for itself quickly.
  • Batch related edits: fewer prompts = lower base cost.

Apply these habits and you’ll see your Claude Code bill shrink from hundreds of dollars to a fraction—without sacrificing speed or quality. Happy coding!

Adding an Email Field to the User System

Below is a concise plan for adding an email field to the user system, followed by a cost‑saving comparison of two prompting approaches.

Prompt Outline (5‑step plan)

  1. Add email to the data modelemail: String in the User data class.
  2. Persist email – Update UserRepository.createUser() to store the new field.
  3. Validate email – Add email validation (standard regex) in CreateUserUseCase.
  4. Update API – Modify the POST /users endpoint to accept and return the email.
  5. Expose email – Include email in the UserResponse DTO.

Note: Follow the existing patterns described in CLAUDE.md.

Cost Comparison

ApproachPrompt(s)Approx. Cost
Multi‑prompt5 separate prompts (one per step)~$3.50
One‑shot1 comprehensive prompt (all steps)~$0.90

Savings: ~75 % reduction in cost for the same work.

Strategies for Ongoing Cost Management

Strategy 6 – The Cost Dashboard Habit

  • Run /cost every 5 messages.
  • Track daily spend in a simple spreadsheet.
  • Use the data to spot costly habits (e.g., long sessions, unnecessary file reads).

Monthly Cost Breakdown (Before vs. After)

CategoryBeforeAfterSavings
Long sessions (50+ messages)$180$0100 %
Medium sessions (15‑30 messages)$95$5245 %
Simple tasks (interactive mode)$45$1273 %
Exploration / reading code$20$1810 %
Total$340$12763 %

The biggest win was eliminating marathon sessions entirely; the second was using one‑shot mode for simple tasks.

What NOT to Optimize

  • Don’t avoid Claude Code when it saves you hours. A $2 prompt that prevents 30 minutes of debugging is a bargain.
  • Don’t write vague prompts to save tokens; they often require multiple follow‑ups, increasing total cost.
  • Don’t skip reading files when context is needed. The token cost of reading a file is tiny compared to generating incorrect code.

The goal is to eliminate waste, not to eliminate usage.

Key Takeaways

  • Start new sessions every ~15 messages – context accumulation is the #1 cost driver.
  • Point to specific lines, not whole files – reduces input tokens by ~40 %.
  • Use claude -p for simple tasks – up to 5× cheaper than interactive mode.
  • Invest in CLAUDE.md – it pays for itself within a week.
  • Batch related changes – one comprehensive prompt beats many small ones.
  • Check /cost every 5 messages – awareness changes behavior.

These numbers come from personal usage on a Kotlin Multiplatform project. Your costs will vary based on plan, project size, and usage patterns, but the percentages and strategies apply universally.

0 views
Back to Blog

Related posts

Read more »