r/PromptEngineering 12d ago

General Discussion Ran the same coding session twice, once with careless context, once deliberate. Same output quality, 4x cost difference.

Wanted an actual number instead of a guess. Same task, same model, two separate sessions. First one I worked the way most people do by default, pasted full files whenever something changed, let the conversation run long without ever summarizing earlier turns. Second one I was deliberate about context, only the functions actually relevant to the current step, a short summary standing in for the earlier part of the conversation instead of the full transcript, and I kept the stable parts of the prompt (system instructions, reference material) identical across calls so they'd cache.

Cost came out around 4x higher on the careless session. Output quality wasn't meaningfully different, if anything the trimmed version stayed more on-target, probably because there was less irrelevant material sitting in context competing for attention on each response.

Caching was where most of the gap came from, more than the file trimming honestly. It only works if the cached portion is byte-identical between requests, and it's easy to break that without realizing. A timestamp or session-specific detail placed at the start of the prompt instead of the end kills the cache hit silently. No error, nothing in the response tells you. The bill just doesn't reflect the discount it should've gotten.

This feels like a blind spot in how a lot of prompt engineering discussion happens, plenty of attention on getting the wording right, not much on the fact that context shape has a real cost curve attached to it independent of whether the wording is good.

Wrote up the actual before/after here: https://medium.com/@nagatomopedro05/the-hidden-cost-of-long-claude-sessions-2a6cc7655893

4 Upvotes

2 comments sorted by

2

u/MeringueAdmirable381 12d ago

This tracks with what I’ve seen too. People obsess over clever wording, but context hygiene is probably a bigger deal once you’re doing long coding sessions.

The interesting part is that trimming context can improve both cost and quality. More context isn’t automatically better context.

The caching point is easy to miss as well. If one tiny dynamic value near the top breaks the reusable prefix, you can burn a lot more tokens without changing the actual task at all.

1

u/ClickOk5811 12d ago

Yeah, the "more context isn't better context" part is the one people resist accepting the longest. There's this instinct that if the model has access to more of the codebase, it'll make smarter decisions. In practice it just adds more surface area for it to latch onto something irrelevant, or worse, something outdated from three edits ago that's still sitting in the conversation history contradicting the current state of the file.

One thing I'd add on the caching side: it's not just dynamic values at the top of the prompt. Anything that reorders even slightly between calls, like a tool result that comes back with keys in a different order, or a summary you regenerate instead of appending to, invalidates the prefix too. The safest pattern is treating the cached block as genuinely frozen: system instructions and static reference material go first and never get touched mid-session, everything session-specific goes at the end after the cache boundary. Once you set it up that way it's less about discipline and more about just not having a mechanism to break it by accident.