Skip to content
Development
Hook

Hooks

What myclaude runs automatically, and when. A hook is a command Claude Code fires at a fixed moment, without you asking for it.

From plugin
myclaude
2.7k11 skills23 agents13 commands2 hooks
Install
> /plugin marketplace add cexll/myclaude

Ships with myclaude. Installing the plugin gets these hooks.

What fires, and when

PreToolUse

  • MatchesBashpython3 ${CLAUDE_PLUGIN_ROOT}/pre-bash.py "$CLAUDE_TOOL_INPUT"python3 ${CLAUDE_PLUGIN_ROOT}/inject-spec.py

UserPromptSubmit

Fires before Claude sees each prompt you send. A plugin can use it to inject context, so the same instruction reaches the model every turn instead of only at session start.

  • python3 ${CLAUDE_PLUGIN_ROOT}/log-prompt.py
Read hooks/hooks.json

In the plugin's words

How myclaude describes its own hook set.

ClaudeKit global hooks: dangerous command blocker, spec injection, prompt logging, session review

Where it lives

  • hooks/inject-spec.pyRunsGitHub
    Read the script
    #!/usr/bin/env python3
    """
    Global Spec Injection Hook (DEPRECATED).
    
    Spec injection is now handled internally by codeagent-wrapper via the
    per-task `skills:` field in parallel config and the `--skills` CLI flag.
    
    This hook is kept as a no-op for backward compatibility.
    """
    
    import sys
    
    sys.exit(0)
    
  • hooks/log-prompt.pyRunsGitHub
    Read the script
    #!/usr/bin/env python3
    """
    Log Prompt Hook - Record user prompts to session-specific log files.
    Used for review on Stop.
    Uses session-isolated logs to handle concurrency.
    """
    
    import json
    import os
    import sys
    from datetime import datetime
    from pathlib import Path
    
    
    def get_session_id() -> str:
        """Get unique session identifier."""
        return os.environ.get("CLAUDE_CODE_SSE_PORT", "default")
    
    
    def write_log(prompt: str) -> None:
        """Write prompt to session log file."""
        log_dir = Path(".claude/state")
        session_id = get_session_id()
        log_file = log_dir / f"session-{session_id}.log"
    
        log_dir.mkdir(parents=True, exist_ok=True)
    
        timestamp = datetime.now().isoformat()
        entry = f"[{timestamp}] {prompt[:500]}\n"
    
        with open(log_file, "a", encoding="utf-8") as f:
            f.write(entry)
    
    
    def main():
        input_data = ""
        if not sys.stdin.isatty():
            try:
                input_data = sys.stdin.read()
            except Exception:
                pass
    
        prompt = ""
        try:
            data = json.loads(input_data)
            prompt = data.get("prompt", "")
        except json.JSONDecodeError:
            prompt = input_data.strip()
    
        if prompt:
            write_log(prompt)
    
    
    if __name__ == "__main__":
        main()
    
  • hooks/pre-bash.pyRunsGitHub
    Read the script
    #!/usr/bin/env python3
    """
    Pre-Bash Hook - Block dangerous commands before execution.
    """
    
    import sys
    
    DANGEROUS_PATTERNS = [
        'rm -rf /',
        'rm -rf ~',
        'dd if=',
        ':(){:|:&};:',
        'mkfs.',
        '> /dev/sd',
    ]
    
    
    def main():
        command = sys.argv[1] if len(sys.argv) > 1 else ''
    
        for pattern in DANGEROUS_PATTERNS:
            if pattern in command:
                print(f"[CWF] BLOCKED: Dangerous command detected: {pattern}", file=sys.stderr)
                sys.exit(1)
    
        sys.exit(0)
    
    
    if __name__ == "__main__":
        main()
    

Read the script before you install anything that runs on your machine. This is the one part of a plugin that acts without being asked.

Ships withmyclaude

AI-powered development automation with multi-backend execution (Codex/Claude/Gemini/OpenCode)

Get the whole plugin