groove-admin-claude-hooks

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
<!-- groove:managed — do not edit; changes will be overwritten by groove update -->
<!-- groove:managed — 请勿编辑;修改内容会被groove更新覆盖 -->

groove-admin-claude-hooks

groove-admin-claude-hooks

Install groove's Claude Code native shell hooks. These run outside the model — deterministic, unconditional — and complement groove's advisory markdown hooks (
.groove/hooks/start.md
,
end.md
).
Use
--disable <hook>
to remove a specific hook. Use
--list
to show current status.
安装groove的Claude Code原生shell钩子。这些钩子在模型之外运行——具备确定性、无条件执行的特性——是groove的建议式markdown钩子(
.groove/hooks/start.md
end.md
)的补充。
使用
--disable <hook>
参数移除指定钩子,使用
--list
参数展示当前状态。

Outcome

实现效果

Selected hooks are registered in
.claude/settings.json
and shell scripts are written to
.groove/hooks/claude/
. Hooks fire automatically on Claude Code lifecycle events without any model involvement.
选中的钩子会被注册到
.claude/settings.json
中,对应的shell脚本会写入
.groove/hooks/claude/
目录。钩子会在Claude Code的生命周期事件触发时自动执行,无需模型参与。

Available hooks

可用钩子

NameEventMatcherWhat it does
daily-end-reminder
Stop
If hour is 16–21 local time and
.groove/index.md
exists, prints a reminder to run
/groove-daily-end
git-activity-buffer
PostToolUse
Bash
If the Bash command contains
git commit
, appends a timestamped line to
.groove/.cache/git-activity-buffer.txt
block-managed-paths
PreToolUse
Write
,
Edit
If
file_path
starts with
.agents/skills/groove
or
skills/groove
, exits non-zero to block the write with an explanatory message
名称触发事件匹配器功能
daily-end-reminder
Stop
如果本地时间为16-21点且
.groove/index.md
存在,打印提醒告知用户运行
/groove-daily-end
git-activity-buffer
PostToolUse
Bash
如果Bash命令包含
git commit
,向
.groove/.cache/git-activity-buffer.txt
追加一行带时间戳的记录
block-managed-paths
PreToolUse
Write
Edit
如果
file_path
.agents/skills/groove
skills/groove
开头,返回非零退出码拦截写入操作并输出说明信息

Steps

操作步骤

--list

--list

Read
.claude/settings.json
if it exists. Report which groove hooks are registered and which scripts exist in
.groove/hooks/claude/
. Exit.
.claude/settings.json
存在则读取该文件,上报已注册的groove钩子以及
.groove/hooks/claude/
目录下存在的脚本,随后退出。

--disable <hook>

--disable <hook>

Remove the named hook's entry from
.claude/settings.json
(leave the script in place). Report removed / not found. Exit.
.claude/settings.json
中移除指定名称的钩子条目(保留对应脚本文件),上报移除结果/未找到对应钩子,随后退出。

Default (install)

默认操作(安装)

  1. Ask which hooks to enable (default: all three):
    Which hooks to install? (all / comma-separated: daily-end-reminder, git-activity-buffer, block-managed-paths)
    Press enter for all.
  2. Read
    .claude/settings.json
    if it exists; parse as JSON (default
    {}
    ). Never discard existing non-groove entries.
  3. Create
    .groove/hooks/claude/
    directory if absent. Make each script executable (
    chmod +x
    ).
  4. For each selected hook: write the shell script and merge the hook entry into
    .claude/settings.json
    .
  5. Write
    .claude/settings.json
    with the merged result.
  6. Report summary:
    ✓ daily-end-reminder  — Stop hook → .groove/hooks/claude/daily-end-reminder.sh
    ✓ git-activity-buffer — PostToolUse/Bash hook → .groove/hooks/claude/git-activity-buffer.sh
    ✓ block-managed-paths — PreToolUse/Write+Edit hook → .groove/hooks/claude/block-managed-paths.sh
    ✓ .claude/settings.json updated
  1. 询问用户需要启用哪些钩子(默认:全部三个):
    Which hooks to install? (all / comma-separated: daily-end-reminder, git-activity-buffer, block-managed-paths)
    Press enter for all.
  2. .claude/settings.json
    存在则读取该文件,解析为JSON格式(默认值为
    {}
    )。绝对不要删除已存在的非groove相关条目。
  3. 如果
    .groove/hooks/claude/
    目录不存在则创建该目录,将每个脚本设置为可执行权限(
    chmod +x
    )。
  4. 针对每个选中的钩子:写入对应的shell脚本,并将钩子条目合并到
    .claude/settings.json
    中。
  5. 将合并后的结果写入
    .claude/settings.json
  6. 上报安装总结:
    ✓ daily-end-reminder  — Stop hook → .groove/hooks/claude/daily-end-reminder.sh
    ✓ git-activity-buffer — PostToolUse/Bash hook → .groove/hooks/claude/git-activity-buffer.sh
    ✓ block-managed-paths — PreToolUse/Write+Edit hook → .groove/hooks/claude/block-managed-paths.sh
    ✓ .claude/settings.json updated

Shell script templates

Shell脚本模板

Write these verbatim to
.groove/hooks/claude/
. Never overwrite an existing script without showing a diff and confirming.
将以下脚本原封不动写入
.groove/hooks/claude/
目录。在未展示差异并获得用户确认的情况下,绝对不要覆盖已存在的脚本。

daily-end-reminder.sh

daily-end-reminder.sh

bash
#!/usr/bin/env bash
bash
#!/usr/bin/env bash

groove: Stop hook — remind about /groove-daily-end during work hours

groove: Stop hook — remind about /groove-daily-end during work hours

hour=$(date +%H) if [ -f ".groove/index.md" ] && [ "$hour" -ge 16 ] && [ "$hour" -le 21 ]; then echo "groove: end of work hours — consider running /groove-daily-end" fi
undefined
hour=$(date +%H) if [ -f ".groove/index.md" ] && [ "$hour" -ge 16 ] && [ "$hour" -le 21 ]; then echo "groove: end of work hours — consider running /groove-daily-end" fi
undefined

git-activity-buffer.sh

git-activity-buffer.sh

bash
#!/usr/bin/env bash
bash
#!/usr/bin/env bash

groove: PostToolUse/Bash hook — buffer git commits for memory log

groove: PostToolUse/Bash hook — buffer git commits for memory log

input=$(cat) command=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('command',''))" 2>/dev/null) if echo "$command" | grep -q "git commit"; then msg=$(echo "$command" | grep -oP '(?<=-m ")[^"]+' | head -1) mkdir -p .groove/.cache echo "$(date '+%Y-%m-%d %H:%M') | ${msg:-<no message>}" >> .groove/.cache/git-activity-buffer.txt fi
undefined
input=$(cat) command=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('command',''))" 2>/dev/null) if echo "$command" | grep -q "git commit"; then msg=$(echo "$command" | grep -oP '(?<=-m ")[^"]+' | head -1) mkdir -p .groove/.cache echo "$(date '+%Y-%m-%d %H:%M') | ${msg:-<no message>}" >> .groove/.cache/git-activity-buffer.txt fi
undefined

block-managed-paths.sh

block-managed-paths.sh

bash
#!/usr/bin/env bash
bash
#!/usr/bin/env bash

groove: PreToolUse/Write+Edit hook — block edits to managed groove paths

groove: PreToolUse/Write+Edit hook — block edits to managed groove paths

input=$(cat) path=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('file_path',''))" 2>/dev/null) if echo "$path" | grep -qE '^(.agents/skills/groove|skills/groove)'; then echo "groove: blocked — '$path' is managed by groove update. Edit under skills/ and rsync to .agents/skills/." >&2 exit 1 fi
undefined
input=$(cat) path=$(echo "$input" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('tool_input',{}).get('file_path',''))" 2>/dev/null) if echo "$path" | grep -qE '^(.agents/skills/groove|skills/groove)'; then echo "groove: blocked — '$path' is managed by groove update. Edit under skills/ and rsync to .agents/skills/." >&2 exit 1 fi
undefined

.claude/settings.json
entries

.claude/settings.json
条目

Merge these into the
hooks
key. Preserve all other keys.
json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/daily-end-reminder.sh" }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/git-activity-buffer.sh" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Write",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/block-managed-paths.sh" }
        ]
      },
      {
        "matcher": "Edit",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/block-managed-paths.sh" }
        ]
      }
    ]
  }
}
When merging: if a
hooks
key already exists, append groove entries to the relevant event arrays. Do not create duplicates — check if a groove command entry already exists before appending.
将以下内容合并到
hooks
键下,保留所有其他键的内容。
json
{
  "hooks": {
    "Stop": [
      {
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/daily-end-reminder.sh" }
        ]
      }
    ],
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/git-activity-buffer.sh" }
        ]
      }
    ],
    "PreToolUse": [
      {
        "matcher": "Write",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/block-managed-paths.sh" }
        ]
      },
      {
        "matcher": "Edit",
        "hooks": [
          { "type": "command", "command": "bash .groove/hooks/claude/block-managed-paths.sh" }
        ]
      }
    ]
  }
}
合并规则:如果
hooks
键已存在,将groove相关条目追加到对应事件的数组中。不要创建重复条目——追加前先检查groove命令条目是否已经存在。

Constraints

约束条件

  • Never overwrite non-groove entries in
    .claude/settings.json
  • Never overwrite an existing script without diff + confirmation
  • Scripts use
    python3
    to parse JSON stdin — if python3 is absent, skip that hook and warn
  • block-managed-paths
    is aggressive: if it causes false positives the user can disable it with
    --disable block-managed-paths
  • After install: remind the user that hooks take effect on the next Claude Code session restart
  • .groove/hooks/claude/
    follows the
    git.hooks
    git strategy from
    .groove/index.md
  • 绝对不要覆盖
    .claude/settings.json
    中的非groove相关条目
  • 未展示差异并获得用户确认的情况下,绝对不要覆盖已存在的脚本
  • 脚本使用
    python3
    解析标准输入的JSON——如果没有安装python3,跳过该钩子并发出警告
  • block-managed-paths
    的拦截逻辑较为严格:如果出现误拦截,用户可以通过
    --disable block-managed-paths
    参数禁用该钩子
  • 安装完成后:提醒用户钩子需要重启下一次Claude Code会话才会生效
  • .groove/hooks/claude/
    目录遵循
    .groove/index.md
    中定义的
    git.hooks
    git策略