The Symptom: Claude Code Forgot Recent Instructions

As developers stack skills and plugins onto AI assistants like Claude Code, a common problem emerges: sessions become sluggish, and the AI starts to lose track of the immediate conversation. This isn't a sign of the model having an 'off day.' Instead, it's a direct consequence of context injection bloat. The author experienced this firsthand, observing that Claude Code would ignore recent commands, cross-wiring them with much earlier topics. Sessions took longer to initiate, and the AI's short-term memory appeared compromised.

The root cause was identified as the massive context injected at session start. This initial data payload had grown so large that newer, more critical instructions were effectively being drowned out, pushed out of the model's limited attention window. Think of it like trying to give directions to someone who's holding a massive encyclopedia; the important, up-to-the-minute street names get lost amidst the pages of historical facts.

Auditing the Context Injection Payload

To address this, a systematic audit was performed. The initial step involved measuring the size of the context injection payload. This payload comprises all the information provided to the AI at the beginning of a session, including skills, plugins, and initial instructions. The goal was to pinpoint what was contributing the most to the bloat and how it could be reduced.

The audit revealed that while skills and plugins were necessary, their cumulative size was a significant factor. More critically, the way this information was structured and presented to Claude Code was inefficient. Large chunks of text, potentially repetitive or non-essential for immediate task completion, were being included. This inefficient packaging meant that more vital user instructions were being prematurely evicted from the model's context window.

The measurement process itself highlighted the scale of the problem. The context injection payload had ballooned to an astonishing 228KB. This is a substantial amount of data to process for every single interaction, especially when the model's context window, while large, is not infinite. For Claude Code to effectively execute new commands, the most recent and relevant information needs to remain accessible. A 228KB injection payload made this increasingly difficult.

Visual representation of context injection size before and after optimization.

Strategies for Context Reduction

Several strategies were employed to tackle the context bloat. The primary focus was on reducing the size of the initial context injection without sacrificing essential functionality or Claude Code's ability to access necessary skills and information.

One key technique involved pruning unnecessary data. This meant carefully reviewing the content of the context injection and removing any information that was redundant, outdated, or not immediately relevant to the core functions. For instance, if a skill had a verbose introductory description that wasn't critical for its operation, it could be shortened or removed.

Another critical step was optimizing the structure of the injected context. Instead of dumping large blocks of text, the information was refactored. This could involve using more concise language, employing structured data formats where appropriate, or ensuring that only the most critical parameters and definitions were included by default. For example, instead of injecting the full documentation for a plugin, only the essential API endpoints and their required arguments might be included. This is akin to packing a suitcase for a trip: you bring what you need, not your entire wardrobe.

The author also explored dynamic loading of certain information. Instead of injecting everything upfront, some data or skill descriptions could potentially be loaded on demand when a specific function was invoked. This requires a more sophisticated management system but can drastically reduce the initial load time and context size.

The Impact: From 228KB to 48KB

The results of this audit and optimization process were dramatic. The context injection payload was successfully reduced from 228KB down to a lean 48KB. This represents an 79% reduction in the initial data load. The implications for Claude Code's performance are significant.

With a drastically smaller context injection, Claude Code can process new instructions much faster. The likelihood of ignoring recent commands is significantly reduced because the most relevant information is more likely to remain within the model's active context window. Sessions start quicker, and the AI responds more promptly and accurately to user input.

This optimization not only improves the user experience through faster response times and more reliable instruction following but also potentially reduces computational costs associated with processing larger context windows. It demonstrates that careful auditing and optimization of context injection are crucial for maintaining the performance and usability of complex AI assistants as they grow in functionality.

What Lies Ahead?

While this optimization has yielded significant improvements, it raises further questions. As more complex skills and plugins are developed, maintaining this lean context injection will require ongoing vigilance. What are the best practices for dynamically managing context in evolving AI assistant architectures? How can developers proactively design skills and plugins with context efficiency in mind from the outset, rather than treating it as an optimization problem after the fact?