bc-knowledge-manager
Caution
KNOWLEDGE.jsonl grows with every task. Duplicate entries, similar patterns across different wordings, and low-priority noise accumulate quickly — the file bloats, compaction at handoff slows, and the most important ❌ entries get buried. The pre-compact.mjs hook fires before every auto-compact, but it can’t help if the file is already in poor shape.
Tip
bc-knowledge-manager runs automatically. The bc-coordinator spawns it before handoff and whenever duplicates are reported. You can also trigger it manually via Task tool with an explicit knowledgePath and mode. It never loses ❌ entries unless they are exact duplicates.
Quick reference
| Field | Value |
|---|---|
| Model | haiku |
| Tools | Read, Write |
| Permission mode | acceptEdits |
| Spawned by | bc-coordinator (via Task tool) |
| Triggers | Before handoff, when duplicates reported by coordinator |
When to use
- Before a session handoff — compact KNOWLEDGE.jsonl so the next session starts with a clean, prioritized file
- After
/brewcode:rulesexport — runprune-rulesmode to strip ❌/✅ entries that have been promoted to rules files - When coordinator reports duplicates — deduplicate-only pass with
mode: dedupeto keep the file clean mid-task - When the file exceeds 100 entries — full compaction removes excess, prioritizing ❌ over ✅ over ℹ️
Examples
# KNOWLEDGE.jsonl entry format
{"ts":"2026-04-17T10:00:00Z","t":"❌","txt":"Avoid SELECT * in queries — causes N+1 on large tables","src":"developer"}
{"ts":"2026-04-17T10:01:00Z","t":"✅","txt":"Use Read then Write (not Edit) for full file rewrites","src":"bc-coordinator"}
{"ts":"2026-04-17T10:02:00Z","t":"ℹ️","txt":"Project uses PostgreSQL 15 with pgvector extension","src":"architect"}
# Spawn via Task tool (full compaction)
Task: bc-knowledge-manager
Prompt: knowledgePath=/abs/path/.claude/tasks/20260417_example_task/KNOWLEDGE.jsonl mode=full maxEntries=100
# Output
Knowledge compaction complete:
- Before: 134 entries
- After: 87 entries
- Removed: 12 duplicates, 21 merged, 14 truncated
- By type: ❌ 31, ✅ 28, ℹ️ 28
- Size: 18420 bytes
# Prune after rules export (prune-rules mode)
Task: bc-knowledge-manager
Prompt: knowledgePath=/abs/path/KNOWLEDGE.jsonl mode=prune-rules
# Output
Pruned 59 entries (❌/✅), kept 28 entries (ℹ️)
Flow
- Read
Reads KNOWLEDGE.jsonl at
knowledgePath. File not found or empty — reports and exits without writing. - Parse
Parses every line as JSON. Malformed lines are skipped and counted separately — they do not halt processing.
- Deduplicate & merge
Removes entries with identical
txt. Then merges entries whosetxtmatches case-insensitively on the first 100 characters — keeps the higher-priority type (❌ wins over ✅ wins over ℹ️). - Sort & truncate
Sorts by priority (❌ → ✅ → ℹ️), then by timestamp descending. If the entry count exceeds
maxEntries(default 100), lowest-priority and oldest entries are dropped first. ❌ entries are never removed unless they were exact duplicates. - Write
Rewrites the file using Read then Write (never Edit). One valid JSON object per line, original timestamps preserved.
- Report
Returns a statistics block: before/after counts, removed breakdown (duplicates / merged / truncated), by-type counts, and final file size in bytes.
Priority & dedup rules
Entry types (priority order)
| Type | Priority | Meaning |
|---|---|---|
❌ | 1 — highest | Avoid: mistakes, failures, known anti-patterns |
✅ | 2 | Best practice: what works reliably |
ℹ️ | 3 — lowest | Info: neutral facts, architecture notes |
Dedup matching
Exact match on txt field → remove the lower-priority copy (or older if same priority).
Similar match on first 100 characters of txt (case-insensitive) → merge into one entry, keep higher-priority t value and newer ts.
Merge mode: prune-rules
After /brewcode:rules exports ❌/✅ entries to .claude/rules/ files, run prune-rules to strip them from KNOWLEDGE.jsonl. Only ℹ️ entries survive. This prevents double-loading the same knowledge as both KNOWLEDGE and rules.
Rules frontmatter note
When rules are exported via /brewcode:rules, use paths (array of glob strings) in frontmatter — globs and alwaysApply are not supported. Rules without paths load always; path-specific rules should load lazily (Bug #16299 causes all to load at session start regardless).
bc-coordinator
Spawns bc-knowledge-manager before handoff and after duplicate reports.
brewcode:start
Infinite execution skill — triggers compaction via pre-compact.mjs hook at context limit.
GitHub source
Agent definition and compaction logic.
Brewcode overview
All brewcode skills, agents, and hooks in one place.
Updating plugins
/brewtools:plugin-update to check and update the brewcode plugin suite in one command.
See the FAQ for details.