claude_code_hook.example•2.39 kB
#!/usr/bin/env python3
"""
Claude Code hook that intercepts "hey good job!" and forces TOOT success pattern capture.
This creates an automatic feedback loop for reinforcement learning.
"""
import sys
import json
import os
import logging
import traceback
# Setup logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def _read_hook_data():
"""Read and parse hook data from stdin."""
try:
hook_data = json.load(sys.stdin)
logger.info("Good job interceptor hook activated")
return hook_data
except json.JSONDecodeError:
logger.error(f"Failed to parse hook data: {traceback.format_exc()}")
print("❌ Failed to parse hook data", file=sys.stderr)
sys.exit(1)
def _show_toot_instructions():
"""Display TOOT success pattern capture instructions."""
logger.info("Displaying TOOT instructions for good job feedback")
print("🎉 **Good job detected!** Triggering TOOT success pattern capture...", file=sys.stderr)
print("", file=sys.stderr)
print("Please use `user_said_i_did_a_good_job()` with:", file=sys.stderr)
print("- name: Brief description of what was done well", file=sys.stderr)
print("- domain: Area of work (e.g., 'mcp_development', 'system_architecture')", file=sys.stderr)
print("- process: Specific type of work (e.g., 'writing_readme', 'debugging_hooks', 'creating_library')", file=sys.stderr)
print("- description: What specifically worked well", file=sys.stderr)
print("- filepaths_involved: List of files that were part of the success", file=sys.stderr)
print("- sequencing: Steps that led to success", file=sys.stderr)
print("", file=sys.stderr)
print("💡 This will help build your success pattern library for future reference!", file=sys.stderr)
def main():
"""Main hook execution."""
hook_data = _read_hook_data()
# Get the user prompt from the standard UserPromptSubmit format
user_prompt = hook_data.get("prompt", "").strip().lower()
logger.info(f"Checking prompt: '{user_prompt[:50]}...'")
if user_prompt.startswith("hey good job!"):
logger.info("Good job prompt detected, showing TOOT instructions")
_show_toot_instructions()
else:
logger.debug("Normal prompt, proceeding without intervention")
sys.exit(0)
if __name__ == "__main__":
main()