agentleFS
peopleforresterpeopleforrester/claude-dotfiles/skills/optimization/iterative-retrieval/SKILL.md

iterative-retrieval

Skill3 starsChanged 8 months agoMITView on GitHub

Progressive context refinement pattern for subagents. Solves the problem of agents not knowing what context they need until they start working. Uses a 4-phase loop: DISPATCH, EVALUATE, REFINE, LOOP.

28 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use configure-ecc, carrier-relationship-management and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • saxon-ySkill

    configure-ecc

    Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.

    Also in 10 projects that use this

  • InfopibeSkill

    carrier-relationship-management

    Codified expertise for managing carrier portfolios, negotiating freight rates, tracking carrier performance, allocating freight, and maintaining strategic carrier relationships. Informed by transportation managers with 15+ years experience. Includes scorecarding frameworks, RFP processes, market intelligence, and compliance vetting. Use when managing carriers, negotiating rates, evaluating carrier performance, or building freight strategies.

    Also in 8 projects that use this

  • InfopibeSkill

    ralphinho-rfc-pipeline

    RFC-driven multi-agent DAG execution pattern with quality gates, merge queues, and work unit orchestration.

    Also in 8 projects that use this

  • +5 more from Infopibe

The file

We split this skill into the rules it gives an agent

3 rules. 1 is common, 2 are distinctive, and 0 are very specific to this project.

  • 1

    Common

    Most of the 25 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 0

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When delegating to subagents, you face a dilemma:

    line 22
  2. Common:

    Update search criteria based on evaluation:

    line 57
  3. Distinctive:

    No critical gaps identified

    line 71

“Common” is measured: kept by at least 6 in 10 of the 25 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Iterative Retrieval Pattern

Solve the subagent context problem: agents don't know what they need until they start looking.

The Problem

When delegating to subagents, you face a dilemma:

  • Send everything: Context overflow, wasted tokens, confused agent
  • Send nothing: Agent lacks context, produces poor results
  • Guess what's needed: Often wrong, misses critical files

The Solution: 4-Phase Iterative Loop

Phase 1: DISPATCH

Send a broad initial query to gather candidate context:

Search for files related to: [topic]
Keywords: [initial keywords]
File patterns: [likely patterns]
Return: File paths with relevance scores

Phase 2: EVALUATE

Score each result for relevance (0.0 to 1.0):

| File | Relevance | Reason |
|------|-----------|--------|
| src/auth/login.ts | 0.9 | Core auth logic |
| src/utils/hash.ts | 0.7 | Used by auth |
| src/config.ts | 0.3 | Has auth config section |
| src/routes.ts | 0.2 | Only references auth path |

Identify gaps:

  • What terminology does this codebase use? (update search terms)
  • What patterns are referenced but not found?
  • What dependencies need exploration?

Phase 3: REFINE

Update search criteria based on evaluation:

Updated keywords: [refined keywords from codebase terminology]
New file patterns: [patterns discovered during evaluation]
Specific files to read: [high-relevance files]
Gaps to fill: [what's still missing]

Phase 4: LOOP

Repeat phases 1-3 with refined criteria.

Stopping Criteria:

  • 3+ files with relevance >= 0.7
  • No critical gaps identified
  • OR max 3 iterations reached (proceed with best available)

Example: Finding Auth Implementation

Iteration 1:

  • DISPATCH: Search for "auth", "login", "session"
  • EVALUATE: Found middleware but not the auth service
  • REFINE: Codebase uses "identity" not "auth"

Iteration 2:

  • DISPATCH: Search for "identity", "credential", "token"
  • EVALUATE: Found IdentityService, TokenManager, SessionStore
  • Result: 5 files with relevance >= 0.8 — stop and proceed

Implementation Pattern

async function iterativeRetrieve(topic: string, maxIterations = 3) {
  let keywords = extractKeywords(topic);
  let context: FileContext[] = [];

  for (let i = 0; i < maxIterations; i++) {
    // DISPATCH
    const candidates = await searchCodebase(keywords);

    // EVALUATE
    const scored = await scoreRelevance(candidates, topic);
    context = mergeContext(context, scored.filter(s => s.relevance >= 0.5));

    // Check stopping criteria
    const highRelevance = context.filter(c => c.relevance >= 0.7);
    if (highRelevance.length >= 3) break;

    // REFINE
    keywords = refineKeywords(keywords, scored);
  }

  return context;
}

When to Use

  • Delegating research to a subagent
  • Exploring unfamiliar codebases
  • Gathering context for code review
  • Building context for architectural analysis

When NOT to Use

  • You already know exactly what files are needed
  • The task is in a single file
  • The codebase is small enough to read entirely

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.