cc工具
CLI伴侣 克劳德代码 它自动化了钩子事件处理、并行lint/test验证、MCP服务器管理、通知、会话跟踪和每个目录跳过配置。
它做什么
cc工具插入Claude Code的钩子系统,在每个钩子事件上运行处理程序——会话生命周期、工具使用、通知和上下文压缩。当配置为 PostToolUse 钩子 validate 命令拦截文件编辑,并在接受更改之前并行运行项目的linter和测试套件。如果任一操作失败,工具调用将被阻止,并显示格式化的错误消息。
除了验证之外,cc工具还提供:
- 吊钩调度 --一个处理程序注册表,将所有Claude Code钩子事件路由到专门构建的处理程序
- 通知 --音频播放、macOS桌面警报和安静时间的ntfy推送通知
- 会话跟踪 --存储会话元数据,支持别名和搜索
- 观测记录 --记录工具使用事件进行分析
- MCP管理 --启用/禁用MCP服务器集成
- 跳过注册表 --lint、test或两者的每个目录跳过规则
安装
需要Go 1.26+和 任务.
task build # Build to ./bin/cc-tools
task install # Copy to $GOPATH/bin命令
cc-tools [arguments]| 命令 | 描述 |
|---|---|
hook | 将Claude Code钩子事件分派给已注册的处理程序(从stdin读取JSON) |
validate | 并行运行lint和测试(从stdin读取JSON) |
session | 列出、搜索和管理会话元数据和别名 |
config | 获取、设置、列出和重置应用程序设置 |
skip | 配置目录以跳过验证(lint、test或all) |
unskip | 从目录中删除跳过设置 |
mcp | 管理Claude MCP服务器(列出、启用、禁用) |
debug | 配置调试日志记录(启用、禁用、状态、列表、文件名) |
钩子集成
添加到您的克劳德代码设置(~/.claude/settings.json):
{
"hooks": {
"PreToolUse": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"PostToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [{ "type": "command", "command": "cc-tools validate" }]
},
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"SessionStart": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"SessionEnd": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"UserPromptSubmit": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"Stop": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"Notification": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
],
"PreCompact": [
{
"matcher": "*",
"hooks": [{ "type": "command", "command": "cc-tools hook" }]
}
]
}
}这 hook 命令从stdin读取事件JSON,分派给已注册的处理程序,并返回结构化输出。这 validate command发现项目的lint/test命令并同时运行它们。
注册处理程序
| 事件 | 处理程序 |
|---|---|
| SessionStart | 超级电源注入、包管理器检测、会话上下文 |
| SessionEnd | 会话元数据持久化 |
| PreToolUse | 精简建议、观察记录、提交前提醒 |
| PostToolUse | 观察记录 |
| UserPromptSubmit | 漂移检测(当会话偏离原始意图时发出警告) |
| 停止 | 使用循环会话提醒跟踪响应计数 |
| 预压缩 | 原木压缩 |
| 通知 | 音频播放、桌面提醒、ntfy推送 |
例子
# Dispatch a hook event (stdin receives event JSON)
echo '{"hook_event_name":"Notification","title":"Done","message":"Tests passed"}' | cc-tools hook
# Validate a file edit
echo '{"tool_name":"Edit","tool_input":{"file_path":"main.go"}}' | cc-tools validate
# Manage sessions
cc-tools session list
cc-tools session info
cc-tools session search "auth refactor"
cc-tools session alias set latest
# Manage MCP servers
cc-tools mcp list
cc-tools mcp enable jira
cc-tools mcp disable jira
# Skip validation for a directory
cc-tools skip lint /path/to/generated
cc-tools skip list
# Configure settings
cc-tools config set validate.timeout 120
cc-tools config get validate.timeout
cc-tools config list配置
设置存储在 ~/.config/cc-tools/config.json.
| 密钥 | 默认值 | 描述 |
|---|---|---|
validate.timeout | 60 | 验证超时(秒) |
validate.cooldown | 5 | 验证运行之间的冷却 |
notifications.ntfy_topic | "" | ntfy.sh推送通知主题 |
compact.threshold | 50 | 紧凑型建议的令牌阈值 |
compact.reminder_interval | 25 | 紧凑型提醒之间的工具调用 |
notify.quiet_hours.enabled | true | 在安静时段抑制通知 |
notify.quiet_hours.start | "21:00" | 安静时间开始时间(HH:MM) |
notify.quiet_hours.end | "07:30" | 安静时间结束时间(HH:MM) |
notify.audio.enabled | true | 启用音频通知声音 |
notify.audio.directory | "~/.claude/audio" | MP3文件目录的路径 |
notify.desktop.enabled | true | 启用macOS桌面通知 |
observe.enabled | true | 启用工具使用观察日志记录 |
observe.max_file_size_mb | 10 | 观测日志记录的最大文件大小(MB) |
learning.min_session_length | 10 | 学习提取的最小会话长度 |
learning.learned_skills_path | ".claude/skills/learned" | 学习技能文件的路径 |
pre_commit_reminder.enabled | true | 提醒在git提交之前运行检查 |
pre_commit_reminder.command | "task pre-commit" | 提交前建议的命令 |
package_manager.preferred | "" | 首选包管理器(覆盖自动检测) |
drift.enabled | true | 根据提示启用漂移检测 |
drift.min_edits | 6 | 检查漂移前的最小编辑量 |
drift.threshold | 0.2 | 关键字重叠率,低于该比率则标记漂移 |
stop_reminder.enabled | true | 启用定期会话提醒 |
stop_reminder.interval | 20 | 提醒之间的响应 |
stop_reminder.warn_at | 50 | 强烈总结警告的响应计数 |
调试日志将写入 ~/.cache/cc-tools/debug/.
发展
task doctor # Check required tools
task tools-install # Install gotestsum, golangci-lint, goimports, mockery
task build # Build binary
task test # Fast tests (-short, 30s)
task lint # golangci-lint
task check # fmt + lint + test-race (run before committing)
task test-race # Tests with race detector
task mocks # Regenerate mocks
task coverage # HTML coverage report许可证
看 许可证 了解详情。
