Skip to content

Pipeline Hooks

CortexPrism edited this page Jun 17, 2026 · 1 revision

Pipeline Hooks

The pipeline hooks system provides a 10-stage middleware architecture for the agent loop.

Hook Stages

INPUT → pre-assess → ASSESS → post-assess → pre-reason → REASON → post-reason
  → pre-tool → TOOL EXECUTE → post-tool → pre-reflect → REFLECT → post-reflect
  → pre-output → OUTPUT → post-output

Built-in Hooks

Hook Stage Priority Purpose
@cortex/injection-guard pre-reason 5 Prompt injection detection
@cortex/model-quartermaster pre-llm, post-llm 5 MQM model selection
@cortex/quartermaster pre-tool, post-tool 6 Tool orchestration learning
@cortex/summarization pre-reason 8 Context compaction (80K tokens)
@cortex/content-safety pre-output 10 Content filtering
@cortex/loop-detection pre-tool 12 Per-file edit tracking
@cortex/tool-output-sandbox post-tool 15 Large output capture
@cortex/pre-completion-checklist post-reason 20 Build-Verify-Fix
@cortex/audit-log post-output 150 Session/turn logging (non-disableable)
@cortex/cost-tracker post-tool, post-output 200 Token/cost metrics

Abort Semantics

Any hook can return { abort } to stop the pipeline immediately. The abort message is delivered to the user and logged to Lens.

Hook Actions

Hooks support five action types:

  • abort — Stop the pipeline
  • modifyInput — Mutate the input before processing
  • modifyLLMResponse — Modify the LLM's response
  • modifyOutput — Modify the final output
  • injectMessages — Add messages to the conversation
  • sideEffects — Log, emit metrics, store data, send notifications

Plugin Hooks

Plugins can contribute their own hooks to the pipeline. Per-session state is cleaned up on turn end to prevent memory leaks.

Hooks CLI

cortex hooks list        # List all hooks
cortex hooks disable @cortex/cost-tracker  # Disable a hook

See Also

Clone this wiki locally