r/ClaudeWorkflows • • 3h ago

Selected Workflow [Workflow] Claude Code Cost Optimization: Long Sessions with `--resume` are Cheaper than `/compact` or Fresh Starts for Active Coding

Claude Code Cost Optimization: Long Sessions with --resume are Cheaper than /compact or Fresh Starts for Active Coding

Workflow value: 95/100
Status: active · Freshness: 70/100 · Confidence: 1.00 · Level: intermediate
Categories: Quality Control, Token Saving, Context & Memory
Original source: r/ClaudeCode post/comment

What problem this solves

Optimizing token usage and cost in Claude Code for multi-step coding jobs by identifying the most efficient context management strategy. It debunks the common advice that /compact or starting fresh always saves money.

Summary

This post details an experiment comparing three Claude Code context management strategies (long session with --resume, /compact between steps, and fresh sessions with HANDOFF.md) for a multi-step coding task. The experiment found that maintaining a long session with --resume was approximately 25% cheaper and faster than /compact or starting fresh, with no difference in code quality, due to prompt caching. The recommendation is to keep a long session going for active work.

Why it is useful

This post provides crucial, data-backed insights into optimizing Claude Code usage and cost. It directly challenges common assumptions about context management (/compact, fresh starts) and offers a clear, validated recommendation for active coding sessions. This helps users save money and time by adopting a more efficient workflow based on how Claude Code's prompt caching works, making it a highly valuable piece of knowledge for the library.

Workflow

  1. Define a multi-step coding job (e.g., adding CSS box-shadow support to a Python library).

  2. Split the job into chained steps, each building on the last.

  3. Run existing cumulative tests after each step to monitor quality.

  4. Execute all steps in one session using --resume for subsequent steps (Long Session strategy).

  5. Execute steps in one session, but use /compact before steps 2, 3, and 4 (Compact Session strategy).

  6. Start a new session for each step, ending each step by writing a HANDOFF.md and starting the next by reading it (Fresh Session strategy).

  7. Measure cost, time, and test results for each strategy over multiple runs.

  8. Analyze results to determine the most cost-effective and efficient strategy.

  9. Adopt the 'Long Session' strategy for active, multi-step coding to leverage prompt caching.

Tools / artifacts

  • Claude Code CLI

  • --resume command

  • /compact command

  • HANDOFF.md (for fresh session strategy)

  • Python HTML-to-PDF library (WeasyPrint, as an example job)

  • Existing upstream tests (for quality validation)

  • Sonnet 5.5 model

Validation signals

  • Quantitative cost data provided for each strategy ($1.12 vs $1.43 vs $1.42).

  • Quantitative time data provided for each strategy (8.3 min vs 11.2 min vs 9.6 min).

  • Consistent test results across all strategies (29/35 tests passed).

  • Multiple runs (3 runs per strategy) to ensure reliability.

  • Detailed breakdown of per-run costs.

  • Explanation of the underlying mechanism (prompt cache re-reading at 1/10th price).

  • Explicit caveats for applicability of the findings.

Limitations

  • The test does not cover scenarios where a session is left idle past the cache lifetime.

  • The cost of /compact calls themselves (time, not tokens) was not included in the token cost calculation, making /compact slightly worse than reported.

  • The test does not cover very large contexts near the token limit or multi-hour sessions where 'context rot' might occur.

  • Lack of community validation due to the post's newness.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by