Back to Devoured - July 03, 2026
DEVOURED
Improving token efficiency for GitHub Copilot in VS Code

Improving token efficiency for GitHub Copilot in VS Code

DevOps VS Code
The VS Code team improved GitHub Copilot's efficiency by implementing client-side tool search, extended prompt caching, and WebSocket-based transports.
What: By deferring tool loading, caching prompt prefixes for up to 24 hours, and replacing HTTP with WebSockets, they significantly reduced token usage and latency for both OpenAI and Anthropic models.
Why it matters: Usage-based pricing for LLMs is forcing engineering teams to move away from brute-force context stuffing toward smarter, stateful management of prompt windows.
Takeaway: If building your own agentic harness, prioritize separating prompt prefixes from dynamic tool payloads and use persistence layers like WebSockets to maintain cached state across sequential tool-calling turns.
Deep dive
  • Prompt Caching: Uses prompt_cache_retention set to 24h to keep cached model state in GPU-local storage.
  • Tool Search: Replaces loading all tool definitions with an on-demand, embedding-guided search for only relevant tools.
  • WebSockets: Replaces intermittent HTTP requests with a persistent connection, enabling response state caching.
  • Breakpoint Anchoring: Anthropic-specific optimization that places cache markers at stable prompt boundaries.
  • Client-side Search: Moves tool searching from the server to the client using embeddings for intent-based discovery.
Decoder
  • Prompt Prefix: The initial, unchanging portion of a prompt (e.g., system instructions) that can be cached to save costs.
  • Time to First Token (TTFT): The latency between a request and the beginning of the model's response.
  • Tool Search: An optimization where models discover available tools during inference instead of receiving the full catalog upfront.
Original article

Improving token efficiency for GitHub Copilot in VS Code

With the recent move to usage-based billing for GitHub Copilot, every token in an agentic session matters. They affect your credits, latency, and the context window an agent has left to finish the task. Each new model generation tends to consume more tokens per task than the last, as we've witnessed in our own data. This means that harness-level efficiencies are increasingly important to counter this trend. As agents take on longer, more autonomous work, an inefficient harness adds up fast.

Making the GitHub Copilot agentic harness in VS Code more token-efficient is continuous work, and it's the best way to counter this trend. For most changes, we run A/B experiments in production and offline evaluations against task suites, confirming that task success rate holds or improves while token usage drops. It's rarely one big win, usually a steady stream of small ones. Below, we walk through recent gains, first for OpenAI models and then for Anthropic models.

How agentic requests spend tokens

Two costs sit at the heart of every agentic request, and two ideas help us reduce them. Both apply across OpenAI and Anthropic models, even though each provider exposes them differently.

The prompt prefix and caching. In an agentic coding session, a large share of every request repeats across turns: system instructions, tool definitions, repository context, and conversation history. This repeated beginning is the prompt prefix. When requests share the exact same prefix, the inference provider can reuse cached model state instead of recomputing it from scratch on each request. Despite the name, the cached artifact is not a human-readable copy of the prompt. It is the model state computed while processing that prefix, represented internally as key/value tensors. Reusing the prefix cuts both cost (cached tokens can be up to 10 times cheaper) and latency, which is why we work to keep the prompt cache hit-rate high.

Tool-definition overhead. Agents can pull in a large number of tools: those exposed by MCP servers, built-in tools, or extension-provided tools. Each tool is sent to the model with a full definition (a name, a description, and a complete JSON parameter schema), and historically every one was loaded into context on every request. Even when that data is cached, the context window overhead is fixed on each turn and grows as the toolset does.

Tool search. Tool search reduces that overhead by letting the model load tool definitions on demand instead of all at once. Upfront, the model sees only lightweight metadata, the name and description of each deferred tool, and the heavier parameter schemas stay out of context until the model searches for a tool and loads it. Because deferred tools are added at the end of the context window rather than the prefix, the cached prompt prefix stays reusable and the caching gains keep working across turns. The payoff is a leaner context window: the model spends fewer tokens on tools it never uses, leaving more room and budget for the actual task.

Efficiency wins for OpenAI models

For OpenAI models, our recent work focused on reducing usage costs and latency for Copilot users through improved token efficiency. We pursued that through three changes: retaining cached model state for longer, reducing tool-definition overhead, and replacing repeated HTTP requests with persistent WebSocket connections.

Extended prompt caching

OpenAI models cache the prompt prefix automatically: the provider infers the reusable prefix and reuses its model state across requests. That reuse has a direct cost benefit. For most OpenAI models that support cached input pricing, uncached input tokens cost 10 times as much as cached input tokens.

Caching the prefix happens on its own, but how long that cache survives is something we can configure. After careful evaluation, we enabled extended prompt caching for supported models through the prompt_cache_retention body parameter. By default, the cache lives in fast GPU memory, where it is dropped after about 5 to 10 minutes of inactivity (up to an hour in some cases) to make room for other work. Setting "prompt_cache_retention": "24h" moves the cache to slower but roomier GPU-local storage and keeps it for up to 24 hours.

The benefit is simple. With the default cache, a pause of more than a few minutes throws the cache away, so your next request has to reprocess the whole prefix at the full, uncached price. Extended retention keeps the cache warm, so picking up where you left off is still fast and cheap, even after a long break.

Time between requests GPT-5.2 GPT-5.3-Codex GPT-5.4
10-20 min +13% +32% +10%
20-30 min +135% +142% +137%
30-40 min +301% +203% +679%
40-60 min +338% +279% +919%

Tool search

To avoid sending all tool definitions on every request, tool search makes this on-demand. Available to models GPT-5.4 and newer, OpenAI's native tool search implements this deferral with a defer_loading flag.

Upfront, the model only sees lightweight metadata: the name and description of each deferred function or, when deferred functions are grouped into a namespace, only the namespace's name and description.

Metric Model Delta
P50 Total tokens used per turn GPT-5.4 -9.81%
P50 Total tokens used per turn GPT-5.5 -8.61%
P50 Time to first token (TTFT) GPT-5.4 -6.88%
P50 Time to first token (TTFT) GPT-5.5 -7.34%
P50 Time to complete (TTC) GPT-5.4 -5.31%
P50 Time to complete (TTC) GPT-5.5 -5.42%

WebSockets

An agentic coding turn can involve many sequential requests to the inference provider; one for each step the model takes as it calls tools and works toward a solution. Responses API WebSocket mode keeps a persistent connection open and provides a lower-latency continuation path for those sequential requests.

Tracking metric Percentile GPT-5.3-Codex GPT-5.4
Time to first token (TTFT) p50 -19.46% -16.37%
Time to first token (TTFT) p95 -12.92% -15.78%
Time to complete (by turn) p50 -13.55% -11.74%
Time to complete (by turn) p95 -7.86% -6.26%

Efficiency wins for Anthropic models

For Anthropic models, our recent work targeted the same two repeating costs: the prompt prefix we keep warm in cache, and the tool payload we send on every turn. We pursued that through two changes: spending our prompt-cache breakpoints more deliberately, and deferring tool definitions through tool search.

Smarter prompt caching

Anthropic's prompt caching works differently from the automatic prefix caching that OpenAI models use. Rather than the provider inferring the reusable prefix, the caller places explicit cache_control breakpoints, and the API caches everything up to each marker.

  • The end of the tool definitions and the end of the system prompt, the parts that change least between turns.
  • A pair of rolling anchors on the two most recent cacheable messages.

Tool search

Anthropic's tool search tool applies the same deferral idea. Tools are marked with defer_loading: true, and alongside the deferred catalog we keep a small, curated set of core tools loaded.

Metric Percentile / scope Delta
Time to first chunk p50 (by turn) -2.45%
Total prompt tokens p50 (by turn) -11.30%
Total prompt tokens p95 (by turn) -8.85%
Total prompt tokens p50 (by user) -18.32%
Total tokens p50 (by turn) -11.09%
Total tokens p95 (by turn) -8.74%
Total tokens p50 (by user) -18.03%

We moved the search itself client-side, backing it with the same tools-grouping system we built for VS Code's reduced toolset. The model still calls a tool_search tool, but instead of Anthropic matching against the deferred catalog, we run the search locally and return tool_reference blocks for the best matches.

What's next

The work above makes our agentic harness leaner: a higher cache hit rate, fewer tool definitions per request, and less transport overhead. The next step is to move whole classes of work off the main agent entirely. We're building specialized subagents, and exploring custom-trained ones, for narrow tasks like searching the workspace, running commands, and summarizing results. Each runs on the smallest, cheapest model that can do the job, instead of the main model paying for that work in its own context.

Explore all 51 articles in today's digest

Fresh dev news, AI-digested daily. Never miss a trend at devoured.fyi