Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/ruvnet/ruflo/llms.txt

Use this file to discover all available pages before exploring further.

ruflo hooks is the command surface for Ruflo’s self-learning lifecycle system. Hooks fire before and after every tool use, session boundary, and task lifecycle event in Claude Code, feeding outcomes back into the ReasoningBank and SONA router. Over time the system learns which agents perform best for each task type, which file patterns carry risk, and which command sequences tend to fail — all without any manual tuning.

Synopsis

ruflo hooks <subcommand> [options]

Subcommands

SubcommandDescription
pretrainBootstrap the ReasoningBank from existing codebase patterns
listList all registered hooks and their enabled/disabled state
metricsShow the learning metrics dashboard
routeRoute a task description to the optimal agent using learned patterns
explainShow transparent reasoning behind a routing decision
pre-editGet context and agent suggestions before editing a file
post-editRecord an editing outcome to the learning pipeline
pre-commandAssess risk before executing a shell command
post-commandRecord a command execution outcome
pre-taskRecord task start and request agent suggestions
post-taskRecord task completion for pattern learning
session-endEnd the current session and persist state
session-restoreRestore a previous session snapshot
task-completedSignal task completion and optionally train patterns (Agent Teams)
teammate-idleAuto-assign pending tasks to an idle teammate (Agent Teams)
model-routePreview which LLM tier (Haiku/Sonnet/Opus) would handle a task
model-outcomeRecord a model routing outcome to update Beta priors
model-statsView Thompson sampling model routing statistics
notifyLog a notification message to the session store
workerManage background workers (12 available)
build-agentsGenerate optimized agent configurations from learned patterns
intelligenceManage the RuVector intelligence subsystem
statuslineGenerate the dynamic shell statusline display
coverage-routeRoute tasks based on test coverage gaps
coverage-suggestSuggest coverage improvements for a file
coverage-gapsList all coverage gaps with recommended agents
token-optimizeApply the agentic-flow token optimization pipeline

Hook events

The following hooks are wired into Claude Code’s settings.json by ruflo init:
Hook nameClaude Code eventPurpose
PreToolUseBefore any tool callRisk assessment, agent context lookup
PostToolUseAfter successful tool callPattern learning from outcomes
UserPromptSubmitOn prompt submissionTask routing via hooks_route
SessionStartSession initializationWarm up ReasoningBank, restore state
StopTask completionEvaluation, quality scoring
NotificationClaude Code notificationLog to session memory
PermissionRequestTool permission promptAuto-allow Ruflo tools
PreCompactBefore context compressionSave session snapshot
tool:pre-callBefore MCP tool callLogging and validation
tool:post-callAfter MCP tool callOutcome recording
All hooks are dispatched through .claude/helpers/hook-handler.cjs, which is written by ruflo init and ruflo init hooks.

pretrain

Scan the current repository and bootstrap the ReasoningBank with patterns extracted from existing code, tests, and documentation. This is the recommended step after init to give the routing system immediate context rather than starting from scratch.
ruflo hooks pretrain [options]
After pretraining, hooks metrics will show a non-zero pattern count and the hooks route command will produce grounded recommendations.
Rerun ruflo hooks pretrain whenever you onboard Ruflo into an existing codebase or after a major architectural change. The command is additive — it does not wipe existing patterns.

list

Show all hooks registered in the current project along with their enabled/disabled state, last run time, and run count.
ruflo hooks list [--format json]

metrics

Display the full learning metrics dashboard including pattern counts, routing accuracy, model routing statistics, and Flash Attention performance.
ruflo hooks metrics [--v3-dashboard]
--v3-dashboard
boolean
default:"false"
Show the extended V3 dashboard with Flash Attention benchmarks, AgentDB integration metrics, and token reduction stats.

route

Ask the routing system which agent type should handle a given task, using learned patterns from the ReasoningBank.
ruflo hooks route --task "<description>" [options]
--task / -t
string
required
Natural language task description. Can also be passed as the first positional argument.
--context / -c
string
Additional context (e.g. file path, language, domain) to improve routing accuracy.
--top-k / -K
number
default:"3"
Number of alternative agent suggestions to return alongside the primary recommendation.
The output shows the primary recommended agent with confidence percentage and reason, a table of alternatives, and estimated success probability, duration, and complexity.

explain

Get a transparent, step-by-step explanation of how the routing system would decide on an agent for a given task.
ruflo hooks explain --task "<description>" [options]
--task / -t
string
required
Task description.
--agent / -a
string
Explain why (or why not) a specific agent type would be chosen.
--verbose / -v
boolean
default:"false"
Include the full list of matched patterns with examples.

pre-edit

Retrieve context — related files, learned patterns, potential risks, and agent suggestions — before editing a file.
ruflo hooks pre-edit --file <path> [options]
--file / -f
string
File path about to be edited.
--operation / -o
string
default:"update"
Type of edit: create, update, delete, or refactor.
--context / -c
string
Free-text context about the intent of the edit.

post-edit

Record the outcome of a file edit. The result feeds back into the pattern learner and adjusts confidence scores for the patterns that were matched in the preceding pre-edit call.
ruflo hooks post-edit --file <path> --success <true|false> [options]
--file / -f
string
File that was edited.
--success / -s
boolean
default:"true"
Whether the edit produced the desired outcome. Defaults to true to match PostToolUse semantics.
--outcome / -o
string
Description of what happened (e.g. "Type error on line 42").
--metrics / -m
string
Comma-separated key:value performance metrics (e.g. "time:500ms,quality:0.95").

pre-command

Assess the risk of a shell command before it executes. Returns a risk level (low/medium/high/critical), a list of identified risks, and safe alternative suggestions.
ruflo hooks pre-command --command "<cmd>" [--dry-run]
--command / -c
string
required
The shell command to analyze.

post-command

Record the outcome of a command execution to update command-pattern risk models.
ruflo hooks post-command --command "<cmd>" --success <true|false> [options]
--command / -c
string
required
The command that was executed.
--success / -s
boolean
default:"true"
Whether the command exited successfully.
--exit-code / -e
number
default:"0"
The numeric exit code.
--duration / -d
number
Execution duration in milliseconds.

task-completed

Signal that a task is done, optionally train patterns from it, and notify the team lead (Agent Teams integration).
ruflo hooks task-completed --task-id <id> [options]
--task-id / -i
string
required
ID of the completed task.
--train-patterns / -p
boolean
default:"true"
Train the neural pattern store from this task’s trajectory.
--notify-lead / -n
boolean
default:"true"
Notify the team lead agent of the completion.
--success / -s
boolean
default:"true"
Whether the task completed successfully.
--quality / -q
number
Optional quality score between 0 and 1.
--teammate-id / -t
string
ID of the teammate that completed the task.

notify

Log a notification message to the session memory store at a given severity level.
ruflo hooks notify --message "<msg>" [--level info|warn|error]
--message / -m
string
required
Notification text.
--level / -l
string
default:"info"
Severity: info, warn, or error.

Examples

# Scan the repo and build the initial pattern store
ruflo hooks pretrain

# Check pattern counts after pretraining
ruflo hooks metrics
The Thompson sampling model router (model-route / model-outcome) uses cost-adjusted multi-armed bandit logic. After approximately 50 outcome events, the router self-corrects against tier overuse without any manual threshold tuning. Each route call costs ~45 µs.

Build docs developers (and LLMs) love