context-retrieval-loop
Skill6 starsChanged 4 months agoApache-2.0View on GitHub
Use when starting work in an unfamiliar area of a codebase, spawning a subagent that needs targeted file context, a first search pass missed the relevant file, or the file scope of a task is unclear.
- Reads credentials
In this repository116 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- skills/graphify/references/CLAUDE.mdCLAUDE.md
- agent-config-security-auditSkill
- agent-harness-designSkill
- agent-readable-docsSkill
- agent-runtime-patternsSkill
- agent-session-forensicsSkill
- ai-regression-testingSkill
- ai-slop-cleanerSkill
- api-doc-reviewSkill
- architecture-decision-recordsSkill
- architecture-simplificationSkill
- ask-claudeSkill
- ask-codexSkill
- ask-geminiSkill
- autonomous-delivery-pipelineSkill
- baseline-comparison-reviewSkill
- bigquery-cost-auditSkill
- brainstormingSkill
- browser-automation-safetySkill
- bug-huntSkill
- build-fix-minimal-diffSkill
- canonical-advisor-routingSkill
- change-impact-checkSkill
- changelog-generatorSkill
- ci-failure-readoutSkill
- codebase-migration-batchesSkill
- context-compressionSkill
- context-docsSkill
- context-minimizationSkill
- data-qualitySkill
- dataset-split-reviewSkill
- dbt-incremental-strategy-auditSkill
- dbt-preflightSkill
- dbt-strategySkill
- dead-code-removalSkill
- defuddleSkill
- dependency-cleanupSkill
- deploy-pipeline-runbookSkill
- dispatching-parallel-agentsSkill
- doc-consistency-checkSkill
- environment-doctorSkill
- experiment-tracking-reviewSkill
- failure-triageSkill
- filesystem-mcp-guardrailsSkill
- finishing-a-development-branchSkill
- flaky-test-investigationSkill
- gh-address-commentsSkill
- github-ci-failure-triageSkill
- graphifySkill
- handoff-disciplineSkill
- hard-won-skill-extractorSkill
- hook-safety-reviewSkill
- incident-readoutSkill
- incremental-migrationSkill
- json-canvasSkill
- local-rag-mcpSkill
- log-driven-diagnosisSkill
- managed-codebase-contextSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 7 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
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
- Distinctive: line 38
Read the most relevant files from Cycle 1 in full.
- Distinctive: line 67
Stop the loop (whichever comes first):
- Distinctive: line 74
After the loop, report:
- Distinctive: line 85
If context is missing, state it explicitly.
- Distinctive: line 89
When dispatching a subagent, pass only the gathered file list — not the full conversation context:
- Distinctive: line 101
Do not read files speculatively.
- Distinctive: line 102
Do not inline entire file contents into the subagent prompt.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Retrieval Loop
Gather the right codebase context before making changes or spawning subagents. Prevents acting on incomplete information.
When to Use
- Starting work on an unfamiliar area of a codebase
- Spawning a subagent that needs targeted file context
- Failing to find a relevant file on the first search pass
- Unsure which files are in scope for a task
The 3-Cycle Loop
Each cycle builds on the previous. Stop early when you have enough context. Do not exceed 3 cycles.
Cycle 1 — Broad Search
# Find files by keyword
rg "<primary-keyword>" --type ts --type js -l
rg "<primary-keyword>" --glob "*.py" -l
# Find by filename pattern
find . -name "*<keyword>*" -not -path "*/node_modules/*" -not -path "*/.git/*"Collect: file paths, key terms, naming conventions seen.
Stop here if: 3 or more directly relevant files found with no critical gaps.
Cycle 2 — Exact Source and Tests
Read the most relevant files from Cycle 1 in full. Then:
# Find tests for those files
rg "<filename-stem>" --glob "*.test.*" --glob "*.spec.*" -l
rg "import.*<module-name>" -l
# Find call sites
rg "<function-name>|<class-name>" --type ts --type js -lCollect: imports used, function signatures, test patterns, adjacent files referenced.
Stop here if: You can describe the change needed and its blast radius.
Cycle 3 — Docs and Setup
# Check project-specific docs
ls docs/ README.md AGENTS.md CLAUDE.md .claude/ 2>/dev/null
# Check config for feature flags, env vars, or schema
rg "<keyword>" .env.example *.config.* *.toml *.yaml -l 2>/dev/nullCollect: configuration constraints, environment requirements, anything that would block a change.
Stopping Conditions
Stop the loop (whichever comes first):
- You have 3+ high-relevance files and understand the change scope
- Cycle 3 complete
- Each new cycle returns only files already seen
Output
After the loop, report:
Context gathered:
<file-path> — <one-line reason for relevance>
...
Missing context (if any):
<what is still unclear and why it matters>If context is missing, state it explicitly. Do not proceed with guesses when a known gap exists.
Integration with Subagents
When dispatching a subagent, pass only the gathered file list — not the full conversation context:
Relevant files for this task:
src/auth/tokens.ts — contains TokenService used by the bug
src/auth/session.ts — session state management
src/auth/tokens.test.ts — existing test patternsConstraints
- Max 3 cycles. Diminishing returns beyond that.
- Do not read files speculatively. Read only files flagged as relevant.
- Do not inline entire file contents into the subagent prompt; pass paths.
- Report gaps rather than silently proceeding with incomplete context.
Verification
- The loop stopped at a stopping condition — never past 3 cycles
- Every gathered file is listed with a one-line relevance reason
- Missing context is stated explicitly — no proceeding on guesses when a gap is known
- Subagents received the file-path list, not inlined file contents
- No speculative reads — only files flagged as relevant were opened
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
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.

