这是一套通用的 Claude Code 工具集合,可以在任何项目中独立使用。
claude-code-tools/
├── README.md # 本文件
├── CLAUDE.md # 开发规范和工作流程指导
├── settings.json # Claude Code 配置文件示例
├── hooks/ # Claude Code hooks 系统
│ ├── README.md # Hooks 详细文档
│ ├── QUICK_START.md # 快速开始指南
│ ├── INTEGRATION.md # 集成说明
│ ├── Makefile # 测试和验证工具
│ ├── smart-lint.sh # 智能代码检查
│ ├── smart-test.sh # 智能测试运行
│ ├── statusline.sh # 状态栏显示
│ ├── ntfy-notifier.sh # 通知系统
│ ├── common-helpers.sh # 公共工具函数
│ ├── lint-*.sh # 各种语言的代码检查脚本
│ ├── test-*.sh # 各种语言的测试脚本
│ ├── spec/ # ShellSpec 测试套件
│ └── 示例配置文件...
├── commands/ # Claude Code 自定义命令
│ ├── check.md
│ ├── next.md
│ ├── prompt.md
│ └── validate.md
└── docs/ # 技术文档
├── claude-notify-go-design.md
└── claude-remote-setup.md
# 复制整个工具集到你的项目
cp -r claude-code-tools /path/to/your/project/.claude-tools
# 或者只复制 hooks 目录
cp -r claude-code-tools/hooks /path/to/your/project/.claude/hooks
创建 Claude Code 配置文件 ~/.claude/settings.json
:
{
"env": {
"BASH_DEFAULT_TIMEOUT_MS": "300000",
"BASH_MAX_TIMEOUT_MS": "600000"
},
"statusLine": {
"type": "command",
"command": "~/.claude/hooks/statusline.sh",
"padding": 0
},
"hooks": {
"PostToolUse": [
{
"matcher": "Write|Edit|MultiEdit",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/smart-lint.sh"
},
{
"type": "command",
"command": "~/.claude/hooks/smart-test.sh"
}
]
}
],
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "~/.claude/hooks/ntfy-notifier.sh"
}
]
}
]
}
}
cd claude-code-tools/hooks
./integrate.sh # 自动集成到 ~/.claude/hooks/
复制 CLAUDE.md
到你的项目根目录,根据项目需要进行自定义。
- smart-lint.sh: 自动检测项目类型并运行相应的代码检查工具
- smart-test.sh: 自动检测并运行项目测试
- statusline.sh: 显示项目状态信息
- ntfy-notifier.sh: 发送通知到 ntfy.sh 服务
- Go: golangci-lint, go test, go fmt
- Python: flake8, pytest, black
- JavaScript/TypeScript: ESLint, Prettier, Jest
- Shell: ShellCheck
- Tilt: buildifier, Python linting for Tiltfiles
/check
: 运行项目检查/next
: 获取下一步建议/prompt
: 生成提示/validate
: 验证代码
# 启用调试模式
export CLAUDE_HOOKS_DEBUG=1
# 配置 ntfy 通知
export NTFY_TOPIC="your-topic"
export NTFY_SERVER="https://ntfy.sh"
# 项目特定配置
export PROJECT_TYPE="go" # 强制项目类型
在项目根目录创建 .claude-hooks-config.sh
:
#!/bin/bash
# 项目特定的 hooks 配置
# 自定义 lint 命令
CUSTOM_LINT_CMD="make lint"
# 自定义测试命令
CUSTOM_TEST_CMD="make test"
# 忽略特定文件模式
IGNORE_PATTERNS=("*.generated.go" "vendor/*")
创建 .claude-hooks-ignore
文件来忽略特定文件或目录:
# 忽略生成的文件
*.generated.go
*_gen.go
# 忽略依赖目录
node_modules/
vendor/
__pycache__/
# 忽略构建输出
build/
dist/
target/
cd hooks
make test # 运行所有测试
make lint # 运行代码检查
make check # 运行 lint + test
# 启用详细输出
export CLAUDE_HOOKS_DEBUG=1
# 手动运行 hook 进行测试
echo '{"eventType": "PostToolUse", "toolName": "Write"}' | ./hooks/smart-lint.sh
- Hooks 不执行: 检查文件权限
chmod +x ~/.claude/hooks/*.sh
- 找不到命令: 确保相关工具已安装 (golangci-lint, shellcheck 等)
- 测试失败: 检查项目结构是否符合预期
- 创建
lint-newlang.sh
和test-newlang.sh
- 在
smart-lint.sh
和smart-test.sh
中添加检测逻辑 - 添加相应的测试用例
修改 ntfy-notifier.sh
或创建自己的通知脚本。
使用 MIT 许可证。
欢迎提交 issue 和 pull request 来改进这个工具集。