agent-hooks-playground
Shared logger for AI coding agent lifecycle events
Package details
Install agent-hooks-playground from npm and Pi will load the resources declared by the package manifest.
$ pi install npm:agent-hooks-playground- Package
agent-hooks-playground- Version
0.1.0- Published
- May 24, 2026
- Downloads
- not available
- Author
- heruujoko
- License
- MIT
- Types
- extension
- Size
- 23.8 KB
- Dependencies
- 1 dependency · 0 peers
Pi manifest JSON
{
"extensions": [
"./pi/extensions/agent-hooks-logger.ts"
]
}Security note
Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.
README
Agent Hooks Playground
A TypeScript/Node.js CLI toolkit that normalizes lifecycle events from three different AI coding agents (Claude Code, Codex, Pi) into a shared JSONL log file.
Overview
Each AI coding agent uses different hook mechanisms:
- Claude Code: Shell-based hooks in settings.json
- Codex: JavaScript hooks in hooks.json with trust flow
- Pi: TypeScript extensions with event subscriptions
All three agents funnel events to a single normalized logger that writes to logs/agent-events.jsonl.
Quick Start
Install dependencies:
npm installBuild the project:
npx tscTest the logger:
npm run summary
Integration Guides
Choose your agent:
Claude Code Integration
- Copy
claude/settings.example.jsonto~/.claude/settings.json - Ensure hook scripts are executable
- Automatic event logging on Claude session
Codex Integration
- Copy
codex/hooks.example.jsonto.codex/hooks.json - Run
/hooksin Codex to review and trust hooks - Automatic event logging after trust
Pi Integration
- Copy or symlink
pi/extensions/agent-hooks-logger.tsto~/.pi/agent/extensions/ - Restart Pi (or run
/reload) to load extension - Automatic event logging via extension events (
source: "extension")
CLI Commands
log
Log events programmatically:
npm run log -- --agent claude --event session_start --summary "Session started" --source hook < data.json
summary
Display event statistics and recent events:
npm run summary
Output includes:
- Total event count by agent
- Event breakdown by type
- Last 10 events with timestamps
welcome
Generate welcome message for specific agent:
npm run welcome -- --agent claude
reset-logs
Clear the log file:
npm run reset-logs
Event Schema
All events follow a standardized format:
type AgentEvent = {
id: string; // Unique event ID
ts: string; // ISO 8601 timestamp
agent: AgentName; // "claude" | "codex" | "pi" | "manual"
event: string; // Event type (e.g., "session_start", "tool_call")
sessionId?: string; // Optional session identifier
cwd?: string; // Current working directory
toolName?: string; // Tool name for tool events
promptPreview?: string; // First 100 chars of user prompt
summary: string; // Human-readable event summary
source: "hook" | "extension" | "manual"; // Event source
raw?: unknown; // Original agent-specific data
};
Supported Events
Claude Code
SessionStart: Session initializationUserPromptSubmit: User submits a promptPreToolUse: Before tool executionPostToolUse: After tool execution completesStop: Claude completes its response
Codex
SessionStart: Session initializationUserPromptSubmit: User submits a promptPreToolUse: Before tool executionPostToolUse: After tool execution completesStop: Codex completes its response
Pi
session_start: Session initializationtool_call: Tool execution
Log Format
Events are written as JSONL (one JSON object per line) to logs/agent-events.jsonl:
{"id":"evt_2026-05-23T12-00-00-000Z_abc1","ts":"2026-05-23T12:00:00.000Z","agent":"claude","event":"SessionStart","summary":"Claude Code session started","source":"hook"}
{"id":"evt_2026-05-23T12-00-05-000Z_abc2","ts":"2026-05-23T12:00:05.000Z","agent":"claude","event":"UserPromptSubmit","summary":"User submitted prompt","source":"hook","promptPreview":"Implement feature X"}
Agent Comparison
| Feature | Claude Code | Codex | Pi |
|---|---|---|---|
| Hook Type | Shell scripts | JavaScript hooks | TypeScript extensions |
| Configuration | settings.json |
hooks.json |
Extension files |
| Trust Required | No | Yes (/hooks command) |
No |
| Event Source | Hook API | Hook API | Extension events |
| Session Events | Yes | Yes | Yes |
| Tool Events | Yes | Yes | Yes |
| Setup Complexity | Low | Medium | Low |
Architecture
Agent Session → Hook/Extension → Normalized Event → Logger → JSONL
↓
Summary CLI reads
Components
src/logger.ts: Core logger that writes to JSONLsrc/cli.ts: CLI interface with four commandssrc/schema.ts: TypeScript event schema definitionssrc/summarize.ts: Summary generation logicsrc/welcome.ts: Welcome message generationclaude/hooks/: Claude-specific hook scriptscodex/hooks/: Codex-specific hook scriptspi/extensions/: Pi-specific TypeScript extension
Error Handling
- Logger never throws — failures display as warnings to stderr
- CLI commands surface errors to user
- All scripts use absolute path resolution from git root
- Failed log attempts don't interrupt agent operation
Testing
Manual verification per agent:
- Follow the integration guide for your agent
- Trigger events by using the agent normally
- Run
npm run summaryto verify events logged - Check for warning output on failures
License
MIT