Six hooks, one turn
A tool call's output becomes part of the model's context, and the hooks are the points where Aphrodite sees that output first.
Every hook is a thin dispatch that forwards its arguments to the Rust dylib and hands the JSON reply back to Hermes.
It is the reason the shim registers one callback per name: on plugin load it asks the dylib for its hook names, and the six hooks are always registered together.
The chain is the whole integration: each seam fires in turn order, and nothing reaches the model that a seam did not first see.
01 // SEQUENCE // PER TURN
The loop a turn walks
- session starts
- → on_session_start · reset per-session state
- ↓
- user turn
- → pre_tool_call · auto-background, chain split
- ↓
- tool or terminal runs
- → transform_tool_result / transform_terminal_output · compress to marker
- ↓
- → pre_llm_call · inject directives, nudges, recall catalog
- ↓
- LLM responds
- → post_llm_call · archive turn, advance counter, expire
- ↓
- ⟲ next turn
The loop closes on itself, so the state a turn leaves behind is the state the next turn reads.
That is why the reset seam exists: a new session starts from a clean baseline instead of inheriting the previous session's counters and markers.
02 // THE SIX // ONE SECTION EACH
What each seam does
03 // ON_SESSION_START
The seam that starts a clean session
- 01 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
Resets every piece of per-session state to a clean baseline: turn counter, conversation index, recent markers, referenced files, tool-event telemetry, ephemeral directives.
Injects nothing - the one-shot first-turn orientation renders later, on the first pre_llm_call.
04 // TRANSFORM_TOOL_RESULT
The seam that compresses a tool result
- 02 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
After every tool call: record telemetry, run the skip gates, classify the content type, hash (BLAKE3), store, and replace the output with <<<CCR:hash|type|size>>> plus a compact preview.
The hook tracks file references before the gates, so aphrodite_files sees every read even when nothing was compressed.
05 // PRE_LLM_CALL
The seam that assembles the context
- 03 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
Runs the poll-worker checkpoint, then the context assembler: first-turn orientation (turn 0 only), [directives:] (never dropped), [nudge:] one-shots at most two (never dropped), background-task status, and the [recall] catalog - the first section dropped under pressure.
One hard budget: 4,000 chars.
06 // TRANSFORM_TERMINAL_OUTPUT
The seam that compresses terminal output
- 04 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
Same pipeline for shell stdout/stderr.
The hook records non-zero exit codes as failures for the error-loop detector; chain-split segments compress unconditionally, before the threshold gate, so marked output never leaks raw; everything else passes the 1,024-char gate first.
07 // POST_LLM_CALL
The seam that closes the turn
- 05 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
Archives the last marker of the turn into the conversation index (so aphrodite_diff can report per-turn compressions), advances the turn counter, purges expired nudges after the counter advances - a one-shot nudge renders exactly once - and expires stale poll-worker tasks.
08 // PRE_TOOL_CALL
The seam before a tool runs
- 06 / 06
- args → libaphrodite_hermes.dylib → JSON reply
- provides_hooks · plugin.yaml
Two interventions before a tool executes.
Auto-backgrounding: the hook rewrites long-running terminal/process calls to run in the background (poll worker, default on).
Chain splitting (opt-in): the hook splits chained commands with invisible segment markers so each segment compresses into its own CCR marker.
Otherwise the call passes through unchanged.
09 // BYPASS // THE ESSENTIAL-TOOL GATE
What never gets compressed
A result is left untouched when it is empty, below threshold, or from the essential set - tools the agent needs raw:
Aphrodite also skips its own tools and headroom helpers - compressing aphrodite_retrieve would just replace resolved content with another marker.
The gate is the reason retrieval stays cheap: a marker the model resolves comes back whole, because nothing downstream of the gate rewrites it a second time.
10 // THRESHOLDS // GATES AND BYPASSES
The numbers that decide
| HOOK | SETTING | DEFAULT | BYPASS |
|---|---|---|---|
| transform_tool_result | tool_threshold_token | 4,096 | empty · essential tools · self tools · 0 = always compress |
| transform_terminal_output | terminal_threshold | 1,024 | empty · below threshold · 0 = always compress |
| pre_llm_call | flow budget_chars | 4,000 | recall catalog drops first; directives and nudges never drop |
| pre_tool_call (chain split) | chain_split_min_segments | - | feature off by default (chain_split = false) |
PRECEDENCE: ENVIRONMENT > TOML > DEFAULT (APHRODITE_TOOL_THRESHOLD_TOKEN · APHRODITE_TERMINAL_THRESHOLD · APHRODITE_FLOW_BUDGET_CHARS · APHRODITE_CHAIN_SPLIT).
SRC: docs/plugin/hooks.md; plugins/aphrodite/plugin.yaml (provides_hooks)
SRC: docs/architecture/04-hook-ffi.md