StealThis .dev

Claude Code Hooks Mastery (Python)

A community reference repo that teaches and ships ready-to-use Claude Code lifecycle hooks in Python for developers customizing agent behavior.

markdown
Targets: HTML

Code

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Claude Code Hooks Mastery (Python)</title>
<style>
  :root {
    --bg: #0b0f17;
    --surface: #141a26;
    --surface-2: #1b2233;
    --text: #e6edf6;
    --muted: #8b97a8;
    --accent: #6ea8fe;
    --border: rgba(255, 255, 255, 0.08);
    --radius: 16px;
  }

  * { box-sizing: border-box; }

  body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    line-height: 1.5;
  }

  .card {
    width: 100%;
    max-width: 640px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  }

  .eyebrow {
    display: inline-block;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--accent);
    background: rgba(110, 168, 254, 0.12);
    border: 1px solid rgba(110, 168, 254, 0.25);
    padding: 4px 10px;
    border-radius: 999px;
    margin-bottom: 14px;
  }

  h1 {
    margin: 0 0 6px;
    font-size: 26px;
    line-height: 1.2;
    letter-spacing: -0.01em;
  }

  .author {
    margin: 0 0 16px;
    font-size: 14px;
    color: var(--muted);
  }

  .desc {
    margin: 0 0 22px;
    font-size: 15px;
    color: var(--text);
  }

  .section-label {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    margin: 0 0 8px;
  }

  .access {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 22px;
  }

  pre {
    margin: 0;
    overflow-x: auto;
  }

  code {
    font-family: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
    font-size: 13px;
    color: #cdd9ec;
  }

  .pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 26px;
  }

  .pill {
    font-size: 12.5px;
    color: var(--text);
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 5px 12px;
    border-radius: 999px;
  }

  .cta {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 600;
    color: #0b0f17;
    background: var(--accent);
    text-decoration: none;
    padding: 12px 20px;
    border-radius: 10px;
    transition: background 0.15s ease, transform 0.15s ease;
  }

  .cta:hover { background: #8bbbff; }

  .cta:focus-visible {
    outline: 3px solid rgba(110, 168, 254, 0.55);
    outline-offset: 2px;
  }

  .cta svg { width: 16px; height: 16px; }
</style>
</head>
<body>
  <main class="card">
    <span class="eyebrow">Claude Code (community)</span>
    <h1>Claude Code Hooks Mastery (Python)</h1>
    <p class="author">by disler</p>

    <p class="desc">
      A community reference repository that teaches and ships ready-to-use Claude Code
      lifecycle hooks in Python — intercept tool calls, add guardrails, log activity, and
      shape agent behavior across the full hook lifecycle.
    </p>

    <p class="section-label">How to access</p>
    <div class="access">
      <pre><code>git clone https://github.com/disler/claude-code-hooks-mastery
cd claude-code-hooks-mastery</code></pre>
    </div>

    <p class="section-label">Compatible with</p>
    <div class="pills">
      <span class="pill">Claude Code</span>
      <span class="pill">Python</span>
      <span class="pill">uv</span>
      <span class="pill">Hooks</span>
      <span class="pill">MCP</span>
    </div>

    <a
      class="cta"
      href="https://github.com/disler/claude-code-hooks-mastery"
      target="_blank"
      rel="noopener"
    >
      <svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
        <path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.01 8.01 0 0 0 16 8c0-4.42-3.58-8-8-8z" />
      </svg>
      View on GitHub
    </a>
  </main>
</body>
</html>

What it is

Claude Code Hooks Mastery is a community-maintained reference repository by disler that demonstrates how to use every Claude Code hook lifecycle event with practical Python examples. Rather than a single plugin, it is a learning hub and starter kit: it covers the full set of hook events (PreToolUse, PostToolUse, Notification, Stop, SubagentStop, UserPromptSubmit, PreCompact, and SessionStart) so you can intercept, log, validate, and shape Claude Code agent behavior.

How to access / install

Clone the repository and explore the example hooks and .claude/settings.json wiring:

git clone https://github.com/disler/claude-code-hooks-mastery
cd claude-code-hooks-mastery

The examples are organized as standalone Python scripts run via uv, registered under the hooks key of your .claude/settings.json. Browse the source and docs directly on GitHub:

https://github.com/disler/claude-code-hooks-mastery

Good for

  • Learning the complete Claude Code hook lifecycle with copy-paste Python examples.
  • Adding guardrails (blocking dangerous tool calls, validating edits, logging activity).
  • Wiring notifications, custom prompts, and session bootstrapping into your agent workflow.
  • Teams standardizing Claude Code behavior across a repository via shared hook scripts.