<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq" -->

---
title: Prompt caching, compression, and compaction in coding agents
description: Coding agents use three distinct optimizations that are easy to confuse: prompt caching, transport compression, and compaction. Prompt caching reuses saved...
canonical: https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Prompt caching, compression, and compaction in coding agents | daily.dev
og:description: Coding agents use three distinct optimizations that are easy to confuse: prompt caching, transport compression, and compaction. Prompt caching reuses saved...
og:url: https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq
og:image: https://api.daily.dev/og/posts/Ix1RrAflq.png
og:image:alt: Prompt caching, compression, and compaction in coding agents
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Prompt caching, compression, and compaction in coding agents

**[Flavio Copes](https://daily.dev/sources/flaviocopes)** · 5 min read · 0 upvotes · 0 comments

## Summary

Coding agents use three distinct optimizations that are easy to confuse: prompt caching, transport compression, and compaction. Prompt caching reuses saved model state for a matching prefix, but still generates a new response each time. Transport compression shrinks bytes on the wire without changing token counts the model processes. Compaction shortens conversation history to cut input tokens, but can reduce cache reuse and lose useful context. Anthropic's cache defaults to a 5-minute lifetime with a 1-hour option, and Claude Code's /usage shows cache hits, misses, and rebuilds. OpenAI notes cached tokens still count toward API rate limits.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://flaviocopes.com/agent-prompt-caching>

## Questions this post answers

### What is the default cache lifetime for Anthropic's Claude prompt caching?

The default cache lifetime is five minutes, with an optional one-hour setting available. A cache read refreshes the lifetime, so actively reused prefixes can stay cached longer. These are API controls with their own requirements and pricing documented by Anthropic for prompt caching.

_Anyone tuning Claude API costs can track caching behavior and changes on daily.dev._

### Does compaction in a coding agent reduce prompt cache hit rates?

Yes, compaction can change the prefix and reduce cache reuse immediately afterward because it replaces earlier conversation history with a shorter summary. OpenAI's cache guide describes this trade-off explicitly. Despite a lower hit rate, fewer total input tokens can still cost less overall, so total input cost should be compared rather than hit rate alone.

_Developers debugging agent cost spikes can follow caching and compaction tradeoffs on daily.dev._

### Does gzip compressing an API request reduce the number of tokens an LLM processes?

No, transport compression only reduces the bytes sent over the network; it expands back to the same JSON and the same token count at the destination. It does not establish a prompt-cache hit and the compressed byte size does not indicate how many input tokens the model actually processes.

_Engineers investigating LLM API usage spikes can track these cost nuances on daily.dev._

## Similar posts on daily.dev

- [Prompt Caching Explained](https://daily.dev/posts/prompt-caching-explained-mhomvre8o) · DigitalOcean Community · 2 upvotes · 0 comments
- [Prompt Caching for Anthropic and OpenAI Models: Building Cost-Efficient AI Systems](https://daily.dev/posts/prompt-caching-for-anthropic-and-openai-models-building-cost-efficient-ai-systems-mjzh92xkq) · DigitalOcean · 2 upvotes · 0 comments
- [Prompt Caching Techniques](https://daily.dev/posts/prompt-caching-techniques-rlnexmcrg) · PromptLayer Blog · 1 upvotes · 0 comments
- [Prompt Caching in LLMs\!](https://daily.dev/posts/prompt-caching-in-llms--yunvudzrh) · Daily Dose of Data Science \| Avi Chawla \| Substack · 1 upvotes · 0 comments

---

Tags: [#ai-agents](https://daily.dev/tags/ai-agents), [#openai](https://daily.dev/tags/openai), [#claude-code](https://daily.dev/tags/claude-code), [#ai-inference](https://daily.dev/tags/ai-inference)

[View this post on daily.dev](https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Prompt caching, compression, and compaction in coding agents","url":"https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq"},"datePublished":"2026-10-26T08:08:59.601Z","dateModified":"2026-10-26T08:14:16.514Z","description":"Coding agents use three distinct optimizations that are easy to confuse: prompt caching, transport compression, and compaction. Prompt caching reuses saved...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cd9cfb1debc24900acce799ca9ac9736?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/cd9cfb1debc24900acce799ca9ac9736?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Flavio Copes","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Flavio Copes","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/1f2dbd275797411bbd37bfdaaf0951a9","url":"https://daily.dev/sources/flaviocopes"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"ai-agents,openai,claude-code,ai-inference","timeRequired":"PT5M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Flavio Copes","item":"https://daily.dev/sources/flaviocopes"},{"@type":"ListItem","position":3,"name":"Prompt caching, compression, and compaction in coding agents"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/prompt-caching-compression-and-compaction-in-coding-agents-ix1rraflq#faq","mainEntity":[{"@type":"Question","name":"What is the default cache lifetime for Anthropic's Claude prompt caching?","acceptedAnswer":{"@type":"Answer","text":"The default cache lifetime is five minutes, with an optional one-hour setting available. A cache read refreshes the lifetime, so actively reused prefixes can stay cached longer. These are API controls with their own requirements and pricing documented by Anthropic for prompt caching. Anyone tuning Claude API costs can track caching behavior and changes on daily.dev."}},{"@type":"Question","name":"Does compaction in a coding agent reduce prompt cache hit rates?","acceptedAnswer":{"@type":"Answer","text":"Yes, compaction can change the prefix and reduce cache reuse immediately afterward because it replaces earlier conversation history with a shorter summary. OpenAI's cache guide describes this trade-off explicitly. Despite a lower hit rate, fewer total input tokens can still cost less overall, so total input cost should be compared rather than hit rate alone. Developers debugging agent cost spikes can follow caching and compaction tradeoffs on daily.dev."}},{"@type":"Question","name":"Does gzip compressing an API request reduce the number of tokens an LLM processes?","acceptedAnswer":{"@type":"Answer","text":"No, transport compression only reduces the bytes sent over the network; it expands back to the same JSON and the same token count at the destination. It does not establish a prompt-cache hit and the compressed byte size does not indicate how many input tokens the model actually processes. Engineers investigating LLM API usage spikes can track these cost nuances on daily.dev."}}]}
```

