---
title: "Just-in-time context retrieval pattern for AI agents | Agentic Pattern Language"
description: "Keep file paths, queries and links in context; load the data with tools only when it is needed. Sourced from Anthropic and Cursor."
url: https://agenticpatternlanguage.com/patterns/just-in-time-context-retrieval/
---

16 [One agent](https://agenticpatternlanguage.com/#one-agent)

# Just-in-time context retrieval

Keep file paths, queries and links in context; load the data with tools only when it is needed.

Also called Dynamic context discovery, Progressive disclosure

Anthropic, Cursor

[How to read this](https://agenticpatternlanguage.com/notation/)

## Part of

* [Agent loop](https://agenticpatternlanguage.com/patterns/agent-loop/)

## Builds on

* [Skills](https://agenticpatternlanguage.com/patterns/skills/)
* [Tool search](https://agenticpatternlanguage.com/patterns/tool-search/)

## Alternatives

* [Retrieval-augmented generation](https://agenticpatternlanguage.com/patterns/retrieval-augmented-generation/)

## The problem

Loading everything up front fills the context window, and a model recalls less as the window fills.

> Some MCP servers include many tools, often with long descriptions, which can significantly bloat the context window.

Cursor [Dynamic context discovery](https://cursor.com/blog/dynamic-context-discovery) Jan 6, 2026

> Studies on needle-in-a-haystack style benchmarking have uncovered the concept of context rot: as the number of tokens in the context window increases, the model’s ability to accurately recall information from that context decreases.

Anthropic [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) Sep 29, 2025

## Therefore

> Rather than pre-processing all relevant data up front, agents built with the “just in time” approach maintain lightweight identifiers (file paths, stored queries, web links, etc.) and use these references to dynamically load data into context at runtime using tools.

Anthropic [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) Sep 29, 2025

> As models have become better as agents, we've found success by providing fewer details up front, making it easier for the agent to pull relevant context on its own.

Cursor [Dynamic context discovery](https://cursor.com/blog/dynamic-context-discovery) Jan 6, 2026

## In use

Claude Code

> Anthropic’s agentic coding solution Claude Code uses this approach to perform complex data analysis over large databases.

Anthropic [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) Sep 29, 2025

Cursor

> In Cursor, we support dynamic context discovery for MCP by syncing tool descriptions to a folder.

Cursor [Dynamic context discovery](https://cursor.com/blog/dynamic-context-discovery) Jan 6, 2026

## Where it breaks

Exploring at run time is slower than reading prepared data, and an agent without guidance wastes context.

> runtime exploration is slower than retrieving pre-computed data.…Without proper guidance, an agent can waste context by misusing tools, chasing dead-ends, or failing to identify key information.

Anthropic [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) Sep 29, 2025

## Sources

1. [Effective context engineering for AI agents](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents) Prithvi Rajasekaran, Ethan Dixon, Carly Ryan, and Jeremy Hadfield, Anthropic, Sep 29, 2025
   > Letting agents navigate and retrieve data autonomously also enables progressive disclosure—in other words, allows agents to incrementally discover relevant context through exploration.
2. [Dynamic context discovery](https://cursor.com/blog/dynamic-context-discovery) Jediah Katz, Cursor, Jan 6, 2026
   > We're calling this pattern dynamic context discovery, in contrast to static context which is always included.

Added Nov 14, 2026
