/agent-toolkit:iterative-retrievalfrom agent-toolkit
Pattern for progressively refining context retrieval to solve the subagent context problem
Ships in agent-toolkit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Check authority before capability. Default STANDARD + SOLO; preserve explicit accepted task profile/topology and current exclusions. Planning or selecting roles does not authorize a worker. HANDOFF, PARALLEL and REVIEW require explicit user authorization before changing actors. Never launch another CLI, worker or orchestrator to bypass a restriction. Check actual exposed tools/schemas only after authority; availability alone grants no action.
If requested capability is missing, disclose it and use SOLO/manual execution only when consistent with user intent. Do not relabel local role passes as independent review or fabricate tool/background success. Reuse existing specific authority within scope; no repeated permission menu. Keep the configured model unless a change is authorized. Mandatory project gates and worktree-first always apply. Consult the existing development-lifecycle-rules contract when installed; this plugin's safe local path requires no other plugin or copied skill catalog.
A bounded context-search technique for local SOLO analysis or explicitly authorized workers. Search/evaluate/refine steps are not another lifecycle or authority to spawn a retrieval agent. Code below is pseudocode, not exposed tools.
Subagents are spawned with limited context. They don't know:
Standard approaches fail:
A bounded search loop that progressively refines context. At the limit, report unresolved gaps; critical missing context blocks dependent implementation rather than granting permission to guess. Local search does not need another actor:
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ SEARCH │─────│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ Max 3 cycles, then proceed │
└─────────────────────────────────────────────┘
Initial broad query to gather candidate files:
// Start with high-level intent
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// Local search or an explicitly authorized retrieval operation
const candidates = await retrieveFiles(initialQuery);
Assess retrieved content for relevance:
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:
Update search criteria based on evaluation:
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)
};
}
Repeat with refined criteria (max 3 cycles):
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 {files: highRelevance, complete: true};
}
// Refine and continue
query = refineQuery(evaluation, query);
bestContext = mergeContext(bestContext, highRelevance);
}
return {files: bestContext, complete: false};
}
Apply this brief locally by default or give it to an already authorized worker:
When retrieving context for this task:
1. Start with broad keyword search
2. Evaluate each file's relevance (0-1 scale)
3. Identify what context is still missing
4. Refine search criteria and repeat (max 3 cycles)
5. Return files with relevance >= 0.7
Stop retrieval when relevant sources resolve the task or the bounded search limit is reached. Report unresolved critical context before dependent changes; worked examples are not required to execute the search/evaluate/refine loop.
| Task branch | Reference |
|---|---|
| A worked bug-fix or feature retrieval example | A worked bug-fix or feature retrieval example |
Read only the branch that applies; expand when the task crosses topics.
What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub mmalyska/claude-plugins --plugin agent-toolkit14 skills in this plugin
/autonomous-agent-harnessDesign or configure bounded recurring agent workflows with persistence, scheduling, and recovery in Claude Code or Codex./blueprintCreate profile-sized, resumable implementation plans with exact file scopes, dependencies, checks and rollback. Planning does not authorize workers or delivery./context-budgetAudit instruction and tool context overhead in Claude Code or Codex, distinguishing measured usage from estimates.Other plugins' skills for the same job