Skip to content
Skills Library
Programming · Building & coding

doompi-author-hook

/doompi-author-hook

Author DoomPi repository or plugin hooks. Use when creating or changing .doom/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to DoomPi.

Repository
doompi ↗
Licence
MIT
Last repository change
14.10.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
1
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 14.10.2026, without references to retired models or APIs.

Licence

MIT, open: use and modify while retaining author attribution.

What it does and when to use it

Author DoomPi repository or plugin hooks. Use when creating or changing .doom/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to DoomPi.

Original author description

Author DoomPi repository or plugin hooks. Use when creating or changing .doom/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to DoomPi.

How it works

  1. Registry and selection
  2. Lightweight module API
  3. Full HookContext contract
  4. Command payloads and decisions
  5. Ownership, sync, and failures
  6. Verification
Original SKILL.md headings · 125 lines, 1,174 words
SKILL.md preview
---
name: doompi-author-hook
description: Author DoomPi repository or plugin hooks. Use when creating or changing .doom/hooks.yaml, selecting hook groups from modes.yaml, writing hook commands, or adapting Claude Code hook payloads and decisions to DoomPi.
---

# Author DoomPi hooks

Write the smallest hook that enforces the requested policy. Hooks are trusted executable code, not sandboxed guardrails.

## Registry and selection

Define personal hooks in `~/.pi/.doom/hooks.yaml` and repository hooks in `<repo>/.doom/hooks.yaml`:

```yaml
groups:
  safety:
    core: true
    hooks:
      - event: PreToolUse
        pi:
          matcher: Bash
          module: .doom/hooks/guard.ts
          timeout: 10
          skipInSubagent: true
          order: 0
```

- Each `pi` row declares exactly one of `command` or `module`. Module paths resolve relative to the declaring repository root or `~/.pi/.doom` root.
- A repository group replaces a personal group of the same ID completely.
- `core: true` always runs. Unset `hookGroups` means all groups; explicit `hookGroups: []` means core only. An explicit list selects those groups plus core.
- Keep `@agimon-ai/doompi-hook` in active packages. Layers select groups through `hookGroups` in `modes.yaml`.
- `matcher` is a regular expression over Claude tool names such as `Bash` and `Write`, including for module rows.
- Lower `order` runs first, then declaration order. Registry commands/modules interleave before plugin commands. Explicit denial ends the chain.
- `skipInSubagent: true` excludes a row from child tool dispatch. Use it for parent-owned effects, not to control lifecycle ownership.

## Lightweight module API

Import from the dependency-free authoring subpath:

```ts
import { defineDoomHook } from '@agimon-ai/doompi-hook/authoring';

export default defineDoomHook({
  setup(ctx) {
    let calls = 0;
    return {
      tool_call(event, ctx) {
        calls += 1;
        if (event.toolName === 'bash' && String(event.input.command).includes('rm -rf')) {
          return { block: true, reason: 'Use a non-destructive command.' };
        }
      },
      async dispose() {
        // Release session-owned resources.
      },
    };
  },
});
```

The default export must expose `setup(ctx)`, returning handlers synchronously or asynchronously. Registry events select native handlers:

- `SessionStart`: `session_start(event, ctx)`, returns void.
- `PreToolUse`: `tool_call(event, ctx)`, returns void or `{ block?: boolean, reason?: string }`.
- `PostToolUse`: `tool_result(event, ctx)`, returns void or `{ content?, details?, isError? }`.
- `Stop`: `agent_settled(event, ctx)`, returns void and cannot send messages.
- Optional `dispose()` returns void or a promise. No module `SessionEnd` exists.

Native events use Pi tool names such as `bash`. Tool-call handlers may mutate `event.input`, which must remain a JSON object. Accepted changes reach later rows and the tool. Tool-result patches support text/image content, JSON-compatible details, and a boolean `isError`. Failed, invalid, or late calls cannot publish mutations or patches. Lifecycle handlers cannot return decisions.

## Full HookContext contract

The authoring API exports `HookContext`, `HookHandlers`, `HookModule`, `HookModuleDescriptor`, `AgentSettledEvent`, `Awaitable`, and `JsonValue` types:

```ts
interface HookContext {
  readonly sessionId: string;
  readonly parentSessionId?: string;
  readonly agent?: string;
  readonly isSubagent: boolean;
  readonly cwd: string;
  readonly repoRoot: string;
  readonly model?: { readonly provider: string; readonly id: string };
  readonly signal: AbortSignal;
  sendMessage(text: string, delivery: 'steer' | 'followUp'): Promise<void>;
  appendCustomEntry(type: string, data: JsonValue): Promise<void>;
}
```

Optional identity/model fields may be absent, including model in native children. `cwd` is the session working directory; `repoRoot` is its resolved repository root. Await context effects. Messages use host prompt admission; admission failures propagate rather than becoming advisory hook failures. Custom entries persist JSON-compatible data in session history.

Setup and row calls for one module/session are serialized. Multiple rows share one setup instance. Store mutable session state in the setup closure, never module globals, which may be shared across sessions. Closure state is not durable across reloads; record custom entries explicitly when needed.

Setup gets a lifetime context; handlers get invocation contexts reflecting cancellation. Invocation effects are revoked after completion. Setup failure, setup/handler timeout, or cancellation quarantines the instance and revokes its effects. Honor `signal`; revocation cannot terminate arbitrary JavaScript or undo completed external effects.

## Command payloads and decisions

Commands run through `/bin/bash -c` from the repository root with Claude-compatible JSON on stdin. Environment fields include `CLAUDE_PROJECT_DIR`, `CODEX_REPO_ROOT`, `ORIGINAL_REPO_PATH`, and `CLAUDE_PLUGIN_ROOT`, the declaring root. Native child payloads use the child's own `session_id`, plus `parent_session_id` and `agent_type`.

The final stdout line beginning with `{` is parsed. Denial is `decision: "block"` or `hookSpecificOutput.permissionDecision: "deny"`. Reasons use top-level `reason` or `hookSpecificOutput.reason`; context uses `hookSpecificOutput.additionalContext`.

- `SessionStart` adds additional context to the conversation.
- `PreToolUse` denial blocks. Additional context also blocks the current call with that text as its reason so the agent can reconsider, rather than silently steering execution.
- `PostToolUse` appends additional context or reason; denial marks the result as an error.
- `Stop` denial with a reason requests a follow-up turn. At most five consecutive refusals schedule follow-ups; a further refusal is reported and stops without another turn. A stop without a refusal reason resets the count. `stop_hook_active` indicates a prior active refusal.
- `SessionEnd` is plugin-command-only and runs for side effects.

Module `agent_settled` cannot implement command Stop continuation by returning a decision or sending a message.

## Ownership, sync, and failures

Terminal parents use Pi tool and lifecycle handlers. For headless parents, the Pi bridge owns `SessionStart`, `Stop`, and plugin `SessionEnd`; server facets alone own tool dispatch. Lifecycle/tool paths share session module setup. Session-start readiness gates dependent turns/tools. Shutdown runs session-end once before disposal.

Native children in both adapters run only `PreToolUse` and `PostToolUse`, never lifecycle rows, regardless of `skipInSubagent`. Children have separate setup/state and retain their launch selection and compiled modules after parent reload/disposal.

After editing modules/imports, registry, or selection, run `doompi sync` or `dpi sync`, check with `doompi sync --check`, then use `/reload` or restart the terminal session. Reopen headless sessions. Sync compiles core plus the union of mode-selected groups, or all groups if any mode leaves selection unset. Compile failure preserves the previous published generation. Runtime imports only descriptor-mapped compiled artifacts, with no live source fallback. Descriptor selection is pinned at binding creation, even for cold lazy imports after replacement configuration. Sync alone does not update a running session.

`timeout` is positive finite seconds, default 10. A module's first invocation budget includes import/setup and handler execution. Execution/setup errors, invalid results, and timeouts are advisory missed checks, not automatic denials. Quarantined instances do not resume checks in that session. Host readiness, cancellation, and context effect/admission failures are not advisory execution failures. Command nonzero exits, invalid JSON, spawn failures, and timeouts are advisory; timeout terminates the process group with SIGTERM then SIGKILL two seconds later.

Compilation/pinning ensure consistency, not isolation or authorization. Modules run in the host Node.js process with host privileges. Synchronous infinite loops, `process.exit`, and out-of-memory failures cannot be contained in-process. Prefer `command:` when process isolation and hard termination matter. Serialization and session-local setup do not isolate globals, filesystem/network access, or external effects. Context revocation gates only the exposed context methods. Do not run untrusted hooks or promise guaranteed enforcement from advisory checks.

## Verification

1. Run commands directly with representative stdin JSON; sync module sources and their imports.
2. Confirm activation with the intended mode and `doompi --explain`.
3. Reload/restart and exercise exact events in a disposable session, including child tool calls, cancellation, timeout, and `skipInSubagent` behavior.
4. Check failure reporting, shared lifecycle/tool setup, result/input changes, and once-only shutdown.
5. Distinguish runtime proof from mocks: verified functional proof covers real Pi bridge dispatch, shared setup, admission markers, cancellation, native command rows, cold descriptor pinning, and both real native child adapters. Direct/MCP command-row proof explicitly mocks tool bodies. Do not claim full intercom plugin integration from that evidence.

Versions

The database has no other skills named doompi-author-hook.

Database snapshot: 13.11.2026 · package version f4dc0c2ac0c1 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 2 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 90doompi-author-major-mode
    Configure DoomPi default packages, layers, extensions, hook groups, and named major modes. Use when creating or editing ~/.pi/.doom/modes.yaml or a repository's .doom/modes.yaml, choosing a default mode, or diagnosing which behavior a mode activates.
  • 81doompi-author-domain
    Configure DoomPi plugin catalogs and domain resource selections in domains.yaml. Use when creating or editing .doom/domains.yaml or ~/.pi/.doom/domains.yaml, choosing local, Git, or npm plugins, filtering plugin resources, setting aliases or defaults, or verifying resolved domain composition.
  • 100agent-harness-reference
    Field reference for Claude Code and GitHub Copilot CLI hook contracts. Covers hook locations, events, matchers, payloads, decisions, exit codes, timeouts, plugin roots, and cloud limits with official URLs and versioned probes. Use for `harness contract`, `copilot cli hook…
  • 82hooks-author
    Write or fix .devin/hooks.v1.json hook files. Use when creating Devin CLI hooks (tool-call guards, lifecycle events, commit hooks) or debugging why a hook isn't firing.
  • 98write-hooks
    Write or audit a Claude Code or Copilot CLI hook. Use when something should run automatically on an event, or a hook misfires or never fires. Not for the skill carrying it (write-skills) or the plugin manifest and catalog.
  • 100react-hooks
    React Hooks patterns, rules, and custom hook development. Covers all built-in hooks (useState, useEffect, useContext, etc.), performance hooks, and patterns for creating reusable custom hooks. USE WHEN: user mentions "custom hooks", "hook rules", "useState", "useEffect",…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.