name: tool-creator description: 为 Claude Code 框架创建工具文件。工具是可执行实用程序,按类别组织在 .claude/tools/ 中。 version: 1.0.0 model: sonnet invoked_by: both user_invocable: true tools: [Read, Write, Edit, Bash] args: ‘–name <工具名称> --category <类别> --implementation <代码>’ best_practices:
- 工具是 CLI 可执行脚本 (.cjs 或 .mjs)
- 保持工具专注(单一职责)
- 添加帮助文本和使用示例
- 包含错误处理 error_handling: graceful streaming: supported output_location: .claude/tools/ verified: false lastVerifiedAt: 2026-02-19T05:29:09.098Z
工具创建器
在 .claude/tools/<category>/ 中创建可执行工具文件。工具按类别组织,如 cli、analysis、validation、integrations 等。
步骤 0: 检查现有工具
在创建前,检查工具是否已存在:
find .claude/tools/ -name "<tool-name>.*" -type f
如果存在 → 调用 Skill({ skill: "artifact-updater", args: "--type tool --path .claude/tools/<category>/<tool-name>.cjs --changes '...'" })
如果新 → 继续步骤 0.5。
步骤 0.5: 伴随检查
在继续创建前,运行生态系统伴随检查:
- 使用
.claude/lib/creators/companion-check.cjs中的companion-check.cjs - 调用
checkCompanions("tool", "{tool-name}")以识别伴随工件 - 查看伴随检查清单 — 记下缺少的必需/推荐伴随项
- 计划在创建后创建或验证缺少的伴随项
- 在创建后集成笔记中包含伴随发现
此步骤是信息性的(不阻止创建)但确保考虑整个工件生态系统。
何时使用
- 创建可重用的命令行实用程序
- 构建分析或验证脚本
- 实现框架自动化工具
- 添加工作流集成实用程序
工具文件格式
工具是 CommonJS 或 ESM 模块,包含:
#!/usr/bin/env node
/**
* 工具名称 - 简要描述
*
* 用法:
* node .claude/tools/<category>/<tool-name>.cjs [选项]
*
* 选项:
* --help 显示帮助
* --option 描述
*/
const main = async () => {
// 工具实现
};
if (require.main === module) {
main().catch(console.error);
}
module.exports = { main };
工具类别
| 类别 | 用途 | 示例 |
|---|---|---|
cli |
命令行实用程序 | 验证器、格式化器 |
analysis |
代码分析工具 | 复杂性、依赖关系 |
validation |
验证脚本 | 模式、lint |
integrations |
外部集成工具 | API 客户端、webhooks |
maintenance |
框架维护 | 清理、迁移 |
optimization |
性能优化 | 索引、缓存 |
runtime |
运行时实用程序 | 配置读取器、加载器 |
visualization |
图表和图形生成 | mermaid、graphviz |
workflow |
工作流自动化 | 任务运行器、协调器 |
gates |
质量门和检查 | 覆盖率、安全性 |
context |
上下文管理 | 压缩、交接 |
创建工作流
步骤 1: 验证输入
// 验证工具名称(小写,连字符,无空格)
const toolName = args.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');
// 验证类别存在
const validCategories = [
'cli',
'analysis',
'validation',
'integrations',
'maintenance',
'optimization',
'runtime',
'visualization',
'workflow',
'gates',
'context',
];
if (!validCategories.includes(args.category)) {
throw new Error(`无效类别。必须是以下之一: ${validCategories.join(', ')}`);
}
步骤 2: 创建工具文件
const toolPath = `.claude/tools/${args.category}/${toolName}.cjs`;
// 创建工具目录(如果不存在)
await mkdir(`.claude/tools/${args.category}`, { recursive: true });
// 生成工具内容
const content = `#!/usr/bin/env node
/**
* ${toolName.replace(/-/g, ' ').replace(/\b\w/g, l => l.toUpperCase())} - ${args.description || '工具描述'}
*
* 用法:
* node .claude/tools/${args.category}/${toolName}.cjs [选项]
*
* 选项:
* --help 显示此帮助信息
*/
${args.implementation}
if (require.main === module) {
main().catch(console.error);
}
module.exports = { main };
`;
await writeFile(toolPath, content);
// 使其可执行(类 Unix 系统)
if (process.platform !== 'win32') {
await chmod(toolPath, '755');
}
步骤 3: 更新工具目录
const catalogPath = '.claude/context/artifacts/catalogs/tool-catalog.md';
// 在适当类别下添加条目到目录
const newEntry = `| ${toolName} | ${args.description} | .claude/tools/${args.category}/${toolName}.cjs | active |`;
// 插入到目录中,保留类别结构
步骤 4: 运行创建后集成
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
await runIntegrationChecklist('tool', toolPath);
await queueCrossCreatorReview('tool', toolPath, {
artifactName: toolName,
createdBy: 'tool-creator',
category: args.category,
});
创建后集成
工具创建后,运行集成检查清单:
const {
runIntegrationChecklist,
queueCrossCreatorReview,
} = require('.claude/lib/creator-commons.cjs');
// 1. 运行集成检查清单
const result = await runIntegrationChecklist('tool', '.claude/tools/<category>/<tool-name>.cjs');
// 2. 排队跨创建者审核
await queueCrossCreatorReview('tool', '.claude/tools/<category>/<tool-name>.cjs', {
artifactName: '<tool-name>',
createdBy: 'tool-creator',
category: '<category>',
});
// 3. 审查影响报告
// 检查 result.mustHave 中的失败项 — 在标记完成前解决
集成验证:
- [ ] 工具已添加到 tool-catalog.md 中的正确类别下
- [ ] 工具文件可执行(Unix)或可运行(Windows)
- [ ] 工具有帮助文本和使用示例
- [ ] 工具通过基本冒烟测试
使用示例
创建验证工具
Skill({
skill: 'tool-creator',
args: `--name schema-validator --category validation --implementation "
const validateSchema = async () => {
console.log('验证模式...');
};
const main = async () => {
await validateSchema();
};
"`,
});
创建分析工具
Skill({
skill: 'tool-creator',
args: `--name complexity-analyzer --category analysis --implementation "
const analyzeComplexity = async (filePath) => {
console.log('分析复杂性:', filePath);
};
const main = async () => {
const [,, filePath] = process.argv;
await analyzeComplexity(filePath);
};
"`,
});
相关技能
skill-creator- 创建调用工具的技能artifact-updater- 更新现有工具
内存协议(强制)
开始前:
阅读 .claude/context/memory/learnings.md
完成后:
- 新工具模式 →
.claude/context/memory/learnings.md - 工具创建问题 →
.claude/context/memory/issues.md - 类别决策 →
.claude/context/memory/decisions.md
假设中断:如果不在内存中,它就没有发生。
生态系统对齐契约(强制)
此创建者技能是一个协调创建者生态系统的一部分。此处创建的任何工件必须对齐并验证相关创建者:
agent-creator用于所有权和执行路径skill-creator用于能力打包和分配tool-creator用于可执行自动化表面hook-creator用于强制执行和护栏rule-creator和semgrep-rule-creator用于政策和静态检查template-creator用于标准化脚手架workflow-creator用于编排和阶段门控command-creator用于用户/操作员命令 UX
跨创建者握手(必需)
完成前,验证所有相关握手:
- 工件路由存在于
.claude/CLAUDE.md和相关路由文档中。 - 发现/注册条目已更新(目录/索引/注册表适用)。
- 伴随工件已创建或明确豁免并说明原因。
validate-integration.cjs通过创建的工件。- 技能索引在技能元数据更改时重新生成。
研究门(首选 Exa,备用 arXiv)
对于新模式、模板或工作流,研究是强制性的:
- 首先使用 Exa 获取实现和生态系统模式。
- 如果 Exa 不足,使用
WebFetch加上 arXiv 参考。 - 在工件参考/文档中记录决策、约束和非目标。
- 保持更新最小化,避免过度工程。
回归安全交付
- 遵循严格的 RED -> GREEN -> REFACTOR 进行行为更改。
- 对更改的模块运行定向测试。
- 对更改的文件运行 lint/format。
- 保持提交按关注点范围化(逻辑/文档/生成的工件)。