Agent skill

Iterative Retrieval

by xu-xiang in xu-xiang/everything-claude-code-zh

“逐步优化上下文检索以解决子代理上下文问题的模式”

— description from SKILL.md by xu-xiang
MITAuto-check passed

Install Iterative Retrieval

skills CLI
$ npx skills add xu-xiang/everything-claude-code-zh --skill iterative-retrieval -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install xu-xiang/everything-claude-code-zh iterative-retrieval --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/xu-xiang/everything-claude-code-zh.git skills-src && mkdir -p .claude/skills && cp -r skills-src/docs/zh-CN/skills/iterative-retrieval .claude/skills/iterative-retrieval && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
iterative-retrieval
GitHub stars
2k
Used in
1 other repo
Token cost
~1.2k tokens
SKILL.md length
81 words
Files
1
Skills in repo
78
Repo updated
First seen
Licence
MIT

At a glance

  • Works in 5 steps: 先宽泛,后逐步细化 - 不要过度指定初始查询 → 学习代码库术语 - 第一轮循环通常能揭示命名约定 → 跟踪缺失内容 - 明确识别差距以驱动优化 → …
  • SKILL.md covers 何时激活, 问题, 解决方案:迭代检索 and 实际示例, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

About this skill

Iterative Retrieval is a skill in xu-xiang/everything-claude-code-zh (2k stars). Its SKILL.md is about 1.2k tokens, and copies of it appear in 1 other owners' repositories. Licence: MIT.

Workflow steps

5 steps, taken from the first numbered list in SKILL.md.

  1. 先宽泛,后逐步细化 - 不要过度指定初始查询
  2. 学习代码库术语 - 第一轮循环通常能揭示命名约定
  3. 跟踪缺失内容 - 明确识别差距以驱动优化
  4. 在“足够好”时停止 - 3 个高相关性文件胜过 10 个中等相关性文件
  5. 自信地排除 - 低相关性文件不会变得相关

What it can do on your machine

Read from SKILL.md and the folder at commit dfbf946. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are javascript and markdown).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    Links to these hosts (documentation or services it may open):

    • x.com

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Iterative Retrieval loads about 1.2k tokens when it runs. Until then it costs about 11 tokens; SKILL.md has 81 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~11
When it runs · the whole SKILL.md, loaded when a task matches
~1.2k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from xu-xiang/everything-claude-code-zh at commit dfbf946, republished under its MIT licence (© xu-xiang). 81 words, ~1,180 tokens.

Download SKILL.mdSave it as .claude/skills/iterative-retrieval/SKILL.md (or your agent's skills folder).
name
iterative-retrieval
description
逐步优化上下文检索以解决子代理上下文问题的模式
origin
ECC

迭代检索模式

解决多智能体工作流中的“上下文问题”,即子智能体在开始工作前不知道需要哪些上下文。

何时激活

  • 当需要生成需要代码库上下文但无法预先预测的子代理时
  • 构建需要逐步完善上下文的多代理工作流时
  • 在代理任务中遇到"上下文过大"或"缺少上下文"的失败时
  • 为代码探索设计类似 RAG 的检索管道时
  • 在代理编排中优化令牌使用时

问题

子智能体被生成时上下文有限。它们不知道:

  • 哪些文件包含相关代码
  • 代码库中存在哪些模式
  • 项目使用什么术语

标准方法会失败:

  • 发送所有内容:超出上下文限制
  • 不发送任何内容:智能体缺乏关键信息
  • 猜测所需内容:经常出错

解决方案:迭代检索

一个逐步优化上下文的 4 阶段循环:

┌─────────────────────────────────────────────┐
│                                             │
│   ┌──────────┐      ┌──────────┐            │
│   │ DISPATCH │─────▶│ EVALUATE │            │
│   └──────────┘      └──────────┘            │
│        ▲                  │                 │
│        │                  ▼                 │
│   ┌──────────┐      ┌──────────┐            │
│   │   LOOP   │◀─────│  REFINE  │            │
│   └──────────┘      └──────────┘            │
│                                             │
│        Max 3 cycles, then proceed           │
└─────────────────────────────────────────────┘
阶段 1:调度

初始的广泛查询以收集候选文件:

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);
阶段 2:评估

评估检索到的内容的相关性:

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:优化

根据评估结果更新搜索条件:

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)
  };
}
阶段 4:循环

使用优化后的条件重复(最多 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);

    // 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(evaluation, query);
    bestContext = mergeContext(bestContext, highRelevance);
  }

  return bestContext;
}

实际示例

示例 1:错误修复上下文
Task: "Fix the authentication token expiry bug"

Cycle 1:
  DISPATCH: Search for "token", "auth", "expiry" in src/**
  EVALUATE: Found auth.ts (0.9), tokens.ts (0.8), user.ts (0.3)
  REFINE: Add "refresh", "jwt" keywords; exclude user.ts

Cycle 2:
  DISPATCH: Search refined terms
  EVALUATE: Found session-manager.ts (0.95), jwt-utils.ts (0.85)
  REFINE: Sufficient context (2 high-relevance files)

Result: auth.ts, tokens.ts, session-manager.ts, jwt-utils.ts
示例 2:功能实现
Task: "Add rate limiting to API endpoints"

Cycle 1:
  DISPATCH: Search "rate", "limit", "api" in routes/**
  EVALUATE: No matches - codebase uses "throttle" terminology
  REFINE: Add "throttle", "middleware" keywords

Cycle 2:
  DISPATCH: Search refined terms
  EVALUATE: Found throttle.ts (0.9), middleware/index.ts (0.7)
  REFINE: Need router patterns

Cycle 3:
  DISPATCH: Search "router", "express" patterns
  EVALUATE: Found router-setup.ts (0.8)
  REFINE: Sufficient context

Result: 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. 自信地排除 - 低相关性文件不会变得相关

相关

  • 长篇指南 - 子智能体编排部分
  • continuous-learning 技能 - 用于随时间改进的模式
  • 在 ~/.claude/agents/ 中的智能体定义

© xu-xiang, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in docs/zh-CN/skills/iterative-retrieval of xu-xiang/everything-claude-code-zh.

Open the folder on GitHubat commit dfbf946

Used in 1 other repository

We found 1 copy of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in xu-xiang/everything-claude-code-zh, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Iterative Retrieval next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Iterative Retrieval compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Iterative Retrieval this skillxu-xiang/everything-claude-code-zh2k1 repos~1.2kAutomated safety check: PassMIT
Iterative Retrievalaffaan-m/ECC276k7 repos~1.6kAutomated safety check: PassMIT
Iterative Retrievalaffaan-m/ECC276k2 repos~1.1kAutomated safety check: PassMIT
Iterative Retrievalaffaan-m/ECC276k2 repos~1.3kAutomated safety check: PassMIT
Iterative Retrievalaffaan-m/ECC276k1 repos~1.1kAutomated safety check: PassMIT
Retrieval Reflexgarrytan/gbrain31k—~735Automated safety check: PassMIT

Similar skills

  • Pattern for progressively refining context retrieval to solve the subagent context problem.

    276k GitHub starsUsed in 7 repos~1.6k tokens
    Agent WorkflowsAuto-check passed
  • サブエージェントのコンテキスト問題を解決するために、コンテキスト取得を段階的に洗練するパターン. An agent skill from affaan-m/ECC.

    276k GitHub starsUsed in 2 repos~1.1k tokens
    Auto-check passed
  • 서브에이전트 컨텍스트 문제를 해결하기 위한 점진적 컨텍스트 검색 개선 패턴. An agent skill from affaan-m/ECC.

    276k GitHub starsUsed in 2 repos~1.3k tokens
    Auto-check passed
  • 逐步优化上下文检索以解决子代理上下文问题的模式

    276k GitHub starsUsed in 1 repo~1.1k tokens
    Auto-check passed
  • Retrieval Reflex

    garrytan/gbrain

    When/what to retrieve — open the brain page for a salient entity before answering from memory.

    31k GitHub stars~735 tokensUpdated yesterday
    Auto-check passed
  • Grade Iterate

    alirezarezvani/claude-skills

    Phase 3 of building a Claude Managed Agent — the bounded grade→iterate loop.

    28k GitHub stars~1k tokensUpdated 1 mo ago
    EducationAuto-check passed

More from xu-xiang/everything-claude-code-zh

All 78 skills in this repo
  • Configure Ecc

    xu-xiang/everything-claude-code-zh

    Everything Claude Code 的交互式安装程序 — 引导用户选择并安装技能和规则到用户级或项目级目录,验证路径,并可选择优化已安装文件。

    2k GitHub starsUsed in 1 repo~2.1k tokens
    Auto-check passed
  • Continuous Learning V2

    xu-xiang/everything-claude-code-zh

    基于本能(Instinct)的学习系统,通过钩子(hooks)观察会话,创建带有置信度评分的原子本能,并将其演化为技能(Skills)、命令(Commands)或智能体(Agents)。v2.1 版本增加了项目作用域(project-scoped)的本能,以防止跨项目污染。

    2k GitHub stars~2.1k tokensUpdated 7 mo ago
    Auto-check passed
  • API Design

    xu-xiang/everything-claude-code-zh

    生产级 API 的 REST API 设计模式,包括资源命名、状态码、分页、过滤、错误响应、版本控制和速率限制. An agent skill from xu-xiang/everything-claude-code-zh.

    2k GitHub stars~2.7k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及适用于 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.2k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.1k tokensUpdated 7 mo ago
    Auto-check passed
  • Backend Patterns

    xu-xiang/everything-claude-code-zh

    后端架构模式、API 设计、数据库优化以及针对 Node.js、Express 和 Next.js API 路由的服务端最佳实践。

    2k GitHub stars~3.2k tokensUpdated 7 mo ago
    Auto-check passed

Questions about Iterative Retrieval

How do I install Iterative Retrieval in Claude Code?

Run `npx skills add xu-xiang/everything-claude-code-zh --skill iterative-retrieval -a claude-code`. Or copy the skill folder (docs/zh-CN/skills/iterative-retrieval in xu-xiang/everything-claude-code-zh) into .claude/skills/iterative-retrieval in your project. Claude Code loads it when a task matches its description.

How do I install Iterative Retrieval in Codex?

Run `npx skills add xu-xiang/everything-claude-code-zh --skill iterative-retrieval -a codex`. Or copy the skill folder (docs/zh-CN/skills/iterative-retrieval in xu-xiang/everything-claude-code-zh) into .agents/skills/iterative-retrieval in your project. Codex loads it when a task matches its description.

Can I use Iterative Retrieval in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add xu-xiang/everything-claude-code-zh --skill iterative-retrieval -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/iterative-retrieval, .gemini/skills/iterative-retrieval, .github/skills/iterative-retrieval and .opencode/skills/iterative-retrieval in your project.

What does Iterative Retrieval need to run?

SKILL.md names no scripts, command-line tools or credentials: Iterative Retrieval is instructions for the agent only.

Does Iterative Retrieval access the network?

SKILL.md names 1 domain. As links in the text: x.com. This is read from the text; nothing was executed.

Is Iterative Retrieval safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Iterative Retrieval use?

Iterative Retrieval is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Iterative Retrieval use?

About 1.2k tokens (SKILL.md is roughly 4.7k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Iterative Retrieval?

Skills that share tags, products or a category with Iterative Retrieval: Iterative Retrieval (affaan-m/ECC, 276k stars), Iterative Retrieval (affaan-m/ECC, 276k stars), Iterative Retrieval (affaan-m/ECC, 276k stars) and Iterative Retrieval (affaan-m/ECC, 276k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Iterative Retrieval?

xu-xiang (a GitHub user) maintains it in xu-xiang/everything-claude-code-zh, which has 1,978 GitHub stars. The repository holds 78 skills in this directory. The repository was last updated on March 5, 2026.

Source: xu-xiang/everything-claude-code-zh on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.