Podcasts पर वापस जाएंClaude
Claude Code 101
Claude Code में Hooks
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 निर्धारक (deterministic) हैं।
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 को अपनी claude.md फ़ाइल में बता सकते हैं कि हर फ़ाइल एडिट के बाद 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.
आप एक इवेंट चुनते हैं, वैकल्पिक रूप से यह तय करने के लिए एक matcher सेट करते हैं कि यह किस टूल पर लागू होता है, और चलाने के लिए एक कमांड प्रदान करते हैं।
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 के matcher के साथ एक 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]