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.

Hooks are the reason you don’t need to learn 313 MCP tools or manually coordinate agents. After npx ruflo init, you just use Claude Code normally. The hooks system intercepts task boundaries, session events, and tool calls — automatically routing work, capturing successful patterns, and triggering background workers — all without requiring any explicit invocation on your part. The 27 hooks that ship with Ruflo cover the full lifecycle of a Claude Code session: from the moment a session starts, through every edit, command, and tool call, to final consolidation when the session ends.
Hooks are installed automatically by npx ruflo init. The .claude/settings.json file controls which hooks are active. Manual setup is only needed if you’re writing custom hooks or selectively disabling built-in ones.

Hook Categories

Task Hooks

Fire at the boundaries of individual tasks — the most important hooks for the learning loop:
HookWhen It FiresWhat It Does
pre-taskBefore any task beginsSearches memory for relevant past patterns; injects context into the agent
post-taskAfter a task completesCaptures the outcome; stores successful patterns to memory
task-completedWhen a task is explicitly marked doneTriggers pattern training; notifies the team lead in multi-agent mode

Model Routing Hooks

Power the intelligent 3-tier model router:
HookWhen It FiresWhat It Does
hooks_routeBefore any tool call that needs a modelSamples Beta(α, β) priors per tier; picks the cheapest tier that meets quality requirements
hooks_model-outcomeAfter a model call returnsUpdates the Beta prior for the chosen tier based on success/failure
hooks_model-routeDuring routing decisionLogs the routing decision and emits [TASK_MODEL_RECOMMENDATION] or [AGENT_BOOSTER_AVAILABLE] signals
After roughly 50 outcomes the Thompson sampling distribution self-corrects against tier overuse — no manual threshold tuning needed.

Session Hooks

Manage session-level context and state:
HookWhen It FiresWhat It Does
SessionStartAt the beginning of a Claude Code sessionLoads persisted memory; warms the agent pool; restores prior session context
session-endWhen the session closesFlushes memory; runs final consolidation; saves the RVF snapshot
PreCompactBefore context compactionDistils the current context window into memory to survive the compaction
UserPromptSubmitWhen the user submits a promptRuns the routing pre-check; injects relevant memory context

Tool Hooks

Intercept MCP tool calls:
HookWhen It FiresWhat It Does
tool:pre-callBefore any MCP tool executesValidates the call against the security layer; logs to the audit trail
tool:post-callAfter an MCP tool returnsCaptures tool output patterns; updates performance metrics

Teammate Hooks

Coordinate Claude Code’s experimental multi-agent teams feature:
HookWhen It FiresWhat It Does
hooks/teammate-idleA teammate finishes its turnAuto-assigns the next pending task from the shared task list
hooks/teammate-*Various teammate lifecycle eventsManages mailbox, inter-agent messaging, and shutdown coordination

12 Background Workers

Beyond the event-driven hooks, Ruflo runs 12 background workers on a schedule or triggered by context signals. Workers run automatically — you can also dispatch them manually:
WorkerAuto-Triggers OnPurpose
ultralearnNew project, major refactorDeep knowledge acquisition sweep across the codebase
auditSecurity-related file changesVulnerability scanning and CVE triage
optimizeSlow operations detectedPerformance suggestions and routing optimisation
consolidateSession end, memory thresholdMemory deduplication, tier promotion, pruning
mapNew directories, large file changesCodebase structure mapping
deepdiveComplex file editsDeep code analysis and context extraction
documentNew functions or classesAuto-documentation generation
refactorCode smell patternsRefactoring detection and suggestions
benchmarkPerformance-critical changesLatency and throughput benchmarks
testgapsCode changes without testsTest coverage gap detection
predictSimilar task seen beforePreloads likely resources based on pattern match
preloadCache miss on frequently accessed patternsResource preloading to warm the cache
# Manually dispatch a worker
npx ruflo@latest worker dispatch --trigger audit --context "./src"

# Check worker status
npx ruflo@latest worker status

How Hooks Power the Learning Loop

The hooks system is the mechanism through which Ruflo gets smarter over time:
1

pre-task fires

memory_search retrieves patterns from past sessions that match the current task. The agent starts with prior context rather than from scratch.
2

Task executes

The agent works. The hooks_route and hooks_model-route hooks manage model tier selection in real time, updating priors with each outcome.
3

post-task fires

If the task succeeded, the pattern is stored to memory with its embedding, tags, and quality score. The post-task hook also triggers the neural_train sweep if enough new patterns have accumulated.
4

Learning propagates

The stored patterns flow into ReasoningBank and PatternLearner. Next time a similar task arrives, pre-task retrieves a higher-quality match and the routing decision is better informed.

CLI Commands for Hooks

# Bootstrap learning from an existing codebase (run once on a new project)
npx ruflo@latest hooks pretrain

# Manually fire the task-completed hook (useful in CI pipelines)
npx ruflo@latest hooks task-completed --task-id <id> --train-patterns

# List all registered hooks and their current state
npx ruflo@latest hooks list
Additional hooks subcommands:
npx ruflo@latest hooks list      # show all hooks with descriptions
npx ruflo@latest hooks status    # show which hooks are currently active
npx ruflo@latest hooks enable    # enable a specific hook by name
npx ruflo@latest hooks disable   # disable a specific hook by name

MCP Hook Tools

The 33 MCP hook tools mirror the CLI surface, callable from Claude Code or any MCP client:
Tool GroupToolsDescription
hooks/pre-*hooks/pre-edit, hooks/pre-command, etc.Fire before write operations
hooks/post-*hooks/post-edit, hooks/post-command, etc.Fire after write operations; capture outcomes
hooks/routehooks_route, hooks_model-route, hooks_model-outcomeModel routing and outcome feedback
hooks/session-*hooks_session-start, hooks_session-end, etc.Session lifecycle management
hooks/task-*hooks_task-completed, hooks_pretrain, etc.Task boundary hooks and training triggers
hooks/teammate-*hooks_teammate-idle, etc.Multi-agent team coordination

Configuration

Hooks are controlled by .claude/settings.json in your project root. This file is created by npx ruflo init and contains the full hook registry:
{
  "hooks": {
    "pre-task": { "enabled": true },
    "post-task": { "enabled": true },
    "SessionStart": { "enabled": true },
    "session-end": { "enabled": true },
    "PreCompact": { "enabled": true },
    "UserPromptSubmit": { "enabled": true },
    "hooks_route": { "enabled": true },
    "hooks_model-outcome": { "enabled": true }
  },
  "workers": {
    "ultralearn": { "enabled": true },
    "audit": { "enabled": true },
    "testgaps": { "enabled": true }
  }
}
To disable a hook project-wide without removing it:
npx ruflo@latest hooks disable --name post-task
To write a custom hook, create a handler in .claude/hooks/ following the plugin hook API and register it in settings.json. Custom hooks receive the same event payload as built-in hooks and can call any MCP tool.

Build docs developers (and LLMs) love