콘텐츠로 이동

03-실전

eesel과 claude-code-hooks-mastery 리포에서 가장 자주 등장하는 5가지.

{
"PostToolUse": [{
"matcher": "Edit|Write",
"hooks": [
{ "type": "command", "command": "pnpm lint --fix $CLAUDE_FILE_PATH || true" },
{ "type": "command", "command": "pnpm prettier --write $CLAUDE_FILE_PATH || true" }
]
}]
}
  • || true로 hook 자체가 실패해도 작업은 진행. 단, 중요한 게이트는 exit 2로 막는다.

2) 위험 명령 하드 차단 (PreToolUse, Bash)

섹션 제목: “2) 위험 명령 하드 차단 (PreToolUse, Bash)”

03장block-dangerous.sh를 그대로 사용. rm -rf /, ~, --force, curl|sh, fork bomb 패턴.

{
"Stop": [{
"matcher": "",
"hooks": [{ "type": "command", "command": ".claude/hooks/run-tests.sh" }]
}]
}
  • 모델 응답이 끝날 때마다 변경된 파일과 관련된 테스트만 돌린다 (11장 TDD).

4) 세션 시작 컨텍스트 주입 (SessionStart)

섹션 제목: “4) 세션 시작 컨텍스트 주입 (SessionStart)”
{
"SessionStart": [{
"matcher": "startup|resume",
"hooks": [{ "type": "command", "command": ".claude/hooks/session-context.sh" }]
}]
}
  • session-context.sh는 stdout으로 마크다운을 뱉는다. Claude Code가 그것을 컨텍스트에 prepend한다.
  • 흔한 내용: 최근 git 로그 5개, 열린 이슈, 어제 작업 요약.

eesel의 사례:

“You could use a ‘SessionStart’ hook to pull in the latest bug reports…”
의역: “SessionStart hook으로 최신 버그 리포트를 끌어올 수 있다.”

{
"Notification": [{
"matcher": "permission_prompt|idle_prompt",
"hooks": [{ "type": "command", "command": ".claude/hooks/notify-slack.sh" }]
}]
}
  • 긴 작업 중 사람 승인이 필요할 때 슬랙으로 ping. 자리를 비워도 안전.
  • hook 자체에 버그가 있으면 디버깅이 까다롭다. 항상 set -euo pipefail + 로그 파일.
  • 빌드/런 hook은 1초 내에 끝나지 않으면 작업 흐름을 망친다. 무거운 검증은 백그라운드(&) 또는 별도 큐.
  • hook 변경은 PR 리뷰. 잘못된 hook 한 줄이 팀 전체 작업을 멈춘다.