batch-operations
它能做什么
这项技能让你的 AI 在项目的多个文件中执行同一项一致的编辑。适合需要在各处完成相同重命名或更新的开发者。
适用场景
- ✓当你想在代码库中所有使用某个函数或组件的地方将其重命名时。
- ✓当你需要在许多文件中更新版本号或导入语句时。
- ✓当你需要把项目从一个库迁移到另一个库,涉及许多文件时。
技能链接
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/batch-operations/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请把我项目中每个文件里的 getUser 函数重命名为 fetchUser。”
每周 5 个新技能,1 分钟读完。
工作原理
这项技能首先找出所有匹配的文件并预览修改内容。然后,它会在这些文件中执行相同的替换。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Batch Operations — Multi-File Changes
Apply consistent changes across many files at once. One pattern, many targets.
When to Use
✅ Good for:
- Renaming a function/component across all files that use it
- Adding an import to every file in a directory
- Updating version numbers across package files
- Applying the same code pattern to multiple similar files
- Migrating from one API to another across the codebase
- Adding/removing a field from all similar data structures
❌ Not for:
- Single-file edits (use direct editing)
- Unique changes per file (handle individually)
- Changes that need per-file judgment (use an agent per domain)
Batch Operation Protocol
Step 1: Define the Pattern
What: [exact text/pattern to find]
Replace: [exact replacement text]
Scope: [file glob pattern, e.g., "src/**/*.tsx"]
Exclude: [files to skip, e.g., "**/*.test.tsx"]
Step 2: Preview Before Executing
# Find all affected files FIRST
grep -rl "oldPattern" src/ --include="*.ts"
# Count matches
grep -rc "oldPattern" src/ --include="*.ts" | grep -v ":0$"
# Show context for each match
grep -rn "oldPattern" src/ --include="*.ts"
🔴 NEVER batch-modify without previewing first. Show the user what will change.
Step 3: Execute the Batch
For text replacements:
# On Linux/macOS
find src -name "*.ts" -exec sed -i 's/oldPattern/newPattern/g' {} +
# On Windows (PowerShell)
Get-ChildItem -Path src -Recurse -Filter *.ts |
ForEach-Object { (Get-Content $_) -replace 'oldPattern','newPattern' | Set-Content $_ }
For structural changes (adding imports, wrapping code):
- Use the Edit tool on each file
- Process files in a consistent order (alphabetical or by dependency)
Step 4: Verify the Batch
# Confirm no missed instances
grep -rl "oldPattern" src/ --include="*.ts"
# Should return empty
# Confirm replacements are correct
grep -rn "newPattern" src/ --include="*.ts" | head -5
# Run tests to catch breakage
npm run test
npm run build
Common Batch Patterns
| Operation | Command Pattern |
|---|---|
| Rename import | Find all import { X } → replace with import { Y } |
| Update version | Find "version": "1.0" → replace across all package.json |
| Add export | Append export { X } to all index files |
| Remove deprecated | Find deprecatedFn() → replace with newFn() |
| Add header | Prepend license header to all source files |
| Type migration | Find interface X → replace with type X = |
Safety Rules
- Preview first — always show affected files before modifying
- Git safety — ensure clean working directory (
git stashor commit first) - Exclude tests — often tests need different treatment than source
- Verify after — run build + tests after every batch operation
- Report changes — list every file modified with change summary
常见问题
在文件被修改之前,我应该检查匹配结果吗?
应该。这项技能先进行预览步骤,让你能看到每一个受影响的文件。
它对单个文件有用吗?
没有用。对于单个文件,直接编辑更简单,这一点技能本身也有说明。
它适用于每个文件都需要判断的修改吗?
不适用。这项技能指出,这类情况最好逐个文件处理。
详情
作者的原始描述
Apply operations across multiple files simultaneously. Pattern-based bulk modifications, search-and-replace across codebases, consistent changes to many files at once.
repo: vudovn/ag-kit
热度
- GitHub 星标
- 8.2k
- 排名
- #12525
- 许可证
- MIT
- 更新时间
- 2026/10/18
评论
- …