Skip to main content

HOOKS_JSON

Constant HOOKS_JSON 

Source
pub const HOOKS_JSON: &str = r#"{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "input=$(cat); cmd=$(echo \"$input\" | jq -r '.tool_input.command // \"\"' 2>/dev/null); if echo \"$cmd\" | grep -qE '\\-\\-help| -h$| -h '; then echo 'Use: oo help <cmd> for a token-efficient command reference' >&2; exit 2; fi; echo \"$input\""
          }
        ]
      }
    ]
  }
}
"#;
Expand description

Minimal Claude Code PreToolUse hooks configuration.

Intercepts --help/-h Bash calls so agents use oo help <cmd> instead.

Schema: hooks is an object keyed by event name; each event maps to an array of hook configs with matcher (string tool name) and hooks (array of commands). exit 2 in a Claude Code hook blocks the tool call and shows the message to Claude. Content filtering (--help/-h) is done inside the command script, not via a schema field, because Claude Code has no command_pattern key in this schema version.

Claude Code sends hook input as JSON on stdin (not via env vars). The script reads stdin with cat, extracts .tool_input.command with jq, checks for help flags, then either blocks (exit 2, message to stderr) or passes through (echo input, exit 0).