iterative-retrieval

A method for finding the right project files by starting with a broad search, checking the results, narrowing the search, and repeating as needed.

In plain words
What is it for?
Use it when assigning work to other agents, locating code for a feature, or refining searches for terms, patterns, and related files.
Why use it?
It helps agents work with enough relevant code without sending an entire repository or guessing which files matter.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/codelably/harmony-claude-code/iterative-retrieval
Any agent
npx skills add codelably/harmony-claude-code --skill iterative-retrieval
Clone the repo
git clone --depth 1 https://github.com/codelably/harmony-claude-code

Made for: Claude Code, Codex.

Per session 19 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,736 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00019 $0.01736
Opus 5 $0.00010 $0.00868
Sonnet 5 $0.00004 $0.00347
Haiku 4.5 $0.00002 $0.00174

Measured 2d ago against content hash 5e94e4373e16, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

iterative-retrieval scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

docs/zh-TW/skills/iterative-retrieval/SKILL.md · 203 lines

How it starts

The opening of the file, as written. The whole thing — 203 lines — stays where its author put it; the contents beside it link to each section on GitHub.

迭代檢索模式

解決多 agent 工作流程中的「上下文問題」,其中子 agents 在開始工作之前不知道需要什麼上下文。

問題

子 agents 以有限上下文產生。它們不知道:

  • 哪些檔案包含相關程式碼
  • 程式碼庫中存在什麼模式
  • 專案使用什麼術語

標準方法失敗:

  • 傳送所有內容:超過上下文限制
  • 不傳送內容:Agent 缺乏關鍵資訊
  • 猜測需要什麼:經常錯誤

解決方案:迭代檢索

一個漸進精煉上下文的 4 階段循環:

┌─────────────────────────────────────────────┐
│                                             │
│   ┌──────────┐      ┌──────────┐            │
│   │ DISPATCH │─────▶│ EVALUATE │            │
│   └──────────┘      └──────────┘            │
│        ▲                  │                 │
│        │                  ▼                 │
│   ┌──────────┐      ┌──────────┐            │
│   │   LOOP   │◀─────│  REFINE  │            │
│   └──────────┘      └──────────┘            │
│                                             │
│        最多 3 個循環,然後繼續               │
└─────────────────────────────────────────────┘

階段 1:DISPATCH

初始廣泛查詢以收集候選檔案:

// 從高層意圖開始
const initialQuery = {
  patterns: ['src/**/*.ts', 'lib/**/*.ts'],
  keywords: ['authentication', 'user', 'session'],
  excludes: ['*.test.ts', '*.spec.ts']
};

// 派遣到檢索 agent
const candidates = await retrieveFiles(initialQuery);

階段 2:EVALUATE

評估檢索內容的相關性:

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

基於評估更新搜尋標準:

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)
  };
}

Read the full file on GitHub · 203 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 203 lines · 19 tokens per session scan A 5e94e4373e16

Subscribe to this mod's changes

iterative-retrieval is a skill published in the GitHub repository codelably/harmony-claude-code (42 stars, last pushed 6mo ago), licensed MIT. It adds 19 tokens to every session and 1,736 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.