OpenClaw Hooks Crash Course - Gemma 4 Ollama 100% Local
By Mervin Praison
Key Concepts
- Open Claw: An open-source platform for managing AI agents and workflows.
- Hooks: Event-driven functions that execute custom code in response to specific actions (e.g.,
/new,/reset) within the Open Claw interface. - Ollama: A tool for running Large Language Models (LLMs) locally.
- Gemma 4 (E2B): A lightweight, high-performance Google model optimized for edge devices.
- Event-Driven Architecture: The mechanism where system actions (commands, messages, agent states) trigger predefined scripts.
- Gateway: The core service in Open Claw that manages communication and model integration.
1. System Setup and Environment
The demonstration uses a Beelink Pro (AMD Ryzen 7 H255, 24GB RAM, 1TB HDD) as a dedicated local server.
- Ollama Installation: Installed via a one-line command on the Linux terminal.
- Model Deployment: The Gemma 4 E2B model is pulled and executed locally using
ollama run gemma-4-e2b. - Open Claw Configuration: The platform is configured to use "Ollama local only" as the model provider, with the base URL pointed to the local instance. Telegram integration is established via a bot token.
2. Understanding and Creating Hooks
Hooks allow users to extend Open Claw functionality by triggering custom logic whenever specific events occur.
Step-by-Step Hook Creation Process:
- Directory Setup: Navigate to the
.openclaw/hooks/directory on the host machine. - Folder Structure: Create a new folder for the specific hook (e.g.,
Telegram_audit). - File Requirements:
hook.md: Provides a description of the hook's purpose.handler.ts: The TypeScript file containing the logic. It listens for specific events (e.g.,command:new,command:reset) and executes actions (e.g., sending a notification to Telegram).package.json: Defines the module metadata.
- Activation:
- List available hooks:
openclaw hooks list - Enable the hook:
openclaw hooks enable [folder_name] - Apply changes:
openclaw gateway restart
- List available hooks:
3. Technical Implementation Details
- Event Types: The system supports various event triggers:
- Command Events: Triggered by slash commands (e.g.,
/new,/stop). - Agent Events: Triggered before workspace bootstrap files are injected.
- Gateway Events: Triggered after the channel starts and hooks are loaded.
- Message Events: Triggered whenever a message is sent or received.
- Command Events: Triggered by slash commands (e.g.,
- Customization: The
handler.tsfile acts as a bridge. While the example uses Telegram, the author notes that this can be modified to trigger WhatsApp, external APIs, or custom webhooks, providing a mechanism for security guardrails or automated logging.
4. Notable Quotes
- "You can customize or trigger any function whenever activity is happening in Open Claw... That is the power of hook."
- "If you want the user to prevent clicking any button or icon, you can do that, too. Easiest way of customizing based on your requirement."
5. Synthesis and Conclusion
The video demonstrates that Open Claw is highly extensible through its hook system. By leveraging local LLMs like Gemma 4 via Ollama, users can build private, automated AI environments. The ability to intercept system events—such as chat resets or new session creations—and route them to external messaging platforms like Telegram provides significant utility for monitoring, security, and workflow automation. The modular nature of the handler.ts file ensures that users can scale their automation from simple notifications to complex API integrations without modifying the core platform code.
Chat with this Video
AI-PoweredLoad the transcript when you're ready to chat so the initial page stays lighter.