팟캐스트로 돌아가기Claude
Claude Code 101
Hooks in Claude Code
Hooks let you run commands at different points in Claude code's life cycle.
hooks를 사용하면 Claude Code 생명주기의 다양한 시점에 명령을 실행할 수 있습니다.
The key difference between hooks and everything else we covered is that hooks are deterministic.
hooks와 지금까지 다룬 다른 기능의 핵심 차이점은 hooks가 결정론적이라는 것입니다.
They always run.
항상 실행됩니다.
So, put it this way.
이렇게 설명해 보겠습니다.
You can tell Claude in your claude.md file to run prettier after every file edit and most of the time it will do that, but sometimes it won't.
claude.md 파일에서 Claude에게 파일 편집 후마다 prettier를 실행하라고 지시할 수 있으며, 대부분의 경우 그렇게 하지만 가끔은 그렇지 않을 수 있습니다.
It's not perfect.
완벽하지 않습니다.
But a hook makes it happen every single time with no exceptions.
하지만 hook을 사용하면 예외 없이 매번 반드시 실행됩니다.
Common use cases could include auto formatting after file edits, logging all executed commands for compliance, blocking dangerous operations like modifying production files, and sending yourself notifications when Claude finishes a task.
일반적인 사용 사례로는 파일 편집 후 자동 포맷팅, 컴플라이언스를 위한 모든 실행 명령 로깅, 프로덕션 파일 수정 같은 위험한 작업 차단, Claude가 작업을 완료했을 때 알림 전송 등이 있습니다.
Hooks are configured in your settings.json file.
hooks는 settings.json 파일에서 구성합니다.
You pick an event, optionally set a matcher for which tool it applies to, and provide a command to run.
이벤트를 선택하고, 선택적으로 적용할 도구의 매처를 설정하고, 실행할 명령을 제공합니다.
User prompts submit runs when you submit a prompt before Claude processes it.
UserPromptSubmit은 프롬프트를 제출하면 Claude가 처리하기 전에 실행됩니다.
Pre-tool use which runs before a tool call, post-tool use runs after a tool call completes.
PreToolUse는 도구 호출 전에 실행되고, PostToolUse는 도구 호출이 완료된 후에 실행됩니다.
Notification runs when Claude sends a notification, and stop runs when Claude finishes responding.
Notification은 Claude가 알림을 보낼 때 실행되고, Stop은 Claude가 응답을 완료할 때 실행됩니다.
The most common hook.
가장 일반적인 hook입니다.
Auto formatting after edits.
편집 후 자동 포맷팅.
You set a post-tool use hook with a matcher of edit or multi-edit, right?
edit 또는 multi-edit 매처로 PostToolUse hook을 설정하면 되죠?
So, it fires whenever Claude modifies a file.
그러면 Claude가 파일을 수정할 때마다 실행됩니다.
The command checks the file extension and runs the appropriate formatter.
명령은 파일 확장자를 확인하고 적절한 포맷터를 실행합니다.
This could be prettier for TypeScript, go format for go, rough for Python, whatever your project uses.
TypeScript에는 prettier, Go에는 go format, Python에는 ruff 등 프로젝트에서 사용하는 도구를 사용할 수 있습니다.
Pre-tool use hooks can block tool calls before they execute.
PreToolUse hooks는 도구 호출이 실행되기 전에 차단할 수 있습니다.
So, your hook receives the tool name and input as JSON on stdin.
hook은 stdin을 통해 JSON 형식으로 도구 이름과 입력을 받습니다.
If it exits with code two, the action is blocked and the STD error message gets fed back to Claude's feedback so Claude knows why it was blocked and can adjust.
종료 코드 2로 종료되면 작업이 차단되고, stderr 메시지가 Claude에 피드백되어 Claude가 차단 이유를 알고 조정할 수 있습니다.
Exit code zero means proceed.
종료 코드 0은 계속 진행을 의미합니다.
Exit code two means block.
종료 코드 2는 차단을 의미합니다.
This is how you enforce hard rules.
이것이 하드 규칙을 강제하는 방법입니다.
Block writes to a production config directory, block bash commands that contain rm-rf, block commits to main, whatever your team needs to be guaranteed, not suggested.
프로덕션 설정 디렉토리에 대한 쓰기 차단, rm-rf가 포함된 bash 명령 차단, main으로의 커밋 차단 등 팀이 보장해야 하는 것을 단순한 제안이 아닌 필수 사항으로 만듭니다.
Hooks configured in .Claude/settings.json are project level and can be checked into your repo. This means that your entire team gets the same hooks automatically.
.Claude/settings.json에 구성된 hooks는 프로젝트 수준이며 저장소에 커밋할 수 있습니다. 이는 팀 전체가 동일한 hooks를 자동으로 갖게 된다는 것을 의미합니다.
Use the Claude project dir environment variable in your commands to reference scripts stored in your project so they work regardless of Claude's current working directory.
명령에서 Claude 프로젝트 디렉토리 환경 변수를 사용하여 프로젝트에 저장된 스크립트를 참조하면 Claude의 현재 작업 디렉토리에 관계없이 작동합니다.
[music]
[music]
Hooks gives you deterministic control over Claude code's behavior.
hooks는 Claude Code 동작에 대한 결정론적 제어를 제공합니다.
[music]
[music]
Use post-tool-use for auto-formatting and logging. Use pre-tool-use to block dangerous operations. Configure them in the /hooks or in settings.
자동 포맷팅과 로깅에는 PostToolUse를 사용하고, 위험한 작업 차단에는 PreToolUse를 사용합니다. /hooks 또는 settings에서 구성하세요.
json
json
[music]
[music]
and check them into your repository so your team gets them, too.
그리고 저장소에 커밋하여 팀도 사용할 수 있도록 하세요.
If something needs to happen every time without fail, don't put it in a prompt.
무언가가 매번 예외 없이 실행되어야 한다면, 프롬프트에 넣지 마세요.
Put it in a hook.
hook에 넣으세요.
[music]
[music]