agentreflex
Concepts

Events

The two lifecycle events a reflex can handle — onToolCall and onToolResult.

A reflex reacts to events from the agent. Each one arrives as a normalized context — the same shape across every agent, so a reflex you write once reads the same everywhere.

onToolCall

Fires before a tool runs. This is where a reflex decides: inspect the call, return pass, deny, or ask.

onToolCall(ctx) {
  // ctx.tool, ctx.command, ctx.paths, ctx.cwd, ctx.agent
  return { action: "pass" };
}

onToolResult

Fires after a tool runs. It can't block — use it for side effects like snapshots or audit logs.

onToolResult(ctx) {
  // ctx.tool, ctx.command, ctx.paths, ctx.cwd
}

The context

FieldDescription
agentWhich agent is acting (claude, cursor, gemini, …).
toolNormalized tool name (Bash, Edit, Write, Read, …).
commandThe shell command, when the tool is a shell.
pathsFile paths the tool would touch.
cwdThe project working directory.
rawThe original agent payload, untouched.

See the spec for the full types.

On this page