Guide

Hooks

REAP hooks let you run automation at key lifecycle events. Hooks are stored as individual files in .reap/hooks/ and the AI agent executes them at the right moment.

Hook Types

Each hook file supports one of two types based on its extension:

command (.sh)

A shell script. Executed in the project root directory by the AI agent. Use for scripts, CLI tools, build commands.

prompt (.md)

An AI agent instruction in Markdown. The agent reads the prompt and performs the described task — code analysis, file modifications, documentation updates, etc. Use for tasks that require judgment.

Each hook is a single file. Multiple hooks per event are executed in the order specified by frontmatter.

File Naming

Hook files follow the pattern: .reap/hooks/{event}.{name}.{md|sh}

Each hook file supports optional YAML frontmatter:

FieldDescription
conditionName of a condition script in .reap/hooks/conditions/ (e.g. always, has-code-changes, version-bumped)
orderNumeric execution order when multiple hooks exist for the same event (default: 50, lower runs first)

Events

EventWhen it fires
onLifeStartedAfter /reap.start creates a new generation
onLifeLearnedAfter learning stage completes
onLifePlannedAfter planning stage completes
onLifeImplementedAfter implementation stage completes
onLifeValidatedAfter validation stage completes
onLifeCompletedAfter completion + archiving (runs after git commit)
onLifeTransitedAfter any stage transition (generic)
onMergeStartedAfter merge generation is created
onMergeDetectedAfter detect stage completes
onMergeMatedAfter mate stage completes (genome resolved)
onMergeMergedAfter merge stage completes (source merged)
onMergeReconciledAfter reconcile stage completes (genome-source consistency verified)
onMergeValidatedAfter merge validation completes
onMergeCompletedAfter merge completion + archiving
onMergeTransitedAfter any merge stage transition (generic)

File-based Configuration

Hooks are file-based — stored in .reap/hooks/, not in config.yml. Each hook is a file named {event}.{name}.{md|sh}.

text
.reap/hooks/
├── onLifeCompleted.reap-update.sh
├── onLifeCompleted.docs-update.md
├── onLifeImplemented.lint-check.sh
└── onMergeMated.notify.md

# Example: .md hook (AI prompt)
# ---
# condition: has-code-changes
# order: 30
# ---
# Review changes and update docs if needed.

# Example: .sh hook (shell script)
# #!/bin/bash
# # condition: always
# # order: 20
# reap update

Automatic Hook Suggestion

During the Completion stage (Phase 5: Hook Suggestion), REAP detects repeated patterns across generations — such as recurring manual steps, repeated commands, or consistent post-stage actions. When a pattern is detected, REAP suggests creating a hook to automate it. Hook creation always requires user confirmation before being applied.

Execution Notes

  • Hooks are executed by the AI agent, not the CLI. The agent scans .reap/hooks/ for matching files.
  • .sh files run as shell scripts in the project root directory.
  • .md files are read as AI prompts and followed by the agent.
  • Hooks within the same event run in order (frontmatter 'order' field, lower runs first).
  • Conditions are evaluated via .reap/hooks/conditions/{name}.sh (exit 0 = run, non-zero = skip).
  • onLifeCompleted/onMergeCompleted hooks run after the git commit — any file changes from hooks will be uncommitted.