Skip to content

Bit-urd/biturd-agent

Repository files navigation

Claude Code Tools

这是一套通用的 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

快速开始

1. 复制到你的项目

# 复制整个工具集到你的项目
cp -r claude-code-tools /path/to/your/project/.claude-tools

# 或者只复制 hooks 目录
cp -r claude-code-tools/hooks /path/to/your/project/.claude/hooks

2. 配置 Claude Code

创建 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"
          }
        ]
      }
    ]
  }
}

3. 安装 hooks 到 Claude Code

cd claude-code-tools/hooks
./integrate.sh  # 自动集成到 ~/.claude/hooks/

4. 配置项目级 CLAUDE.md

复制 CLAUDE.md 到你的项目根目录,根据项目需要进行自定义。

主要功能

Hooks 系统

  • 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

故障排除

调试 hooks

# 启用详细输出
export CLAUDE_HOOKS_DEBUG=1

# 手动运行 hook 进行测试
echo '{"eventType": "PostToolUse", "toolName": "Write"}' | ./hooks/smart-lint.sh

常见问题

  1. Hooks 不执行: 检查文件权限 chmod +x ~/.claude/hooks/*.sh
  2. 找不到命令: 确保相关工具已安装 (golangci-lint, shellcheck 等)
  3. 测试失败: 检查项目结构是否符合预期

自定义和扩展

添加新的语言支持

  1. 创建 lint-newlang.shtest-newlang.sh
  2. smart-lint.shsmart-test.sh 中添加检测逻辑
  3. 添加相应的测试用例

自定义通知

修改 ntfy-notifier.sh 或创建自己的通知脚本。

许可证

使用 MIT 许可证。

贡献

欢迎提交 issue 和 pull request 来改进这个工具集。

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published