SSyncropel Docs

Hooks

Show a running actor a lesson after one of its tool calls returns, by saving a hook. Also covers spl session hooks, which record an external agent's session.

Two things called hooks

Syncropel has two hook mechanisms, and they solve different problems:

  1. Post-tool hooks (core.hook.v1): a lesson shown to an actor after one of its own tool calls returns. Covered first below.
  2. Session hooks (spl session): record an external agent's session (a Claude Code session, for instance) in your workspace. Covered in Session hooks.

Post-tool hooks: a lesson as a record

A post-tool hook watches the tool call that just returned. If a condition matches, the actor is shown a sentence on its next turn. You can teach a running actor a new lesson by saving one record.

A hook is a core.hook.v1 record on th_engine_config, saved with topic: "hook", the same way a permission rule is. Its fields:

fieldmeaning
namethe hook's name, shown to the actor
whena CEL condition (permission context) about the call that returned
textwhat the actor is shown next turn, with ${tool} and ${status} substituted
max_fires_per_runhow many times it may fire in one run (default 3)
enabledwhether it loads
namespacethe namespace it applies in

The when condition sees the call that just returned as a record whose body is {tool, args, status, content}, plus resource = tool:<name>, current_actor() and trust(). Inside a hook, trust() returns the run's own trust score for its own actor and domain, and 0.0 for any other pair. The condition reads only the first 4,096 characters of a tool's answer.

A hook can only add words

A hook can only add a sentence. It has no priority, action, suppress, replace, order, or instead_of field. It cannot block a call, override another hook, or change what a tool does. A record with any of those fields is refused, and so is any unknown field.

A hook shows words to every run in the workspace, so only owners can write one. Anyone else who writes a core.hook.v1 record gets CONFIG_WRITE_DENIED.

Writing a hook

A hook is a settings record on th_engine_config, like other settings. There is no spl config add-hook command; you write the record:

spl know --thread th_engine_config --actor did:sync:system:engine --act LEARN \
  --body '{
    "kind": "core.hook.v1",
    "topic": "hook",
    "name": "note-empty-search",
    "when": "record.body.tool == \"search_records\" && record.body.status == \"ok\"",
    "text": "The ${tool} call returned ${status}. If the result is empty, widen the query before concluding the record is absent.",
    "max_fires_per_run": 2,
    "enabled": true
  }'

Syncropel includes two built-in hooks (a repeat guard and an absence guard). A core.hook.v1 record adds more.

When it takes effect

  • Normal runs pick up a new hook straight away. A hook you save mid-run is shown after that run's next tool call.
  • Sandboxed runs get their hooks when they start. A hook saved after a sandboxed run has started reaches it the next time it starts.

max_fires_per_run counts within one run. A resumed run starts counting again.

Verify what loaded

The number of enabled hooks in force is reported in the engine health check:

curl -s -H "Authorization: Bearer $ADMIN" localhost:9100/v1/engine/health \
  | jq '.work_loop.hooks_loaded'

A hook that fails to load keeps its record but is not counted, so hooks_loaded is what is actually in force, not what you wrote.

What a hook cannot do

A hook only shows words. It cannot write a record, ask for a decision, or take any action.

Session hooks

spl session hook and spl session install-hooks are a different mechanism: they record an external agent's session (such as a Claude Code session) in your workspace, including its purpose, its log, its turns, and a report written at the end.

Install the hooks into the agent's settings (safe to run more than once):

spl session install-hooks

By default this writes into ~/.claude/settings.json; pass --settings to target another file, and --env KEY=VALUE (repeatable) to set the environment the hook command runs with, for example --env SYNCROPEL_HOME=/path.

Once installed, the agent runs spl session hook at key moments in its session, and that command records the session. You do not usually call spl session hook by hand. The related session-state verbs (context, capture, forget) are covered in Session checkpoints.

See also

On this page