About this skill
The Iterative Retrieval skill provides a robust pattern to address the 'context problem' frequently encountered in multi-agent workflows. Sub-agents often begin tasks with limited context, leading to inefficiencies or failures because they don't initially know which specific files, code patterns, or project terminologies are relevant. Traditional approaches like sending all context (exceeds limits), sending no context (lacks information), or guessing (often wrong) prove inadequate. This skill introduces a structured, 4-phase loop to progressively refine the context: 1. **DISPATCH**: The agent receives a task or dispatches a sub-task. 2. **EVALUATE**: The agent assesses its current context and identifies gaps or ambiguities relevant to the task. 3. **IDENTIFY**: Based on the evaluation, the agent determines precisely what additional information (e.g., specific files, code snippets, definitions) is needed. 4. **RETRIEVE**: The agent fetches the identified context. This loop allows the agent to acquire only the necessary information, incrementally building a refined and relevant context, thus optimizing token usage and improving task accuracy.
Best use case
An AI agent operating within a large, unfamiliar codebase needs to perform a task (e.g., 'implement feature X', 'debug error Y') but lacks specific contextual information about relevant files, design patterns, or domain-specific terminology to start effectively.
サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン
The Claude sub-agent will successfully identify and retrieve the exact contextual information needed to complete its task accurately and efficiently. This leads to reduced token consumption, fewer errors due to missing context, and improved performance in complex software development or knowledge work.
Practical example
Example input
A Claude sub-agent is instructed with the task: 'Refactor the authentication module to use OAuth 2.0.' It has access to the project repository but no specific files are provided.
Example output
The Claude sub-agent, after applying iterative retrieval, identifies and retrieves the following context: 1. `src/auth/legacy_auth.py`: The existing authentication module. 2. `src/api/routes/user.py`: API endpoints that utilize authentication. 3. `docs/auth_architecture.md`: Project documentation on authentication design. 4. `pyproject.toml`: To understand dependencies and project structure. With this refined context, the agent can now proceed with the refactoring task effectively.
When to use this skill
- Use this skill when a Claude sub-agent: - Is launched with limited initial context but requires deep understanding of a codebase or domain. - Needs to navigate complex, large, or poorly documented code repositories. - Is performing tasks in a multi-agent setup where context sharing is dynamic and incremental. - Must optimize token usage by avoiding sending an entire codebase as context. - Encounters ambiguity or insufficient information to complete a task effectively.
When not to use this skill
- Avoid this skill when: - The required context is already fully and precisely provided to the agent. - The task is simple and operates on a small, well-defined, and fully available context. - Immediate action is required, and the overhead of iterative refinement is not justified. - The agent is operating in an environment where context retrieval is trivial or already highly optimized by other means.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/iterative-retrieval/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How iterative-retrieval Compares
| Feature / Agent | iterative-retrieval | Standard Approach |
|---|---|---|
| Platform Support | Claude | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | easy | N/A |
Frequently Asked Questions
What does this skill do?
サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン
Which AI agents support this skill?
This skill is designed for Claude.
How difficult is it to install?
The installation complexity is rated as easy. You can find the installation instructions above.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# 反復検索パターン
マルチエージェントワークフローにおける「コンテキスト問題」を解決します。サブエージェントは作業を開始するまで、どのコンテキストが必要かわかりません。
## 問題
サブエージェントは限定的なコンテキストで起動されます。以下を知りません:
- どのファイルに関連するコードが含まれているか
- コードベースにどのようなパターンが存在するか
- プロジェクトがどのような用語を使用しているか
標準的なアプローチは失敗します:
- **すべてを送信**: コンテキスト制限を超える
- **何も送信しない**: エージェントに重要な情報が不足
- **必要なものを推測**: しばしば間違い
## 解決策: 反復検索
コンテキストを段階的に洗練する4フェーズのループ:
```
┌─────────────────────────────────────────────┐
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ DISPATCH │─────│ EVALUATE │ │
│ └──────────┘ └──────────┘ │
│ ▲ │ │
│ │ ▼ │
│ ┌──────────┐ ┌──────────┐ │
│ │ LOOP │─────│ REFINE │ │
│ └──────────┘ └──────────┘ │
│ │
│ 最大3サイクル、その後続行 │
└─────────────────────────────────────────────┘
```
### フェーズ1: DISPATCH
候補ファイルを収集する初期の広範なクエリ:
```javascript
// 高レベルの意図から開始
const initialQuery = {
patterns: ['src/**/*.ts', 'lib/**/*.ts'],
keywords: ['authentication', 'user', 'session'],
excludes: ['*.test.ts', '*.spec.ts']
};
// 検索エージェントにディスパッチ
const candidates = await retrieveFiles(initialQuery);
```
### フェーズ2: EVALUATE
取得したコンテンツの関連性を評価:
```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)
}));
}
```
スコアリング基準:
- **高(0.8-1.0)**: ターゲット機能を直接実装
- **中(0.5-0.7)**: 関連するパターンや型を含む
- **低(0.2-0.4)**: 間接的に関連
- **なし(0-0.2)**: 関連なし、除外
### フェーズ3: REFINE
評価に基づいて検索基準を更新:
```javascript
function refineQuery(evaluation, previousQuery) {
return {
// 高関連性ファイルで発見された新しいパターンを追加
patterns: [...previousQuery.patterns, ...extractPatterns(evaluation)],
// コードベースで見つかった用語を追加
keywords: [...previousQuery.keywords, ...extractKeywords(evaluation)],
// 確認された無関係なパスを除外
excludes: [...previousQuery.excludes, ...evaluation
.filter(e => e.relevance < 0.2)
.map(e => e.path)
],
// 特定のギャップをターゲット
focusAreas: evaluation
.flatMap(e => e.missingContext)
.filter(unique)
};
}
```
### フェーズ4: LOOP
洗練された基準で繰り返す(最大3サイクル):
```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);
// 十分なコンテキストがあるか確認
const highRelevance = evaluation.filter(e => e.relevance >= 0.7);
if (highRelevance.length >= 3 && !hasCriticalGaps(evaluation)) {
return highRelevance;
}
// 洗練して続行
query = refineQuery(evaluation, query);
bestContext = mergeContext(bestContext, highRelevance);
}
return bestContext;
}
```
## 実践例
### 例1: バグ修正コンテキスト
```
タスク: "認証トークン期限切れバグを修正"
サイクル1:
DISPATCH: src/**で"token"、"auth"、"expiry"を検索
EVALUATE: auth.ts(0.9)、tokens.ts(0.8)、user.ts(0.3)を発見
REFINE: "refresh"、"jwt"キーワードを追加; user.tsを除外
サイクル2:
DISPATCH: 洗練された用語で検索
EVALUATE: session-manager.ts(0.95)、jwt-utils.ts(0.85)を発見
REFINE: 十分なコンテキスト(2つの高関連性ファイル)
結果: auth.ts、tokens.ts、session-manager.ts、jwt-utils.ts
```
### 例2: 機能実装
```
タスク: "APIエンドポイントにレート制限を追加"
サイクル1:
DISPATCH: routes/**で"rate"、"limit"、"api"を検索
EVALUATE: マッチなし - コードベースは"throttle"用語を使用
REFINE: "throttle"、"middleware"キーワードを追加
サイクル2:
DISPATCH: 洗練された用語で検索
EVALUATE: throttle.ts(0.9)、middleware/index.ts(0.7)を発見
REFINE: ルーターパターンが必要
サイクル3:
DISPATCH: "router"、"express"パターンを検索
EVALUATE: router-setup.ts(0.8)を発見
REFINE: 十分なコンテキスト
結果: throttle.ts、middleware/index.ts、router-setup.ts
```
## エージェントとの統合
エージェントプロンプトで使用:
```markdown
このタスクのコンテキストを取得する際:
1. 広範なキーワード検索から開始
2. 各ファイルの関連性を評価(0-1スケール)
3. まだ不足しているコンテキストを特定
4. 検索基準を洗練して繰り返す(最大3サイクル)
5. 関連性が0.7以上のファイルを返す
```
## ベストプラクティス
1. **広く開始し、段階的に絞る** - 初期クエリで過度に指定しない
2. **コードベースの用語を学ぶ** - 最初のサイクルでしばしば命名規則が明らかになる
3. **不足しているものを追跡** - 明示的なギャップ識別が洗練を促進
4. **「十分に良い」で停止** - 3つの高関連性ファイルは10個の平凡なファイルより優れている
5. **確信を持って除外** - 低関連性ファイルは関連性を持つようにならない
## 関連項目
- [The Longform Guide](https://x.com/affaanmustafa/status/2014040193557471352) - サブエージェントオーケストレーションセクション
- `continuous-learning`スキル - 時間とともに改善するパターン用
- `~/.claude/agents/`内のエージェント定義Related Skills
workspace-surface-audit
Audit the active repo, MCP servers, plugins, connectors, env surfaces, and harness setup, then recommend the highest-value ECC-native skills, hooks, agents, and operator workflows. Use when the user wants help setting up Claude Code or understanding what capabilities are actually available in their environment.
safety-guard
Use this skill to prevent destructive operations when working on production systems or running agents autonomously.
repo-scan
Cross-stack source code asset audit — classifies every file, detects embedded third-party libraries, and delivers actionable four-level verdicts per module with interactive HTML reports.
project-flow-ops
Operate execution flow across GitHub and Linear by triaging issues and pull requests, linking active work, and keeping GitHub public-facing while Linear remains the internal execution layer. Use when the user wants backlog control, PR triage, or GitHub-to-Linear coordination.
manim-video
Build reusable Manim explainers for technical concepts, graphs, system diagrams, and product walkthroughs, then hand off to the wider ECC video stack if needed. Use when the user wants a clean animated explainer rather than a generic talking-head script.
laravel-plugin-discovery
Discover and evaluate Laravel packages via LaraPlugins.io MCP. Use when the user wants to find plugins, check package health, or assess Laravel/PHP compatibility.
design-system
Use this skill to generate or audit design systems, check visual consistency, and review PRs that touch styling.
click-path-audit
Trace every user-facing button/touchpoint through its full state change sequence to find bugs where functions individually work but cancel each other out, produce wrong final state, or leave the UI in an inconsistent state. Use when: systematic debugging found no bugs but users report broken buttons, or after any major refactor touching shared state stores.
ck
Persistent per-project memory for Claude Code. Auto-loads project context on session start, tracks sessions with git activity, and writes to native memory. Commands run deterministic Node.js scripts — behavior is consistent across model versions.
canary-watch
Use this skill to monitor a deployed URL for regressions after deploys, merges, or dependency upgrades.
benchmark
Use this skill to measure performance baselines, detect regressions before/after PRs, and compare stack alternatives.
swiftui-patterns
SwiftUI 架构模式,使用 @Observable 进行状态管理,视图组合,导航,性能优化,以及现代 iOS/macOS UI 最佳实践。