
Iterative Retrieval
Give subagents the right codebase context over several retrieval passes instead of dumping the whole repo or starving them of files.
Overview
Iterative Retrieval is a journey-wide agent skill that progressively refines codebase context for subagents through a 4-phase dispatch-and-evaluate loop—usable whenever a solo builder needs to fix missing or oversized ag
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill iterative-retrievalWhat is this skill?
- 4-phase iterative loop (dispatch → evaluate → refine) for progressive context
- Targets the subagent context problem: unknown files, patterns, and terminology upfront
- Contrasts failing strategies: send everything, send nothing, or guess context
- Applicable when building multi-agent workflows and RAG-like code exploration pipelines
- Origin ECC pattern for optimizing token usage in orchestration
- 4-phase iterative retrieval loop documented in SKILL.md
Adoption & trust: 5k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Subagents start blind to which files matter, so one-shot context either overflows the window or leaves them unable to complete the task.
Who is it for?
Builders orchestrating multiple agents on large repos who see context limit failures or repeated wrong-file retrieval.
Skip if: Single-turn chats on tiny codebases where a direct file read suffices, or teams that do not use subagent spawning at all.
When should I use this skill?
Spawning subagents that need codebase context they cannot predict upfront, building multi-agent workflows with progressive context, or hitting context-too-large and missing-context failures.
What do I get? / Deliverables
You run a structured retrieval loop that narrows to relevant code and terminology so subagents can work with bounded, sufficient context and lower wasted tokens.
- Bounded context bundle tailored for a subagent task
- Documented retrieval iterations (dispatch/evaluate) before implementation work
Recommended Skills
Journey fit
Useful at every journey phase - explore requirements and options before committing to a direction.
Where it fits
Spawn a subagent to implement a feature module after two retrieval passes surface the right service layer and test fixtures.
Explore unfamiliar areas of a forked repo to estimate scope without loading the entire tree into one prompt.
Give a test-writing subagent incremental context until it finds existing harness patterns instead of guessing paths.
Investigate a production bug by retrieval rounds that narrow from logs to the owning package before patch implementation.
How it compares
Use as an orchestration pattern on top of search tools—not instead of a dedicated code-review or planning skill.
Common Questions / FAQ
Who is iterative-retrieval for?
Solo and indie developers building multi-agent workflows in Claude Code-style setups who need a repeatable way to feed subagents the right slices of a codebase.
When should I use iterative-retrieval?
Use it when spawning subagents that need unpredictable context, when multi-agent pipelines hit missing-context errors, during build agent-tooling work, and again in ship or operate when debugging agent failures or exploring unfamiliar modules.
Is iterative-retrieval safe to install?
It is documentation of a retrieval pattern without bundled binaries; review the Security Audits panel on this page and limit what search or shell tools your agents may call when implementing the loop.
SKILL.md
READMESKILL.md - Iterative Retrieval
# Iterative Retrieval Pattern Solves the "context problem" in multi-agent workflows where subagents don't know what context they need until they start working. ## When to Activate - Spawning subagents that need codebase context they cannot predict upfront - Building multi-agent workflows where context is progressively refined - Encountering "context too large" or "missing context" failures in agent tasks - Designing RAG-like retrieval pipelines for code exploration - Optimizing token usage in agent orchestration ## The Problem Subagents are spawned with limited context. They don't know: - Which files contain relevant code - What patterns exist in the codebase - What terminology the project uses Standard approaches fail: - **Send everything**: Exceeds context limits - **Send nothing**: Agent lacks critical information - **Guess what's needed**: Often wrong ## The Solution: Iterative Retrieval A 4-phase loop that progressively refines context: ``` ┌─────────────────────────────────────────────┐ │ │ │ ┌──────────┐ ┌──────────┐ │ │ │ DISPATCH │─────│ EVALUATE │ │ │ └──────────┘ └──────────┘ │ │ ▲ │ │ │ │ ▼ │ │ ┌──────────┐ ┌──────────┐ │ │ │ LOOP │─────│ REFINE │ │ │ └──────────┘ └──────────┘ │ │ │ │ Max 3 cycles, then proceed │ └─────────────────────────────────────────────┘ ``` ### Phase 1: DISPATCH Initial broad query to gather candidate files: ```javascript // Start with high-level intent const initialQuery = { patterns: ['src/**/*.ts', 'lib/**/*.ts'], keywords: ['authentication', 'user', 'session'], excludes: ['*.test.ts', '*.spec.ts'] }; // Dispatch to retrieval agent const candidates = await retrieveFiles(initialQuery); ``` ### Phase 2: EVALUATE Assess retrieved content for relevance: ```javascript function evaluateRelevance(files, task) { return files.map(file => ({ path: file.path, relevance: scoreRelevance(file.content, task), reason: explainRelevance(file.content, task), missingContext: identifyGaps(file.content, task) })); } ``` Scoring criteria: - **High (0.8-1.0)**: Directly implements target functionality - **Medium (0.5-0.7)**: Contains related patterns or types - **Low (0.2-0.4)**: Tangentially related - **None (0-0.2)**: Not relevant, exclude ### Phase 3: REFINE Update search criteria based on evaluation: ```javascript function refineQuery(evaluation, previousQuery) { return { // Add new patterns discovered in high-relevance files patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)], // Add terminology found in codebase keywords: [...previousQuery.keywords, ...extractKeywords(evaluation)], // Exclude confirmed irrelevant paths excludes: [...previousQuery.excludes, ...evaluation .filter(e => e.relevance < 0.2) .map(e => e.path) ], // Target specific gaps focusAreas: evaluation .flatMap(e => e.missingContext) .filter(unique) }; } ``` ### Phase 4: LOOP Repeat with refined criteria (max 3 cycles): ```javascript async function iterativeRetrieve(task, maxCycles = 3) { let query = createInitialQuery(task); let bestContext = []; for (let cycle = 0; cycle < maxCycles; cycle++) { const candidates = await retrieveFiles(query); const evaluation = evaluateRelevance(candidates, task); // Check if we have sufficient context const highRelevance = evaluation.filter(e => e.relevance >= 0.7); if (highRelevance.length >= 3 && !hasCriticalGaps(evaluation)) { return highRelevance; } // Refine and continue query = refineQuery(e