Skip to content
Apothem
उदाहरण

न्यूनतम हुक

न्यूनतम Apothem हुक उदाहरण — हर फ़ाइल लेखन पर एक जाँच सक्रिय करें।

यह उदाहरण संभव सबसे छोटा Apothem हुक दिखाता है: एक PreToolUse हुक जो हर Write टूल कॉल से पहले सक्रिय होता है और लक्ष्य पथ को लॉग करता है।

हुक स्क्रिप्ट

# src/apothem/hooks/log_writes.py
import json, sys

data = json.load(sys.stdin)
path = data.get("tool_input", {}).get("file_path", "unknown")
print(f"[apothem] Writing to: {path}", file=sys.stderr)
sys.exit(0)  # always exit 0; block with the deny envelope below

settings.json में पंजीकरण

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Write",
        "hooks": [
          {
            "type": "command",
            "command": "python src/apothem/hooks/log_writes.py"
          }
        ]
      }
    ]
  }
}

हुक का परीक्षण

Claude Code में कोई भी फ़ाइल लेखन करें और हुक ट्रेस पैनल में stderr आउटपुट देखें।

लेखन को अवरुद्ध करना

लेखन को ब्लॉक करने के लिए, deny एनवेलप को stdout पर प्रिंट करें और फिर भी 0 के साथ बाहर निकलें, जैसा Apothem के अपने हुक करते हैं:

print(json.dumps({"hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "deny", "permissionDecisionReason": "blocked by log_writes"}}))
sys.exit(0)

On this page