Artifact 4099db10bf9755885a78515bbb5b40a5c7fce07ea936734964167419de47bb54:
- Executable file
tools/rule_redundancy.sh
— part of check-in
[35bb724e4f]
at
2026-11-19 17:07:11
on branch rule-redundancy
— Reduce rule redundancy: covered-by-global retirement, identical-copy collapse, global-rule offers, restore
A benchmark on real rules found reworded duplicates inside a project are rare; the redundancy is project rules that restate the global CLAUDE.md, identical copies, and one rule saved in several projects.
- ctx rules restore KEY undoes any retirement or replacement, and neither automatic check retires that rule again while its text and the global text are unchanged. - Identical copies in one project collapse after each import (frontmatter and spacing ignored); a copy comes back when the rule it was collapsed into leaves force. - ctx rules covered sends active project rules to the automatic judge in bounded batches and retires one only with a verbatim quote of at least 20 characters from the global CLAUDE.md; the rule comes back when the quote leaves the global text, and a verdict is skipped if the rule changed during the call. - The decisions page offers groups of the same rule in several projects as one global rule; make global acts only on the listed keys, needs two projects, and refuses CLAUDE.md, AGENTS.md, global rules and rules with an until date. - ctx rules activity lists collapses, covered retirements and restores. tools/rule_redundancy.sh reports what each step would do on a copy of an archive.
On a copy of the live archive: 380 active rules, 3 retired as covered, 0 identical copies, 10 cross-project groups offered. (user: dmestas, size: 1296) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # Reports how much of an archive's rules the automatic clean-up would touch, changing nothing: # rules in force, identical copies a rules import would collapse, rules the covered check would # send to the judge, and groups of the same rule saved in several projects. # # cp ~/.ctx/ctx.sqlite /tmp/copy.sqlite # with ctx not running # CTX_DB=/tmp/copy.sqlite tools/rule_redundancy.sh # # The global CLAUDE.md is the rule keyed under CLAUDE_CONFIG_DIR, else ~/.claude, as for ctx. set -eu CTX=${CTX:-ctx} [ -n "${CTX_DB:-}" ] || { echo "rule_redundancy: set CTX_DB to a scratch copy of the archive" >&2; exit 2; } [ -n "${HOME:-}" ] && [ "$CTX_DB" -ef "$HOME/.ctx/ctx.sqlite" ] && { echo "rule_redundancy: CTX_DB is the live archive; use a copy" >&2; exit 2; } export CTX_DB echo "active rules: $("$CTX" sql "SELECT count(*) FROM ctx_doc WHERE kind = 'rule' AND status IS NULL")" echo "identical copies to collapse: $("$CTX" rules collapse --dry-run | sed -n 's/^\([0-9]*\) identical cop.* would collapse$/\1/p')" echo "rules to send to the covered check: $("$CTX" rules covered --dry-run | sed -n 's/^\([0-9]*\) rules would be sent.*/\1/p')" echo "groups of the same rule in several projects: $("$CTX" rules same | sed -n 's/^\([0-9]*\) groups\{0,1\} of the same rule.*/\1/p')"