PreCompact

PreCompact is a hook for Claude Code from ruvnet/ruflo. Its token cost is not measured, scanned A, original, MIT.

A pre-compaction hook that displays reminders and project guidance before the agent's context is shortened.

In plain words
What is it for?
It helps review project instructions and coordination details before manual or automatic context compaction.
Why use it?
It helps preserve awareness of available agents, coordination rules, workflows, and custom instructions during context reduction.

Hook for Claude Code

Part of the claude-flow plugin — 134 skills, 52 commands, 11 agents, 4 hooks shipped together

One of 4 entries in hooks.json — they are configured in one file and arrive together.

About the project

Ruflo is an execution and coordination layer for Claude Code and Codex that equips AI coding agents with tools, memory, control loops, sandboxes, and collaboration mechanisms. Developers use it to organize specialized agents into swarms, coordinate workflows, retain knowledge across sessions, and communicate across machines. The catalogue entries are Ruflo’s skills, commands, agents, hooks, and plugin components.

ruvnet/ruflo · 70,334 stars · on GitHub

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add hooks/ruvnet/ruflo/pre-compact
Clone the repo
git clone --depth 1 https://github.com/ruvnet/ruflo

Made for: Claude Code.

Or install claude-flow, the plugin that ships this one along with the rest of its 134 skills, 52 commands, 11 agents, 4 hooks.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for PreCompact

README.md
[![agentmods](https://agentmods.dev/badge/hooks/ruvnet/ruflo/pre-compact.svg)](https://agentmods.dev/hooks/ruvnet/ruflo/pre-compact)
Your own site
<a href="https://agentmods.dev/hooks/ruvnet/ruflo/pre-compact"><img src="https://agentmods.dev/badge/hooks/ruvnet/ruflo/pre-compact.svg" alt="Measured on agentmods" height="20"></a>
Per session not measured What this adds to a session before it is invoked.
When invoked not measured Not applicable: nothing here is loaded into a session.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Security

Grade A, and why

PreCompact scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the commands this hook runs, not an audit. A hook is shell that executes on your machine at the event it names, which is why every command in it is printed with what was found.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

Origin

Copies of this mod

8 near-identical copies found in the catalogue:

.claude-plugin/hooks/hooks.json · 22 lines

What it actually says

{
  "PreCompact": [
    {
      "matcher": "manual",
      "hooks": [
        {
          "type": "command",
          "command": "/bin/bash -c 'INPUT=$(cat); CUSTOM=$(echo \"$INPUT\" | jq -r \".custom_instructions // \\\"\\\"\"); echo \"🔄 PreCompact Guidance:\"; echo \"📋 IMPORTANT: Review CLAUDE.md in project root for:\"; echo \"   • 54 available agents and concurrent usage patterns\"; echo \"   • Swarm coordination strategies (hierarchical, mesh, adaptive)\"; echo \"   • SPARC methodology workflows with batchtools optimization\"; echo \"   • Critical concurrent execution rules (GOLDEN RULE: 1 MESSAGE = ALL OPERATIONS)\"; if [ -n \"$CUSTOM\" ]; then echo \"🎯 Custom compact instructions: $CUSTOM\"; fi; echo \"✅ Ready for compact operation\"'"
        }
      ]
    },
    {
      "matcher": "auto",
      "hooks": [
        {
          "type": "command",
          "command": "/bin/bash -c 'echo \"🔄 Auto-Compact Guidance (Context Window Full):\"; echo \"📋 CRITICAL: Before compacting, ensure you understand:\"; echo \"   • All 54 agents available in .claude/agents/ directory\"; echo \"   • Concurrent execution patterns from CLAUDE.md\"; echo \"   • Batchtools optimization for 300% performance gains\"; echo \"   • Swarm coordination strategies for complex tasks\"; echo \"⚡ Apply GOLDEN RULE: Always batch operations in single messages\"; echo \"✅ Auto-compact proceeding with full agent context\"'"
        }
      ]
    }
  ]
}
Same file

What else hooks.json configures

This page is one entry in a file that holds 4. Installing the file brings all of them; each is measured and scanned on its own page.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 22 lines scan A b5c120219ac0

Subscribe to this mod's changes

PreCompact is a hook published in the GitHub repository ruvnet/ruflo (70,334 stars, last pushed yesterday), licensed MIT. Its token cost is not measured: a hook is shell that never enters the context. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.