omp packages

pi-command-hooks0.1.1

Run Codex and Claude Code-style command hooks in Pi.

joynik108 Published 2 days ago MIT ~275 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-hooks

Run Codex and Claude Code-style command hooks in Pi. Requires Pi 1.7.0 or newer within the 1.x series and macOS or Linux.

Install

After publication, install from npm with:

pi install npm:pi-command-hooks

For a local checkout, run pi install /absolute/path/to/pi-hooks. To test a tarball, install it into a staging directory with npm, then register the extracted package directory with Pi:

stage="$(mktemp -d)"
npm install --prefix "$stage" ./pi-command-hooks-0.1.0.tgz
pi install "$stage/node_modules/pi-command-hooks"

Keep the registered directory in place while using the package.

Configuration

Copy the global example to ~/.pi/agent/hooks.json. Pi resolves the agent directory through getAgentDir(). PI_CODING_AGENT_DIR changes that directory. Pi's --agent-dir takes precedence.

Copy the project example to .pi/hooks.json in the directory where you start Pi. The extension reads that file only after Pi trusts the directory. Use Pi's trust prompt, /trust, or --approve for one invocation. Reload Pi after editing the configuration. The example's $schema path is relative to the example. Update or remove it after copying.

<agent-dir>/hooks.json ──────► global groups ─┐
<cwd>/.pi/hooks.json ─ trust ► project groups ┴─► match ─► run ─► apply result

Each file uses schema version 1. The root hooks maps event names to arrays of groups. Set compatibility on each group to claude (the default) or codex. Copy a compatible group from its source agent into this map. The extension reads only Pi's two files.

  • matcher takes a case-sensitive JavaScript regex. Omit it, leave it empty, or use * to match all. UserPromptSubmit and Stop ignore matchers. Tool matchers accept the Pi name and known aliases, such as read and Read, bash and Bash, and find and Glob.
  • Each group contains a hooks array. Each handler sets type: "command" and command. Add args, including an empty array, to execute directly. Omit it for /bin/sh. Set shell: "bash" for /bin/bash.
  • timeout is in seconds, from 0.001 to 600. Defaults are 60 seconds, 30 for prompts, and 1.5 for session end. Session end has a shared three-second budget.
  • Global groups run first. Within each file, group and handler order follow the arrays. Each scope runs identical matched handlers once per event. Execution form, mode, timeout, condition, context limit and failure policy count toward identity. The two scopes deduplicate independently. disableAllHooks: true disables only the file that declares it.
  • Set onFailure: "block" on PreToolUse, UserPromptSubmit or PreCompact to block when a matching handler fails. The default, "continue", reports the failure and continues. Unreadable JSON has no recoverable handler policies. A protective tool hook locks the arguments it approves against later rewrites during the same dispatch.
  • if supports a subset of Claude tool rules, such as Bash(git *) and Read(src/**). Complicated shell syntax runs the hook whenever its tool matches. Use the command itself for decisions that require parsing shell input precisely.

Global commands inherit Pi's environment. Project commands receive PATH, HOME, USER, LOGNAME, TMPDIR, LANG, LC_ALL, LC_CTYPE and TERM when available. Set projectEnv in the global file to allow more variable names. Both scopes receive PI_PROJECT_DIR. Claude mode also sets CLAUDE_PROJECT_DIR. Explicit argv form expands these placeholders without shell parsing. Commands run with your permissions. Project trust and environment filtering provide no filesystem isolation.

Compatibility

Every command receives one JSON object on stdin with session_id, transcript_path, cwd and hook_event_name. It receives model when available and permission_mode: "default" where applicable. The transcript uses Pi's format. Codex turn IDs and agent-specific permission state are unavailable.

Hook event Pi event Additional stdin and matching Results
SessionStart session_start, session_compact source and optional model. Match startup, resume, clear, fork, compact. Add context. Reload only reloads configuration.
SessionEnd session_shutdown Match reason. Codex uses other. Claude can also receive clear or resume. Observation only.
UserPromptSubmit input prompt, before Pi expands templates. Reject or add context.
PreToolUse tool_call Match tool_name. Also receives tool_input and tool_use_id. Deny, add context or replace validated arguments. Claude can request confirmation.
PostToolUse tool_result Same tool fields plus tool_response. Codex receives text, including execution errors. Claude receives a Pi result object on success. Add feedback. Codex can replace the model-visible result.
PostToolUseFailure tool_result on error Claude only. Same tool fields plus error and is_interrupt. Add feedback. Preflight rejections and aborts without a result skip this hook.
Stop agent_before_settle last_assistant_message and stop_hook_active. Add context or request one continuation per prompt. Aborted and failed runs skip it.
PreCompact session_before_compact Match trigger as manual or auto. Claude also gets custom_instructions. Cancel compaction. Pi cannot apply hook-provided compaction instructions.
PostCompact session_compact Match trigger. Receives compact_summary. Observation only.
PermissionRequest, PermissionDenied, SubagentStart, SubagentStop, Notification, ConfigChange — Pi exposes no equivalent public hook event for these source events. Configuration reports the unsupported event.

Claude stdin uses display aliases and adds file_path to read, write and edit. For edit, old_string and new_string describe the first replacement. Codex uses Bash for bash and Pi names for other tools. Use Edit or edit to match Pi edits. A Codex script that expects apply_patch and its patch text needs an adapter.

Command output

Exit 0 with empty stdout succeeds. SessionStart and UserPromptSubmit also accept plain-text context. An object-shaped JSON response can contain systemMessage or hookSpecificOutput.additionalContext where supported. Use decision: "block", hookSpecificOutput.permissionDecision: "deny" for tools, or exit 2 to reject a supported action. Exit 2 takes feedback from stderr or a Claude JSON blocking reason. For Stop, blocking asks Pi to continue once. continue: false on Stop takes precedence over requests to continue.

In Claude mode, valid JSON can control the action when a hook exits with a code other than 0 or 2. With onFailure: "block", such an exit counts as a command failure. Codex mode also treats it as a command failure. Use exit 0 when returning a JSON decision.

Return hookSpecificOutput.updatedInput to replace arguments for Pi's built-in bash, read, write or edit. Codex also requires permissionDecision: "allow" in the same response. Invalid replacements keep the previously accepted arguments. Claude ask requires the Pi UI; without it, the call is denied. allow cannot bypass Pi or another hook. Each output stream has a 64 KiB ceiling. Timeouts and cancellation kill the command's process group. A descendant that creates a new process group can escape that cleanup.

The extension rejects http, mcp_tool, prompt and agent because this package executes local commands only. Pi also rejects asynchronous execution, reawakening and PowerShell. statusMessage, commandWindows and suppressOutput are accepted where applicable for portability. They have no effect on this POSIX runner. Plugin roots, persisted hook environments and tool-specific response replacements such as updatedMCPToolOutput require their source host. Claude's deferred tool calls require its resume protocol. Pi treats Claude PreToolUse responses with continue: false as a blocked tool call with a termination request. Pi cannot retain a deferred tool call.

References: Pi extension API, Codex hooks, Claude Code hooks.

License: MIT.