Plugin

Plugin Hooks

Session startson_session_start - reset per-session stateUser turnpre_tool_call - auto-background, chain splitTool or terminal runstransform_tool_result ortransform_terminal_output - compress to markerpre_llm_call - inject directives and catalogLLM respondspost_llm_call - archive turn, advance counter
PLUGIN/HOOKS
IN THIS DOCUMENT

Crimson marks the heading currently in view; every entry is one of the document's own headings.

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.

HookPurposeWhen it fires
on_session_startReset all per-session state to a clean baselineA Hermes session starts
pre_tool_callAuto-background long-running calls; split chained commandsBefore a tool executes
transform_tool_resultCompress large tool results into CCR markersAfter every tool call
transform_terminal_outputCompress large terminal output into CCR markersAfter every terminal execution
pre_llm_callInject directives, nudges, engine-offload, and the recall catalogBefore each LLM request
post_llm_callArchive the turn, advance the counter, expire stale stateAfter each LLM response
Session startson_session_start - reset per-session stateUser turnpre_tool_call - auto-background, chain splitTool or terminal runstransform_tool_result ortransform_terminal_output - compress to markerpre_llm_call - inject directives and catalogLLM respondspost_llm_call - archive turn, advance counter
PLUGIN/HOOKS

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 a terminal or process call whose command matches the long-running patterns to run in the background: it returns a modify action with background: true and notify_on_complete: true, and Hermes runs the tool asynchronously. The agent observes completion through its normal poll flow. process calls with action: poll are never backgrounded - they are checks, not work.
  • Chain splitting. When chain splitting is enabled (APHRODITE_CHAIN_SPLIT=1 or [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 least chain_split_min_segments segments. The marker-splitting lets transform_terminal_output compress 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:

  1. 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.
  2. 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 compressing aphrodite_retrieve would replace resolved content with another marker); or when it is below the tool threshold (default 4,096 characters, shipped example 256; 0 disables the gate and always compresses).
  3. 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.
  4. 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:

  1. 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.
  2. 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.
  3. Threshold gate. Unmarked output below the terminal threshold (default 1,024 characters, shipped example 256; 0 disables the gate) passes through untouched.
  4. Classify and store. The hook types output containing exit code: or Error: as terminal and 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:

  1. First-turn orientation ([aphrodite: first-turn orientation], turn 0 only)
  2. [directives: ...] block - never dropped
  3. [nudge: ...] one-shots, at most two - never dropped
  4. [engine-offload: ...] - present only when the context engine archived middle turns this turn; never dropped, because the archive already mutated the conversation index
  5. [retrieval: ...] - opt-in guidance line rendered from [prompts] retrieve_guidance
  6. Background-task status
  7. [auto-expand: ...] - opt-in guidance line rendered when auto_expand is on
  8. [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

HookSettingDefaultBypass
transform_tool_result[compression] tool_threshold_token4,096 (shipped example 256)empty, essential tools, self tools, below threshold; 0 = always compress
transform_terminal_output[compression] terminal_threshold1,024 (shipped example 256)empty, below threshold; 0 = always compress
pre_llm_call[flow] budget_chars4,000recall catalog dropped first; directives, nudges, and engine-offload never drop
pre_llm_call (context engine)[compression] engine_threshold_pct45 (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