Hooks and triggers

Start agent work from a file change, a schedule, the end of a turn, or a script outside kcode.

A hook starts agent work when an event fires. Hooks are written in the project’s own config file, so a team shares them through the repository.

Turning hooks on

Hooks run under two conditions:

  1. Project hooks is on in Settings › Advanced, which sets hooks_enabled = true in ~/.kcode/config.toml.
  2. The project is trusted. The trust dialog lists the project’s hooks by name.

A hook

Each [[hooks]] table in <project>/.kcode/config.toml is one hook:

[[hooks]]
name = "retest"
on = "fs:file-changed"
filter = "src/**/*.rs"
prompt = "A source file changed. Run its tests and report failures."
concurrency = "replace"   # drop | queue | replace | parallel

[[hooks]]
name = "morning-triage"
on = "timer:cron"
schedule = "0 0 9 * * 1-5"
run = "/triage"
session = "title:triage"  # active | new | title:<t>

A hook either sends a prompt to the agent or runs a command or a skill with run. session picks the session that does the work.

Events

on Fires when
fs:file-changed A file that matches filter changes.
timer:cron The schedule comes due. The schedule has six fields, and the first is seconds.
app:turn-finished A turn ends. app:turn-started and app:turn-error are the other turn events.
worktree:create A worktree is made. worktree:remove fires when one is removed.
webhook:<name> A trigger of that name arrives from outside kcode.

Triggers from a script

kcode trigger fires a webhook: hook from CI, cron or any shell, and hands it a line of text:

[[hooks]]
name = "deploy-done"
on = "webhook:deploy-done"
prompt = "A deploy finished: {{text}}. Check the health endpoint and summarize the release."
session = "title:release"
kcode trigger deploy-done "Build 812 is live on staging" \
  --project ~/code/app \
  --session "release"

The text takes the place of {{text}} in the prompt. With hooks off, or with no open session of that title, the trigger runs nothing, says why, and exits 1.

Limits

kcode holds each hook to rate limits of its own. A fire that a limit drops adds a notice that names the hook and the limit. [triggers_framework.rate_limits] in ~/.kcode/config.toml sets the limits.

Beyond hooks

A hook reacts to an event with a prompt. A plugin reacts with code: it watches the same events, and it can change or refuse a step inside the agent loop. The events reference lists every event.

Product video