๐Ÿค–HermesBlog
Hermes Feature Guides ยท Part 18/9/2026

Event Hooks โ€” Auto-Trigger at Key Moments

Event Hooks โ€” Auto-Trigger at Key Moments โ€” easy-to-understand guide based on official docs (updated 2026-08-09)

Think of event hooks like a smart doorbell that not only rings when someone arrives, but also automatically unlocks the door, turns on the lights, and texts you a photo โ€” all without you lifting a finger.

In Hermes Agent, event hooks are small pieces of code that run automatically at specific moments in your agentโ€™s life. Instead of manually checking โ€œdid the agent finish?โ€ or โ€œdid a new chat start?โ€, you can set up hooks to do something useful at exactly the right time.

Four Ways to Hook In

Hermes gives you four different hook systems, each with its own job:

System Best for
Gateway hooks Logging, alerts, webhooks (Gateway only)
Plugin hooks Tool interception, metrics, guardrails (CLI + Gateway)
Shell hooks Drop-in scripts for blocking, auto-formatting (CLI + Gateway)
Outbound webhooks Push signed events to external HTTP endpoints (CLI + Gateway)

Donโ€™t worry about memorizing all four. Start with Gateway hooks โ€” theyโ€™re the easiest to understand.

Your First Gateway Hook

Gateway hooks live in ~/.hermes/hooks/. Each hook is a folder with two files:

~/.hermes/hooks/
โ””โ”€โ”€ my-hook/
    โ”œโ”€โ”€ HOOK.yaml      # Tells Hermes which events to listen for
    โ””โ”€โ”€ handler.py     # The code that runs when an event fires

Step 1: Declare Events in HOOK.yaml

name: my-hook
description: Log all agent activity to a file
events:
  - agent:start
  - agent:end

Step 2: Write the Handler

import json
from datetime import datetime
from pathlib import Path

LOG_FILE = Path.home() / ".hermes" / "hooks" / "my-hook" / "activity.log"

async def handle(event_type: str, context: dict):
    entry = {
        "timestamp": datetime.now().isoformat(),
        "event": event_type,
        **context,
    }
    with open(LOG_FILE, "a") as f:
        f.write(json.dumps(entry) + "\n")

Three simple rules for handlers:

  • The function must be named handle
  • It receives event_type (a string) and context (a dictionary)
  • It can be async or regular โ€” both work

What Can You Listen For?

Here are some useful events:

Event When it fires
gateway:startup Gateway process starts
session:start New chat session begins
session:reset User runs /new
agent:start Agent starts processing a message
agent:end Agent finishes processing

You can even use wildcards like command:* to catch a whole family of events.

The Best Part: Hooks Canโ€™t Crash Your Agent

If your hook code has a bug, Hermes catches the error, logs it, and moves on. Your agent keeps working. This means you can experiment freely without fear of breaking things.

Summary & Practical Tip

Event hooks are your agentโ€™s โ€œauto-pilotโ€ โ€” they run at key moments to handle logging, alerts, or any custom logic you dream up. Start small: create a hook that logs agent:start and agent:end to a file. Once you see it working, expand to other events.

Pro tip: Use session:compress events to track when your agentโ€™s context gets compacted. If you notice frequent compression, itโ€™s a sign your conversations are getting too long โ€” consider telling users to start fresh sessions more often.

๐Ÿ“– Official Docs

This article is based on the official Hermes Agent documentation:Official docs โ€บ user-guide/features/hooks