The plugin registers six hooks with Hermes.
Every hook is a thin dispatch that forwards its arguments to the Rust dylib (libaphrodite_hermes.dylib); the dylib holds all of the actual behavior and replies with JSON that the Python module hands back to Hermes.
Registration is driven by the dylib’s hook list: on plugin load the shim asks the dylib for its hook names and registers one callback per name.
It is the reason the six hooks below are always registered together: the dispatch surface is the dylib’s own contract, and plugin.yaml declares the same set under provides_hooks.
| Hook | Purpose | When it fires |
|---|---|---|
on_session_start | Reset all per-session state to a clean baseline | A Hermes session starts |
pre_tool_call | Auto-background long-running calls; split chained commands | Before a tool executes |
transform_tool_result | Compress large tool results into CCR markers | After every tool call |
transform_terminal_output | Compress large terminal output into CCR markers | After every terminal execution |
pre_llm_call | Inject directives, nudges, engine-offload, and the recall catalog | Before each LLM request |
post_llm_call | Archive the turn, advance the counter, expire stale state | After each LLM response |
on_session_start
Fires when a Hermes session starts.
It resets every piece of per-session state to a clean baseline:
- the turn counter
- the conversation index
- recent markers
- referenced files
- tool-event telemetry
- ephemeral directives
- and the manual directive latch.
It injects nothing.
The one-shot first-turn orientation is rendered later by the context assembler on the first pre_llm_call (see below), so a session reset followed by a fresh turn behaves exactly like a new session.
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.
pre_tool_call
Fires before a tool executes and can modify the pending call. Two interventions are possible, both driven by the poll worker and chain-split features:
- Auto-backgrounding. When the poll worker is enabled (
APHRODITE_POLL_WORKER, default on), the hook rewrites aterminalorprocesscall whose command matches the long-running patterns to run in the background: it returns a modify action withbackground: trueandnotify_on_complete: true, and Hermes runs the tool asynchronously. The agent observes completion through its normal poll flow.processcalls withaction: pollare never backgrounded - they are checks, not work. - Chain splitting. When chain splitting is enabled (
APHRODITE_CHAIN_SPLIT=1or[compression] chain_split = true, default off), the hook rewrites a chained terminal command (cd x && cargo build && cargo test) with invisible segment markers, provided it has at leastchain_split_min_segmentssegments. The marker-splitting letstransform_terminal_outputcompress each segment into its own CCR marker, so the model sees several compact previews instead of one large blob.
If neither intervention applies, the call passes through unchanged.
transform_tool_result
Fires after every tool call with the tool’s result. The pipeline:
- Telemetry. The hook records the call’s status, error type/message, arguments, and duration into the tool-event ring, which feeds the error-loop and phase detectors, and skips empty results here.
- Skip gates. Aphrodite leaves a result untouched when it is empty; when the tool is in the essential set (
skill_view,skills_list,skill_manage,memory,session_search,read_file,read_terminal- the agent needs raw output); when it is one of Aphrodite’s own tools or a headroom helper (already compact metadata, and compressingaphrodite_retrievewould replace resolved content with another marker); or when it is below the tool threshold (default 4,096 characters, shipped example 256;0disables the gate and always compresses). - Classify. The content-type detector assigns a type and upgrades generic text/log/plain results (git status, ls, test, grep) so the preview carries high-signal shape.
- Store. The hook hashes the content (BLAKE3), stores it in the inline store, and replaces it with a marker of the form
<<<CCR:hash|type|size>>>with a preview. Hermes swaps the tool output for the marker; retrieval returns the exact original bytes.
The hook tracks file references before the skip gates, so it records read_file and search_files results for aphrodite_files and the catalog even when it never compresses them.
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.
transform_terminal_output
Fires after every terminal execution. The pipeline mirrors tool results:
- Telemetry. The hook records the command and return code; a non-zero exit code marks the event as a failure and feeds the error-loop detector.
- Chain split. When chain splitting is enabled and the output carries the segment markers injected by
pre_tool_call, the hook compresses each segment into its own marker (unconditional, before the threshold gate, so marked output never leaks raw) and merges per-segment error hints into previews. - Threshold gate. Unmarked output below the terminal threshold (default 1,024 characters, shipped example 256;
0disables the gate) passes through untouched. - Classify and store. The hook types output containing
exit code:orError:asterminaland runs other output through the normal content-type detection with the same semantic upgrade as tool results. It hashes, stores, and replaces above-threshold content with a marker.
pre_llm_call
Fires before each LLM request.
It first runs the poll-worker checkpoint (pushing status nudges for running, completed, and failed background tasks), then the single context assembler composes the per-turn injection.
The assembler builds every section in a fixed order under one hard byte cap (flow_budget_chars, default 4,000), dropping sections from the bottom when over budget:
- First-turn orientation (
[aphrodite: first-turn orientation], turn 0 only) [directives: ...]block - never dropped[nudge: ...]one-shots, at most two - never dropped[engine-offload: ...]- present only when the context engine archived middle turns this turn; never dropped, because the archive already mutated the conversation index[retrieval: ...]- opt-in guidance line rendered from[prompts] retrieve_guidance- Background-task status
[auto-expand: ...]- opt-in guidance line rendered whenauto_expandis on[recall]catalog summary - the first section dropped under budget pressure
The assembler builds the first-turn orientation from the [prompts] session_inject template (default compiled into the binary, {VERSION} interpolated to the plugin version).
The hook injects it once on turn 0, then never again; an empty string disables it entirely.
The hook returns {"context": ...}, which Hermes injects into the model’s turn. When the assembled context is empty, the hook injects nothing.
post_llm_call
Fires after each LLM response.
It archives the last marker recorded this turn into the conversation index (so aphrodite_diff can report per-turn compressions), advances the turn counter, purges expired nudges (after the counter advances, so a one-shot nudge renders exactly once), and expires stale poll-worker tasks.
Thresholds
| Hook | Setting | Default | Bypass |
|---|---|---|---|
transform_tool_result | [compression] tool_threshold_token | 4,096 (shipped example 256) | empty, essential tools, self tools, below threshold; 0 = always compress |
transform_terminal_output | [compression] terminal_threshold | 1,024 (shipped example 256) | empty, below threshold; 0 = always compress |
pre_llm_call | [flow] budget_chars | 4,000 | recall catalog dropped first; directives, nudges, and engine-offload never drop |
pre_llm_call (context engine) | [compression] engine_threshold_pct | 45 (shipped example 30) | engine disabled, 0 = never, 100+ = off, below engine_min_msgs, fill % below threshold, middle < 3 turns |
pre_tool_call (chain split) | [compression] chain_split_min_segments | - | feature off by default (chain_split = false) |
Each setting has an environment-variable equivalent (APHRODITE_TOOL_THRESHOLD_TOKEN, APHRODITE_TERMINAL_THRESHOLD, APHRODITE_FLOW_BUDGET_CHARS, APHRODITE_CHAIN_SPLIT, APHRODITE_ENGINE_THRESHOLD_PCT); environment overrides TOML, which overrides the default.
The context-engine row is the pre_llm_call trigger for Context Engine.
See aphrodite.toml Configuration for the full schema.
See also
- Directives - the
[directives: ...]block injected bypre_llm_call - Context Engine - the Hermes context-engine integration point
- Tool Relay: Tools - the tools these hooks coordinate with