Published on

Claude Code Hooks升级 — 执行时间测量·感知努力级别·CI自动代码审查

2026年5月,Claude Code的Hook系统新增了三项重要功能。


PostToolUse输出替换 — 覆盖任意工具

此前仅限MCP工具,现在所有工具均可使用。

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "python3 sanitize_output.py",
            "hookSpecificOutput": { "updatedToolOutput": true }
          }
        ]
      }
    ]
  }
}

effort.level — 感知努力级别

  • Hook输入JSON:effort.level字段
  • 环境变量:$CLAUDE_EFFORT
if [ "$CLAUDE_EFFORT" = "high" ] || [ "$CLAUDE_EFFORT" = "xhigh" ]; then
  npm run test:full
else
  npm run test:smoke
fi

duration_ms — 精确测量执行时间

if [ "$DURATION" -gt 5000 ]; then
  echo "[SLOW] $(date): ${DURATION}ms" >> slow-tools.log
fi

claude ultrareview — CI自动代码审查

claude ultrareview src/ --json
claude ultrareview --diff origin/main...HEAD

来源

Claude Code Hooks升级 — 执行时间测量·感知努力级别·CI自动代码审查 | MINSSAM.COM