Skip to main content
The hooks command manages event-driven hooks configured in .praisonai/hooks.json.
This CLI and its HooksManager API are a standalone, opt-in utility. Configured hooks do NOT fire automatically inside an Agent — an event only occurs when your own code calls HooksManager.execute(). Agent and Task never call it. For hooks that fire automatically around an Agent’s tool/LLM calls, use the live praisonaiagents.hooks package instead. See Memory HooksManager for the standalone utility in depth.
Install requirement: praisonai hooks requires pip install praisonai (the full wrapper). On a standalone pip install praisonai-code install every hooks subcommand exits 1 with hooks requires the full wrapper. Install the full wrapper: pip install praisonai — a single-line hint, no Rich traceback (PR #2854).

Quick Start

List event hooks example

Usage

List Hooks

Expected Output:
When no hooks are configured, list prints an empty-state hint pointing at .praisonai/hooks.json.

Show Statistics

Initialize Hooks

Creates a template .praisonai/hooks.json file.
The only Typer-registered actions are list, stats, and init. The underlying handler also accepts help. There is no add or remove subcommand — configure hooks by editing the file hooks init creates.
An unknown hooks action prints an error and exits non-zero (1). Earlier versions printed the error but returned 0, so shell scripts checking $? saw success. Update any script that relied on the old exit code.

Hooks Configuration

Manage Event-Driven Hooks hooks init writes this template to .praisonai/hooks.json:

Available Hook Events

Hook Types

Shell Hooks

Python Hooks

How It Works

The “event” below is triggered by whoever calls HooksManager.execute() — this page documents the CLI-facing utility and its programmatic API. Inside an Agent/Task run, nothing calls it. For hooks that fire automatically around an Agent’s tool/LLM calls, use /features/hooks.
  1. Load: Hooks are loaded from .praisonai/hooks.json
  2. Register: Hooks are registered for specific events
  3. Trigger: Events trigger corresponding hooks
  4. Execute: Hook commands/functions are executed with context

Context Variables

Hooks receive context variables that can be used in commands:

Examples

Code Formatting Hook

Linting Hook

Command Validation Hook

Programmatic Usage

HooksManager is exported from praisonaiagents.memory, not the top-level package. The event fires only because your code calls .execute() — an Agent never does.
This is a standalone utility: its events fire only when you call .execute(). To gate an operation, put the .execute() call inside your own tool or wrapper. See Memory HooksManager for the full API, and Live Agent Hooks for hooks that fire automatically.

Best Practices

Use hooks for consistent code formatting and validation across your project.
Hooks add execution time. Keep hook commands fast to avoid slowing down agent operations.