MediumContext Window Anxiety: Why Developers Are Rethinking How They Build AI Apps | by Kapil Khatik | Medium
Sitemap

Context Window Anxiety: Why Developers Are Rethinking How They Build AI Apps

7 min readMay 30, 2026

--

Press enter or click to view image in full size

You build your first AI-powered app. It feels magical. The model remembers your instructions, follows the thread of the conversation, and gives smart, relevant answers. You ship a demo and everyone loves it.

Then six weeks later, a user reports something weird. The app starts forgetting things mid-session. Responses get inconsistent. Token costs are spiking in ways you can’t explain. And somewhere in your codebase, you discover you’ve been passing 8,000 tokens of conversation history on every single request, whether the model actually needs it or not.

Welcome to context window anxiety.

What Is a Context Window, Actually?

If you’re new to building with LLMs, here’s the quick version. A context window is the amount of text a language model can “see” at once when generating a response. Everything the model knows about your conversation — your instructions, the history of prior messages, the documents you’ve uploaded, tool outputs — all of it has to fit inside this window.

Think of it like working memory for the AI. And just like working memory, it has a hard limit.

Early models had context windows of 2,048 tokens (roughly 1,500 words). Today’s models can handle 128,000 or even 200,000 tokens. That sounds enormous, until you see how fast a real application fills it up.

A detailed system prompt: 500 tokens. A conversation history after 20 back-and-forths: 3,000 tokens. A document you’ve fed in for analysis: 10,000 tokens. Run a few of those in production across real users and you’re bumping against the ceiling faster than you’d expect.

The Real Problem Is Not the Limit Itself

Most of the conversation around context windows focuses on the technical ceiling. “This model supports 128k tokens!” But developers who have shipped real AI products will tell you that the ceiling is almost never the first thing that breaks.

The real problem is the engineering complexity that comes from pretending the limit does not exist.

When developers first build with LLMs, they often start by dumping everything into the context. Full conversation history. Full document. Full system prompt. It works great in testing. It keeps working fine through the first few weeks of production. Then slowly, three things start to hurt.

Memory accumulates in weird ways. When every new message gets appended to the history and sent back with the next request, your app quietly inflates over time. A user who has been chatting for an hour now costs 10x more per request than a brand new user. And the model does not always handle long histories gracefully. It starts over-weighting older messages. It loses track of a decision made 50 turns ago. The experience degrades in subtle ways that are genuinely hard to debug.

State management becomes a nightmare. In most web applications, state lives in a database. You query exactly what you need, when you need it. With LLMs, “state” means what’s in the context window, and that context has to be carefully constructed on every single request. You have to decide in real time: what does the model actually need to know right now? That turns out to be a surprisingly difficult question, and nobody warned you it was part of the job.

Costs compound quietly. With most LLM APIs, you pay per token on both input and output. Once your context balloons, your input token count per request climbs fast. A product that costs $0.002 per request in month one might be costing $0.02 by month three, simply because conversations are getting longer and nobody audited the context packing logic. That is a 10x increase before you have shipped a single new feature.

What Developers Are Actually Doing About It

This is where things get genuinely interesting. The community has been quietly developing a set of practices around context management, and they are starting to look a lot like mature software engineering patterns applied to a new layer of the stack.

Selective summarization. Instead of keeping the full conversation history, some teams summarize older messages at regular intervals. After every 10 turns or so, the oldest messages get collapsed into a short paragraph. The model sees recent exchanges in full and older context as a compact summary. It is imperfect, but it keeps context size predictable without losing important thread.

External memory stores. This is where things get architecturally interesting. Retrieval-Augmented Generation (RAG) was originally designed for document search. But more teams are now using it for episodic memory. Instead of keeping everything in the context window, you store facts, preferences, and prior decisions in a vector database, and retrieve only the most relevant pieces at query time. More complex to build, but it scales far better.

Get Kapil Khatik’s stories in your inbox

Join Medium for free to get updates from this writer.

Structured state objects. Some developers have moved away from raw conversation history entirely. Instead, they maintain a structured JSON object representing the “state of the session,” updated incrementally by the model itself. The model reads from and writes to this object rather than scrolling through a long, unstructured history. It is cleaner, more debuggable, and noticeably more cost-efficient.

Tiered context loading. Think of this like lazy loading for conversations. You have a base layer (system prompt, user preferences, current task), a dynamic layer (recent messages, current tool outputs), and a deep layer (historical facts, stored documents) that only gets pulled in when relevance is detected. The idea is to be surgical about what you include rather than packing everything and hoping for the best.

None of these solutions are perfect. Each has tradeoffs. But the point is that developers are now treating context management as a first-class concern, not an afterthought.

The Cost Question Nobody Is Talking About Loudly Enough

Let’s be direct about money for a second, because this is where a lot of early-stage AI products quietly run into trouble.

A product that seems cost-effective in a demo can become economically shaky in production, not because model pricing changed, but because context management was never treated as a serious engineering problem.

There is a pattern many developers recognize in hindsight: teams spend hours obsessing over their prompts to squeeze out better output quality, while never once looking at their input token counts with the same rigor. They fine-tune the system prompt by 200 words, then later discover they have been sending 15,000 tokens of stale conversation history on every single request. The output quality tuning is visible and satisfying. The context bloat is invisible until it shows up in your billing dashboard.

The mental model that helps: every token in the context window is a computational cost. Treat it the way you would treat database queries. You would not return every row from every table just because you might need it. You would not pull the entire object graph into memory when you only need two fields. That same discipline applies to LLM context.

Why This Matters Beyond Individual Apps

Context window anxiety is not just a developer experience problem. It has real implications for which AI products get built and who gets to build them sustainably.

Right now, the teams that ship reliable, cost-efficient AI apps at scale are the ones that have figured out context management. They have built internal libraries for it. They have developed in-house best practices. They have people on the team who understand this layer of the stack deeply. That is becoming a genuine competitive moat, which means teams treating it as a footnote are falling behind in ways they may not fully recognize yet.

There is also a product design dimension here that often goes unnoticed. How you manage context shapes the user experience in fundamental ways. If your app “forgets” a preference the user stated three sessions ago, that feels frustrating no matter how good your model’s reasoning is on a fresh prompt. If your app is slow to respond because it is loading a massive context on every call, users drop off. The memory architecture is part of the product. It is not just backend plumbing.

What to Watch For

Model providers are competing aggressively on context window size, but the smarter investment might be in the tooling around it. Memory-as-a-service products are starting to emerge. Several inference providers are experimenting with caching layers that let you store and reuse parts of the context window across requests, which changes the cost calculation significantly.

There is also genuine research progress on models that can manage their own long-term memory more intelligently, distinguishing what to retain versus what to discard in something closer to a human-like way. That would change a lot about how AI apps get built. It is not quite there at production quality yet, but it is coming.

The Takeaway

If you are building with LLMs, context management is not a nice-to-have optimization. It is a core engineering challenge that affects reliability, cost, and user experience in ways that compound quietly over time.

The good news is that the patterns are solidifying. Summarization, external memory, tiered context loading, structured state objects — these are not exotic techniques anymore. They are becoming the standard toolkit for anyone building serious AI-powered products.

The developers who will build the best AI apps over the next few years are not just the ones who write the most clever prompts. They are the ones who treat the context window as a first-class engineering concern and design around its constraints deliberately from day one.

Start paying attention to what is in your context window. And more importantly, start asking hard questions about what does not need to be there.

If this resonated, follow for more on the engineering challenges of building real AI products — not just demos.

--

--

Kapil Khatik
Kapil Khatik

Written by Kapil Khatik

AI engineer writing practical deep-dives on LLMs, local AI, and developer tools. I break down what's actually worth your time in the AI space.