hook-manager
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseHook Manager
钩子管理器
Discover, install, and manage automation hooks from the bopen-tools collection for Claude Code and Opencode.
发现、安装并管理来自bopen-tools集合的、适用于Claude Code和Opencode的自动化钩子。
Available Hooks
可用钩子列表
| Hook | Event | Description | Auto-install |
|---|---|---|---|
| PreToolUse | Blocks edits to .env files (security) | Recommended |
| Stop | Shows uncommitted changes when agent stops | Optional |
| PostToolUse | Auto-stages files after edits | Optional |
| UserPromptSubmit | Adds timestamp/dir/branch to prompts | Optional |
| PostToolUse | Runs lint:fix after file edits | Optional |
| SessionStart | Runs linting on session start | Optional |
| PostToolUse | Runs tests after file edits | Optional |
| PreToolUse | Protects shadcn UI components | Optional |
| 钩子名称 | 触发事件 | 描述 | 安装建议 |
|---|---|---|---|
| PreToolUse | 阻止对.env文件的编辑(安全防护) | 推荐 |
| Stop | 当Agent停止运行时,显示未提交的变更 | 可选 |
| PostToolUse | 文件编辑后自动暂存修改 | 可选 |
| UserPromptSubmit | 在提示中添加时间戳/目录/分支信息 | 可选 |
| PostToolUse | 文件编辑后自动运行lint:fix | 可选 |
| SessionStart | 会话启动时自动运行代码检查 | 可选 |
| PostToolUse | 文件编辑后自动运行测试 | 可选 |
| PreToolUse | 保护shadcn UI组件文件不被修改 | 可选 |
Installing a Hook
安装钩子
Hooks are installed by copying the JSON config to your agent's hooks directory:
钩子的安装方式是将JSON配置文件复制到Agent的钩子目录中:
Claude Code
Claude Code
bash
undefinedbash
undefinedCreate hooks directory if needed
若需要则创建钩子目录
mkdir -p ~/.claude/hooks
mkdir -p ~/.claude/hooks
Copy hook from plugin cache
从插件缓存中复制钩子文件
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/<hook-name>.json ~/.claude/hooks/
undefinedcp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/<hook-name>.json ~/.claude/hooks/
undefinedOpencode
Opencode
bash
undefinedbash
undefinedCreate hooks directory if needed
若需要则创建钩子目录
mkdir -p ~/.opencode/hooks
mkdir -p ~/.opencode/hooks
Copy hook from plugin cache
从插件缓存中复制钩子文件
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/<hook-name>.json ~/.opencode/hooks/
Then restart your agent to load the hook.cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/<hook-name>.json ~/.opencode/hooks/
然后重启Agent以加载钩子。Hook Details
钩子详情
protect-env-files (Recommended)
protect-env-files(推荐)
Security hook - Prevents accidental edits to environment files containing secrets.
- Blocks: ,
.env,.env.local,.env.production.env.staging - Prompts for confirmation if edit attempted
- No performance impact
安全防护钩子 - 防止意外编辑包含敏感信息的环境配置文件。
- 阻止编辑的文件:,
.env,.env.local,.env.production.env.staging - 当尝试编辑时会提示确认
- 无性能影响
uncommitted-reminder
uncommitted-reminder
Shows git status when Claude finishes responding if there are uncommitted changes.
- Helps prevent forgotten commits
- Exit code 2 feeds back to Claude
当Claude结束响应时,若存在未提交的变更则显示git状态。
- 帮助避免遗忘提交变更
- 返回退出码2给Claude
auto-git-add
auto-git-add
Automatically runs after Write/Edit/MultiEdit operations.
git add -A- Only stages, never commits
- 5 second timeout
在执行Write/Edit/MultiEdit操作后自动运行。
git add -A- 仅暂存文件,不会自动提交
- 超时时间为5秒
time-dir-context
time-dir-context
Adds context line to every prompt: timestamp, working directory, git branch.
- Example:
Context: 2025-01-24 14:32:15 | /Users/you/project | Branch: main
在每个提示中添加上下文信息行:时间戳、工作目录、git分支。
- 示例:
Context: 2025-01-24 14:32:15 | /Users/you/project | Branch: main
lint-on-save
lint-on-save
Runs after file edits.
bun lint:fix- Requires project with script in package.json
lint:fix - Requires and
bunjq - Works with statusline for lint count display
文件编辑后运行。
bun lint:fix- 要求项目的package.json中包含脚本
lint:fix - 需要安装和
bunjq - 可配合状态栏显示代码检查结果数量
lint-on-start
lint-on-start
Runs linting when session starts.
- Same requirements as lint-on-save
会话启动时运行代码检查。
- 要求与lint-on-save相同
auto-test-on-save
auto-test-on-save
Runs tests after file edits.
- Can be slow on large test suites
- Consider project-specific setup
文件编辑后自动运行测试。
- 在大型测试套件中运行可能较慢
- 建议根据项目进行特定配置
protect-shadcn-components
protect-shadcn-components
Prevents edits to shadcn/ui component files.
- Only relevant for projects using shadcn/ui
防止编辑shadcn/ui组件文件。
- 仅适用于使用shadcn/ui的项目
Installing This Skill
安装本技能
bash
bunx skills add b-open-io/bopen-tools --skill hook-managerbash
bunx skills add b-open-io/bopen-tools --skill hook-managerUninstalling a Hook
卸载钩子
Claude Code:
bash
rm ~/.claude/hooks/<hook-name>.jsonOpencode:
bash
rm ~/.opencode/hooks/<hook-name>.jsonRestart your agent.
Claude Code:
bash
rm ~/.claude/hooks/<hook-name>.jsonOpencode:
bash
rm ~/.opencode/hooks/<hook-name>.json重启Agent。
Listing Installed Hooks
列出已安装钩子
Claude Code:
bash
ls ~/.claude/hooks/Opencode:
bash
ls ~/.opencode/hooks/Claude Code:
bash
ls ~/.claude/hooks/Opencode:
bash
ls ~/.opencode/hooks/Quick Install Commands
快速安装命令
Claude Code
Claude Code
bash
undefinedbash
undefinedSecurity (recommended)
安全防护(推荐)
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/protect-env-files.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/protect-env-files.json ~/.claude/hooks/
Workflow helpers
工作流辅助工具
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/uncommitted-reminder.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/auto-git-add.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/uncommitted-reminder.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/auto-git-add.json ~/.claude/hooks/
Context enrichment
上下文信息增强
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/time-dir-context.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/time-dir-context.json ~/.claude/hooks/
Development automation
开发流程自动化
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-save.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-start.json ~/.claude/hooks/
undefinedcp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-save.json ~/.claude/hooks/
cp ~/.claude/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-start.json ~/.claude/hooks/
undefinedOpencode
Opencode
bash
undefinedbash
undefinedSecurity (recommended)
安全防护(推荐)
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/protect-env-files.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/protect-env-files.json ~/.opencode/hooks/
Workflow helpers
工作流辅助工具
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/uncommitted-reminder.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/auto-git-add.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/uncommitted-reminder.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/auto-git-add.json ~/.opencode/hooks/
Context enrichment
上下文信息增强
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/time-dir-context.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/time-dir-context.json ~/.opencode/hooks/
Development automation
开发流程自动化
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-save.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-start.json ~/.opencode/hooks/
undefinedcp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-save.json ~/.opencode/hooks/
cp ~/.opencode/plugins/cache/bopen-tools/user/.claude/hooks/lint-on-start.json ~/.opencode/hooks/
undefinedVerifying Installation
验证安装
After installing and restarting your agent:
bash
claude --debugLook for hook registration messages in the debug output.
安装并重启Agent后:
bash
claude --debug在调试输出中查找钩子注册信息。