본문으로 건너뛰기
cccskills
무료GitHub에 공개

crush-hooks

Create, configure, and troubleshoot Crush hooks, commands that run before tool execution. Use them to block or approve calls, rewrite tool input, or add context for the agent, with guidance on configuration and troubleshooting.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

원문원문 설명 보기

Use when the user wants to add, write, debug, or configure a Crush hook — gating or blocking tool calls, approving or rewriting tool input before execution, injecting context into tool results, or troubleshooting hook behavior in crush.json.

설치 방법 보기

이럴 때 유용합니다

  • Blocking destructive shell commands
  • Automatically approving read-only tools
  • Adding editing reminders for the agent
  • Rewriting tool input before execution
  • Troubleshooting hooks configured in crush.json

포함된 파일(1)

  • SKILL.md7.1 KB

SKILL.md(원문)

설치하기 전에 에이전트에게 전달되는 지시 내용을 확인할 수 있습니다.

Crush Hooks

Hooks are user-defined commands in crush.json that fire at specific points during execution, giving deterministic control over tool behavior. They run before permission checks and only on the top-level agent's tool calls — sub-agent calls (task tool, agentic_fetch, etc.) are not intercepted, though the sub-agent tool call itself is.

For the full reference, see docs/hooks/README.md. This skill covers what you need to author correct hooks.

Supported Events

Only PreToolUse is currently supported. Event names are case-insensitive and accept snake_case (PreToolUse, pretooluse, pre_tool_use all work).

Configuration

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "^bash$",              // regex against tool name (optional; omit to match all)
        "command": "./hooks/my-hook.sh",   // required: shell command to run
        "timeout": 10                     // optional: seconds, default 30
      }
    ]
  }
}

Project-level hooks take precedence over global. Matching hooks are deduped by command, run in parallel, and aggregated in config order (not finish order).

Language

command is a shell command, so hooks can be written in any language by invoking the interpreter: node ./hooks/h.js, python3 ./hooks/h.py, ./hooks/h.sh, inline echo '…', etc. The rest of this skill shows bash, but the input/output contract is identical regardless of language.

Input

Environment variables:

VariableDescription
CRUSH_EVENTEvent name (e.g. PreToolUse)
CRUSH_TOOL_NAMETool being called (e.g. bash)
CRUSH_SESSION_IDCurrent session ID
CRUSH_CWDWorking directory
CRUSH_PROJECT_DIRProject root directory
CRUSH_TOOL_INPUT_COMMANDFor bash calls: the shell command
CRUSH_TOOL_INPUT_FILE_PATHFor file tools: the target file path

JSON on stdin:

{
  "event": "PreToolUse",
  "session_id": "313909e",
  "cwd": "/home/user/project",
  "tool_name": "bash",
  "tool_input": {"command": "rm -rf /"}
}

Output

Communicate back via exit code (+ stderr) or JSON on stdout.

Exit CodeMeaning
0Success. Stdout is parsed as the JSON envelope below.
2Block this tool call. Stderr becomes the deny reason.
49Halt the whole turn. Stderr becomes the halt reason.
OtherNon-blocking error. Logged and ignored; tool call proceeds.

Exit 2 blocks one tool call (agent sees the reason and can try again); exit 49 ends the whole turn (user takes over). Default to deny — reach for halt only when letting the agent retry is itself the problem (e.g. secrets detected, policy violation).

JSON envelope (exit 0):

{
  "version": 1,
  "decision": "allow",
  "halt": false,
  "reason": "...",
  "context": "Extra info for the model",
  "updated_input": {"command": "rewritten"}
}
  • decision: "allow", "deny", or omit. "allow" is affirmative pre-approval — it bypasses the permission prompt entirely. Omit it (or null) when you only want to inject context or rewrite input without also auto-approving the call.
  • halt: true: ends the turn (same as exit 49).
  • reason: shown to the model on deny; to model and user on halt.
  • context: string or array of strings. Appended to what the model sees. Empty entries are dropped.
  • updated_input: shallow-merge patch against tool_input, not a replacement. Keys you include overwrite; keys you don't are preserved. Nested objects are replaced wholesale, not deep-merged. Ignored on deny/halt.

Aggregation (Multiple Hooks)

Composed in config order:

  • deny > allow > no opinion. First deny decides; subsequent allows don't override.
  • halt is sticky: any hook halting ends the turn.
  • reason and context concatenate in config order (newline-joined).
  • updated_input patches shallow-merge sequentially; later patches win on colliding keys.

Canonical Examples

Block destructive commands

#!/usr/bin/env bash
set -euo pipefail

if echo "$CRUSH_TOOL_INPUT_COMMAND" | grep -qE 'rm\s+-(rf|fr)\s+/'; then
  echo "Refusing to run rm -rf against root" >&2
  exit 2
fi

Config: {"matcher": "^bash$", "command": "./hooks/no-rm-rf.sh"}

Auto-approve read-only tools (inline, no script)

{"matcher": "^(view|ls|grep|glob)$", "command": "echo '{\"decision\":\"allow\"}'"}

Every view/ls/grep/glob call now runs without prompting.

Inject context without auto-approving

Emit only context — omit decision so the normal permission flow still runs.

#!/usr/bin/env bash
set -euo pipefail

if [[ "$CRUSH_TOOL_INPUT_FILE_PATH" == *.go ]]; then
  echo '{"context": "Remember: run gofumpt after editing Go files."}'
else
  echo '{}'
fi

Config: {"matcher": "^(edit|write|multiedit)$", "command": "./hooks/go-context.sh"}

Rewrite tool input (shallow merge)

#!/usr/bin/env bash
set -euo pipefail

read -r input
rewritten=$(echo "$input" | jq -r '.tool_input.command' | some-rewriter)

cat <<EOF
{
  "context": "Rewrote command",
  "updated_input": {"command": "$rewritten"}
}
EOF

If the original call was {"command": "npm test", "timeout": 60000}, the tool runs with {"command": "<rewritten>", "timeout": 60000} — timeout is preserved.

Authoring Checklist

  1. Add #!/usr/bin/env bash and set -euo pipefail (for shell scripts).
  2. chmod +x the script.
  3. Add the entry under hooks.PreToolUse in crush.json with the right matcher.
  4. Decide intent: inject context (omit decision), auto-approve ("allow"), block (exit 2), or halt (exit 49).
  5. If rewriting input, remember updated_input is a shallow merge — only include the keys you want to change.

Debugging

  • Timeouts kill the hook silently and the tool call proceeds. Bump timeout if needed.
  • Non-zero exit codes other than 2/49 are logged but don't block — check Crush logs.
  • Use echo "debug info" >&2 for logging without corrupting stdout JSON.
  • matcher is a regex against the tool name. Use ^bash$ (not bash) if you don't also want to match mcp_something_bash.

Claude Code Compatibility

Crush also accepts Claude Code's hookSpecificOutput envelope. One intentional divergence: Crush treats updated_input as shallow-merge, Claude Code replaces. Existing Claude Code hooks work without modification for the matcher/decision parts; revisit any that relied on updatedInput fully replacing tool input.

리뷰

아직 리뷰가 없습니다. 사용해 본 소감을 남겨 주세요.

댓글

로그인 없이 쓸 수 있습니다. 사용 후기, 질문, 작동하지 않은 환경 등을 편하게 남겨 주세요.

아직 댓글이 없습니다. 첫 댓글을 남겨 보세요.

보내면 바로 공개됩니다. 이메일 주소나 전화번호 같은 개인 정보는 쓰지 마세요. URL은 2개까지입니다.

0 / 1,000자

이 양식은 reCAPTCHA로 보호되며 Google 개인정보처리방침 및 서비스 약관이 적용됩니다.

같은 저장소의 스킬

Add or edit skills bundled with Crush, following guidance on file placement, required metadata, compile-time embedding, and discovery tests. It also explains how built-in skills are loaded and how user skills override them.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Adding a skill bundled with Crush
  • Editing an existing built-in skill
  • Understanding skill discovery and overrides
charmbracelet/crush2.9만2026년 10월 18일 업데이트

Configure Crush with Bash or JSON files to choose AI providers and models, connect external tools, set permissions, and adjust behavior. Understand how project and global settings combine when customizing your working environment.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Set up AI providers and model selections
  • Connect MCP servers and language servers
  • Configure tool permissions and execution hooks
charmbracelet/crush2.9만2026년 10월 18일 업데이트

jq

무료

Extract fields, filter records, and reshape JSON from API responses, configuration files, or logs using Crush’s built-in jq. Get help writing and debugging transformations, constructing new JSON, and formatting output for other commands.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Extract selected fields from API responses
  • Filter JSON arrays by conditions
  • Reshape configuration data or construct JSON
charmbracelet/crush2.9만2026년 10월 18일 업데이트

Add or modify commands handled inside Crush's embedded shell before they reach the operating system. The guidance covers command routing, input and output streams, exit codes, and cancellation so commands work with pipes, redirection, and hook timeouts.

한국어 요약은 준비 중입니다. 영어 요약을 표시하고 있습니다.

  • Adding a command to Crush's embedded shell
  • Modifying an existing built-in command
  • Supporting pipes and output redirection
charmbracelet/crush2.9만2026년 10월 18일 업데이트

charmbracelet의 스킬 모두 보기

이 스킬의 문제 신고