Claude Code Spend Optimization Strategies

Claude Code Spend Optimization Strategies

Written by: Mark Hull, Co-Founder and CEO, Exceeds AI | Last updated: July 13, 2026

Key Takeaways

  • Claude Code token costs now represent an operational and governance problem, not just a prompting issue. Large organizations like Uber have burned through annual AI budgets in a few months.
  • A structured seven-step workflow that includes context clearing, CLAUDE.md trimming, and .claudeignore usage delivers measurable token savings across engineering teams.
  • Model tiering across Haiku, Sonnet, and Opus, combined with prompt caching and batch API usage, cuts spend when matched to task complexity and applied consistently.
  • Commit-level attribution via Exceeds Ink is essential for governance because it tracks per-developer and per-commit spend and proves ROI with auditable data.
  • Teams that want to move from guesswork to measurable AI ROI should book a demo with Exceeds AI to roll out these strategies at scale.

Prerequisites for Running This Seven-Step Workflow

You need Claude Code CLI access with the /usage command available before you start. Confirm your team uses a version that exposes the status-line token counter. You also need a Git repository with commit hooks ready, specifically prepare-commit-msg, post-commit, and post-rewrite, so you can install Exceeds Ink.

Exceeds Ink runs as a single lightweight Rust binary that writes a structured Git Note at refs/notes/exceeds-ink when a commit finalizes. It runs without a long-lived daemon and does not mutate global git config. Without that provenance layer, spend numbers from /usage stay at the session level and never become commit-level proof.

Step 1: Clear Context Between Tasks with /clear

Every token in Claude Code’s active context window is re-sent with each request, which multiplies cost. A session that accumulates file reads, tool outputs, and prior turns across unrelated tasks silently inflates input tokens. Run /clear between distinct tasks so the context window resets to zero.

Common Mistake: Teams often treat a single Claude Code session as a persistent workspace across multiple features. Start each new task with /clear.

Pro Tip: Pair /clear with a short task description in the first message. A focused, scoped prompt costs far fewer tokens than a long, wandering session history.

Troubleshooting: If token counts stay high after /clear, check whether a CLAUDE.md or MCP tool injects a large system prompt at every session start. Address that in Step 2 and Step 3.

Step 2: Trim CLAUDE.md to 200–400 Lines

CLAUDE.md loads into every Claude Code session as part of the system prompt, so bloat there becomes permanent overhead. A file that has grown to 800 or 1,200 lines through accumulated team additions doubles or triples baseline input token cost before anyone sends a message. Audit CLAUDE.md and enforce a 200–400 line ceiling.

The following four-step audit helps you remove bloat while keeping the context your team actually needs:

  1. Run wc -l CLAUDE.md to establish your baseline. This number shows how far you are from the 200–400 line target.
  2. Remove duplicated instructions, outdated context, and prose that restates what the model already knows. This cut delivers the fastest line reduction without hurting behavior.
  3. For content that still matters but does not belong inline, move reference material such as architecture diagrams and full API specs to separate files. Link them by path instead of embedding them directly.
  4. Add a comment at the top of CLAUDE.md: # Target: 200–400 lines. Review before adding. This visible constraint discourages future bloat and reminds editors to prune as they go.

Pro Tip: Treat CLAUDE.md like a lean README. Every line costs money on every request. Remove any line that does not change model behavior.

Common Mistake: Teams often append to CLAUDE.md without deleting anything. Assign a quarterly owner to review and trim the file.

Step 3: Use .claudeignore to Exclude Build Folders and Caches

Claude Code tokenizes every file it reads for context during agent-mode tasks, codebase searches, or tool calls. Build artifacts, compiled outputs, node_modules, .next, dist, and cache directories can add millions of tokens to a single agentic session. Excluding these paths prevents silent cost spikes.

Create a .claudeignore file in the repository root using the same syntax as .gitignore. The example below targets common high-volume directories across JavaScript, Python, and typical build pipelines:

node_modules/ dist/ .next/ build/ *.pyc __pycache__/ .cache/ coverage/ 

Troubleshooting: If Claude Code still reads ignored paths, confirm that .claudeignore sits in the repo root and that your CLI version supports it. If support is missing, use explicit --ignore flags on agent invocations.

Pro Tip: Use the status-line file-read counter to see which directories Claude Code actually reads during a session. Add the highest-volume directories to .claudeignore first.

Step 4: Tier Models and Cap MAX_THINKING_TOKENS

Model tiering and thinking caps prevent routine work from consuming premium tokens. Agentic workflows can draw five to thirty times the tokens of simple completions, so routing every task to Opus or enabling extended thinking on boilerplate work quickly overruns budgets.

Use a three-tier policy that maps cost to complexity and keeps most work on lower-cost models:

  • Haiku: Autocomplete, docstring generation, simple unit tests, and grep-style searches.
  • Sonnet: Feature implementation, refactoring, code review, and moderate debugging.
  • Opus with extended thinking: Architecture decisions, complex multi-file rewrites, and security analysis.

Cap MAX_THINKING_TOKENS in your Claude Code configuration so extended thinking cannot run unbounded on tasks that do not need it:

export MAX_THINKING_TOKENS=8000 

Set this value in your team’s shared shell profile or CI environment so the cap becomes the default for every engineer. After the cap is in place, adjust it upward only on a per-task basis for clearly scoped Opus work that needs extended reasoning.

Common Mistake: Teams often leave MAX_THINKING_TOKENS unset. The default allows extended thinking to consume tens of thousands of tokens on tasks where Sonnet without thinking would produce equivalent output.

Pro Tip: Model and task routing is the single largest lever for managing consumption-pricing exposure. Document the tiering policy in CLAUDE.md so every engineer follows the same rules.

Step 5: Enable Prompt Caching and Batch API for Non-Urgent Work

Prompt caching and batch processing reduce cost on repeat-heavy and non-urgent workloads. Correctly configured prompt caching can cut input tokens by up to 90 percent when you reuse the same system prompt or large context block across requests in a session.

Enable caching by structuring CLAUDE.md and system prompts so stable content appears at the top of the context. Anthropic’s API caches the longest matching prefix, so place volatile content such as task-specific instructions after stable content such as project context and coding standards.

For non-urgent batch work like dependency audits, large-scale refactors, and test generation across a codebase, use the Anthropic Batch API. Batch requests run asynchronously and cost less than synchronous inference. Wire these jobs into CI pipelines that run overnight or on a schedule instead of blocking developer sessions.

Pro Tip: List the five most common Claude Code task types on your team. Move any repetitive and non-blocking tasks to the batch API as soon as possible.

Troubleshooting: If cache hit rates stay low, check whether CLAUDE.md content changes between sessions through dynamic timestamps or user-specific injections. Stabilize the prefix to improve cache efficiency.

Step 6: Monitor Spend with /usage, the Status Line, and Commit-Level Attribution

Monitoring confirms whether your earlier changes actually reduce spend. Once you implement context clearing, CLAUDE.md trimming, model tiering, and caching, you need to measure impact instead of guessing. The /usage command in Claude Code reports token consumption for the current session, and the status line shows a running token counter during agentic tasks.

Both tools help with real-time awareness, but they do not answer the governance question of which commits drive spend and whether tactics reduce cost over time. Zapier tracks employees’ AI token usage via a dashboard and investigates cases where usage is five times higher than peers to separate efficient “golden patterns” from wasteful “anti-patterns.” That governance model requires per-engineer and per-task attribution instead of session-level aggregates.

Only commit-level provenance via Exceeds Ink lets teams prove whether tactics reduce spend over time. Exceeds Ink captures token cost per agent and model at commit finalization, writes a structured Git Note at refs/notes/exceeds-ink, and correlates that spend with the actual lines shipped. The result is a before-and-after comparison that stays auditable and portable instead of locked inside a vendor’s cloud. The 90th-percentile developer spends approximately $691 per month on AI tokens, and without commit-level attribution leaders cannot tell whether that spend produces proportional output or just churn.

Exceeds AI Repo Leaderboard shows top contributing engineers with trends for AI lift and quality
Exceeds AI Repo Leaderboard shows top contributing engineers with trends for AI lift and quality

Common Mistake: Relying on /usage alone for spend governance. Session-level data cannot map cleanly to specific commits, pull requests, or developers without a provenance layer.

Pro Tip: Install Exceeds Ink on every developer machine as part of onboarding. The Git Note it writes is readable by any Git client and survives outside the Exceeds platform, so it functions as an audit record instead of a dashboard dependency.

Actionable insights to improve AI impact in a team.
Actionable insights to improve AI impact in a team.

See commit-level attribution in action. Book a demo to explore how Exceeds Ink turns token spend into auditable ROI proof.

Step 7: Implement the Daily Cost-Efficient Workflow

A simple daily routine turns these tactics into consistent behavior. Tactics only reduce spend when every engineer applies them on every day. The following seven-step workflow operationalizes Steps 1 through 6 into a single repeatable routine that takes under two minutes per task and keeps optimizations automatic.

  1. Open a new Claude Code session and run /clear before the first task so you start from an empty context.
  2. State the task scope explicitly in the first message because a narrow scope reduces context accumulation.
  3. Select the appropriate model tier, Haiku, Sonnet, or Opus, based on task complexity instead of habit.
  4. Check the status-line token counter after the first tool call. If it already looks high, run /clear and restart with a tighter scope.
  5. Run /usage at the end of each task so you log session cost mentally before switching tasks.
  6. Commit your work so Exceeds Ink can write token cost and attribution data to the Git Note automatically through the post-commit hook.
  7. At the end of the day, review per-commit spend in the Exceeds Ink CLI with exceeds-ink stats and flag any sessions that ran far above baseline.

Troubleshooting: If daily spend does not decline after you implement Steps 1 through 6, run exceeds-ink blame to find outlier commits. Check the interaction mode, such as agent, ask, or plan, recorded in the Git Note because agent-mode sessions without a plan phase often cause runaway token consumption.

Validation and Success Criteria

Measurement confirms whether this program works for your team. The validation standard for Claude Code spend optimization uses a before-and-after comparison of token spend per commit and per developer, based on commit-level data from Exceeds Ink. Establish a two-week baseline before you change anything, then implement all seven steps and compare the following metrics.

Exceeds AI Impact Report shows AI code contributions, productivity lift, and AI code quality
Exceeds AI Impact Report shows AI code contributions, productivity lift, and AI code quality
  • Median tokens per commit should decline by 20 to 40 percent within two sprints.
  • Per-developer monthly spend should sit near the $150 to $250 average monthly Claude Code spend benchmark.
  • Cost per merged pull request should vary significantly, which shows that high spend does not automatically equal high output.

If per-commit spend does not decline, use the Git Note interaction-mode field to see whether engineers default to agent mode on tasks that Sonnet in ask mode could handle at a fraction of the cost.

Advanced Considerations and Next Steps

Once you validate that these tactics reduce spend for individual engineers, the next challenge is scaling them across your entire organization. Team rollout requires more than a checklist. Encode the tiering policy and CLAUDE.md line limit in a shared SKILL.md distributed via Exceeds Ink’s ink-prompting-coach, which installs as a slash command directly into each engineer’s Claude Code agent so guidance appears inside the workflow instead of in a forgotten wiki.

For spend reporting, Exceeds Ink’s per-commit token data feeds into board-ready ROI reports that connect token spend to shipped output such as lines attributed, commits produced, and session-to-merge velocity. Mark Hull, founder of Exceeds AI, developed three workflow tools totaling around 300,000 lines of code at a token cost of approximately $2,000. That $2,000-per-300K-lines benchmark becomes a governance reference point when you tie it to commit history.

Exceeds AI Impact Report with Exceeds Assistant providing custom insights
Exceeds AI Impact Report with PR and commit-level insights

Governance policies that reference per-commit AI authorship become possible because Exceeds Ink’s attestation lives as structured JSON in the repo. Teams can block deploys when AI-generated code exceeds a threshold in sensitive paths or require extra review when agent mode produced more than a set percentage of a diff. When DX appears as an alternative provenance layer, point back to Exceeds Ink’s architecture described earlier, which avoids PATH shimming and global config changes that other tools often require.

Frequently Asked Questions

How do I handle false positives in AI spend attribution when engineers use multiple tools in the same session?

Exceeds Ink uses per-tool checkpoint materializers that resolve edit evidence against the actual working tree at commit finalization. Each line in the commit carries its tool, model, session, and interaction mode. Lines that cannot be confidently attributed are recorded as unknown instead of being silently assigned to AI or human. A session where an engineer used both Claude Code and manual edits therefore produces an accurate split instead of inflated AI attribution that would distort spend-per-commit calculations.

We use Claude Code alongside Cursor and GitHub Copilot. Will spend optimization tactics for Claude Code affect the other tools?

The seven steps in this playbook are Claude Code native and do not change Cursor or Copilot behavior. The governance layer, commit-level attribution via Exceeds Ink, still covers all three tools through dedicated adapters. Your per-developer spend reporting then aggregates Claude Code token costs alongside Cursor billing, read from Cursor’s own state database, and Copilot usage so you see total AI spend in one place instead of three separate dashboards.

How is Exceeds Ink different from metadata-only tools like DX or Jellyfish for spend governance?

Metadata-only tools see pull request cycle times and commit volumes but cannot show which lines are AI-generated, which model produced them, or what those tokens cost. DX’s AI Code Insights captures usage through a closed-source CLI daemon and stores attribution in DX Data Cloud, so nothing lives in your repo. Jellyfish provides financial reporting but no code-level AI provenance. Exceeds Ink writes a portable, machine-readable Git Note alongside every commit that any Git client can read, and it runs without a long-lived daemon or global git config mutation.

Is there a security concern with installing Exceeds Ink on developer machines?

Exceeds Ink runs as a single Rust binary that activates only when a Git hook fires and then exits. It does not run continuously, does not replace the git binary, and does not mutate global git configuration. Remote ingest uses HMAC-SHA256-signed tokens that you can revoke per machine. An LLM-based redaction layer removes prompt content before persistence. An aggregate-only mode keeps transcripts off the wire entirely through a single environment variable. Different teams in the same organization can choose different privacy levels, from local-only to full identified replay, without changing the binary.

How quickly will we see spend reduction after implementing these steps?

Steps 1 through 3, which cover context clearing, CLAUDE.md trimming, and .claudeignore, produce measurable token reductions on the first day because they affect every session. Step 4, which covers model tiering and the MAX_THINKING_TOKENS cap, shows impact within the first sprint as engineers follow the routing policy. Steps 5 through 7, which cover caching, batch API, and the daily workflow, compound over two to four weeks. Commit-level data from Exceeds Ink provides the before-and-after comparison that reveals each step’s contribution instead of attributing all savings to the program as a whole.

Conclusion

Claude Code spend reduction works as a seven-step operational discipline rather than a one-time prompt tweak. Each step cuts token consumption in a measurable way, and the commit-level provenance layer described in Step 6 turns those reductions into board-ready ROI proof.

See how this looks in your own repos. Book a demo with Exceeds AI.

Discover more from Exceeds AI Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading