Repository navigation
v0.40.0 — the injection, the start-up path, the guard messages, the docs and the rules pack, slimmed
The injection, the start-up path, the guard messages, the documentation and
the rules pack, slimmed and put in order. Five concerns after v0.39.2, one
commit each, from a cloud session; a sixth, found the moment the branch ran on
the maintainer's own Windows machine, is recorded below (b07430d). No hook's
enforcement semantics change: what is denied, blocked, forgiven or recorded is
byte-identical, and every rewrite below is pinned by a test that says so.
Prompt injection: a contract and a reminder, not two contracts
prompts/user-prompt.md was 7,075 characters — larger than the SessionStart
contract it was meant to remind of, two thirds of it restating that contract
verbatim — and it was re-sent on every prompt, so a fifty-turn session carried
fifty copies of it until compaction. The premise that justified the copy
("re-inject every turn so the rules survive compaction") had been overtaken:
SessionStart fires again after every compaction (source: compact) and
hooks.json registers it without a matcher, so the contract already came back.
The per-turn prompt is now a 2.6k-character reminder (1.5k in Chinese) that
names every hard gate, every Stop layer, the reply-schema field names, the tldr
cap and the sync-check semantics, and nothing else. What left it was
duplication, eleven version tags, and six "consequence" rows describing blocks
the hooks never issue. tests/test_inject_context.py now derives the tokens the
reminder must carry from the guards themselves (STATIC_PATTERNS slugs,
PATCH_MARKERS labels, _LAYER_IDS, TLDR_MAX_ITEM_COLUMNS, the rolling
threshold, the schema fields, every advertised hedge against _HEDGE_INNER) and
caps its size, so it can neither lose a gate nor grow back into the contract.
session-start.md is the single authority: its §4 no longer links a
CLAUDE.md this repository stopped tracking in v0.38.2 (and the test waivers
that covered the link are gone), the "9-layer" row names the layers (a)–(f) it
lists, the operator-only CC_ENFORCER_DISABLE_LAYER_G switch is no longer shown
to the agent, %USERPROFILE% joins the rule-11 row in English, and the
sync-gate row says what actually settles a group. The per-turn edict table
drops the intro and footer sentences the contract already carried
(render_injection(chrome=False)), and the realistic-install budget test now
covers all four prompts, not two.
Runtime: every hook loads only what its common path uses
Measured on Linux / Python 3.11 before the change, a bare interpreter cost
13 ms and every hook 63–81 ms. The difference was modules imported at start-up
for work the common path never does, plus stop_guard compiling ~115 regexes
up front — 31 of the 33 ms its import took, on a path that mostly returns after
the done-claim check.
| scenario | own share before | after |
|---|---|---|
UserPromptSubmit (every prompt) |
≈ +50 ms | +19 ms |
PreToolUse(Read) |
+53 ms | +27 ms |
PreToolUse(Bash) |
+50 ms | +21 ms |
Stop (all nine layers) |
+68 ms | +33 ms |
inject_context:argparse(and theshutil/bz2/lzmabehind it)
replaced by a five-line--eventparser with the same exit-2 contract;
lib.state,lib.envfileandgc_stateimported inside the SessionStart
maintenance branch; the payload parsed only when auto-GC can use the session
id; thefrom . import gc_statebranch that could never succeed removed.lib/tomlioimportstomllibon first parse;edictsandsync_gatedrop
their own sentinels and asktomlio.available()only once a config file
exists, so a project without one never loads the parser.Edict/EdictHitandGroup/Violationare__slots__classes
instead of frozen dataclasses (dataclasses→inspect/ast/dis,
~10 ms per hook);mdctx.LineCtxis acollections.namedtuple.tracebackis imported inside the failing-open handlers;bash_guard
importshashlibandlib.stateon the registration path only;
stop_guardimportslib.sync_gatewhen layer (i) runs.stop_guardcompiles each pattern the first time a layer uses it
(_LazyPattern); a Stop with no done-claim compiles the done set and nothing
else, and the lazy object answers exactly whatre.compilewould.stop_guardreadslast_assistant_message— the field Claude Code's Stop
payload documents — before the legacyassistant_messageand the transcript
fallback. Production had been taking the fallback on every Stop because the
documented field was never read; the fallback's first window is now 256 KiB
(×16 growth) instead of 4 MiB.bash_guardtokenises a command once;state.record_edit_turnsaves only
when the flag or turn changes;lib/lang.pyis the one definition of the
active language (three copies before);projrootownsPLUGIN_NAMEand the
.claude/cc-enforcer/<file>layout;stateownsAUTO_GC_MARKER.bench_hooks.pygains the two injection scenarios, measures an allowed
systematic Edit and a Stop on an edit turn (all nine layers live — the old
Edit row measured the deny path and the old Stop row a non-edit turn), and
aborts on a non-zero exit or unexpected output.
tests/test_startup_cost.py pins the property rather than the milliseconds.
Guard messages say what the hooks do
Three deny / block texts told the agent something the hooks do not do: the
block footer promised a one-shot grace ("the next Stop is allowed even if this
layer still fails") that v0.29 had replaced with per-layer grace; recovery (a)
and (c) offered re-trigger / boundary case / negative case as passing
markers, none of which is in the English evidence or convergence sets; and the
rolling-patch recovery advised padding an edit to ten lines to clear the
small-edit bar — the accretion the gate exists to catch. Each now names what
passes. The six longest messages are cut to headline, evidence and recovery;
version tags inside them are gone; the force-push deny text joins the catalog
so it follows CC_ENFORCER_LANG. Chinese catalog mirrored key for key; the demo
image re-rendered.
Design conflicts closed
i18n_check, edicts and inject_context no longer cite the untracked
CLAUDE.md; sync-gate.toml and docs/EDICTS.md point at sections that
exist; the Python floor is stated once as 3.11 (tomllib) with CI on 3.13;
both manifest descriptions are a 923-character product description instead of a
5.4k-character rolling changelog; the three _PLUGIN_NAME / tomllib sentinel
/ _resolved_lang copies are one definition each.
Documentation reorganised
docs/ARCHITECTURE.md (80k characters, 158 version references, every
subsection nested under "The injection budget", the Stop guard ordered by
release) is rewritten by component at ~41k: one subsection per hook, the Stop
decision table in evaluation order with the markers grouped by layer, per-layer
grace described for the first time, the shared modules, session state and the
configuration files each in one place, the data flow including Stop, and a
sorted, deduplicated connected-files map. README.md drops its release
narrative and its duplicated principles; Contributing and the release checklist
move to docs/CONTRIBUTING.md; docs/RULES.md is a catalog again;
docs/README.md no longer claims the documents never repeat each other;
tests/README.md is an inventory with live counts. History lives in this file.
The rules pack states the discipline; one line per rule states the hook
rules/ is presented as a portable, LLM-agnostic discipline pack, and a fifth
of it was hook implementation: rule 09 alone carried a 10k-character "Physical
interception" section — the rolling-patch classifier table, the patch-marker
regex catalogue, the detector-fix history from v0.25 to v0.26 — and rules 03,
08, 10, 11 and 12 carried their own hook tables and 55 version notes between
them. Every rule now opens with one Enforced by line under its title, in
both languages, that says which hook intercepts it and on what (rule 09's names
the seven Bash tokens; the doc gate now pins rule 03's line to the same
inventory), and the hook sections and version notes are gone. Facts corrected
on the way: rule 08 no longer counts global among layer (e)'s keywords or
describes the trigger as a turn-count comparison; rule 09's "1–3 lines" is the
hook's ≤ 10-line bound; rule 10's "10+ chars" is the detector's 8; rule 11
names CLAUDE_PLUGIN_DATA (not CC_PLUGIN_DATA) and no longer quotes a
maintainer's home path; rule 12 describes per-layer grace instead of the
retired one-shot guard; "minimum effective change" is defined once, in rule 07
check 4, where six sites already pointed. The English pack goes from 87.9k to
78.5k characters (rule 09: 21.5k → 13.8k) and the Chinese mirror from 42.3k to
37.1k, with identical heading sequences and the same enforcement tokens.
commands/checklist.md (9.4k → 6.7k characters) keeps its eight sections, the closed
patch-marker set, the output format and the items with no rule-text
counterpart, and stops restating the rules and the prompts; its description
now counts eight sections, and its example reads "layer (a)–(i)".
Two test premises that held everywhere except on the machine the plugin was written on
Running this branch on the maintainer's Windows machine gave five failures on
a suite that was green in the cloud and would have been green on CI. Both
causes are a test taking ambient machine state for an empty room — the
v0.38.3 class (a test that encoded the maintainer's directory layout),
pointing the other way. Neither is a hook defect; both are fixed in the
test, by changing the gate's mechanism rather than adding the offending name
to a list.
tests/test_doc_sync.pyenumerated "the repository's documents" by walking
the working tree, with three skip lists of directory names (.git,.ce,
memory,node_modules,__pycache__,.pytest_cache— no two lists
alike, each name a past incident patched by name). Another plugin keeps 21
ignored markdown files under.ccm/on this machine, so the identifier
check citedE01andIGNORECASEout of session notes and the
language-registry check demanded 21 files be registered. Every enumeration
now asksgit ls-filesonce and derives from that: the identifier scan,
the Python definitions it resolves against, the structure-tree ghost check,
the language registries and the link resolver — which resolves targets
against the index too, so a link that works only because an ignored file
happens to be on this disk fails here exactly as it would in a clone, and
the by-nameCLAUDE.mdexception of v0.38.2 becomes a consequence of the
rule instead of a special case._trackedraises when git lists nothing,
because an empty document set passes every scan; a twin plants an
untracked file inside the repository and requires every scanner to be
blind to it.tests/test_startup_cost.py(new in this release) built its subprocess
environment from the real one, HOME included.edicts.global_path()is
Path.home()plus.claude/cc-enforcer/edicts.toml, and this machine keeps
one, sobash_guardand both injection paths loadedtomllibfor a config
that genuinely exists, and the gate called that a regression.setUpnow
points HOME and USERPROFILE at the empty temporary project, the isolation
test_edicts.pyalready used; a twin writes anedicts.tomlinto a home
the test controls and requirestomllibto appear, so the negative checks
are known not to be vacuous and the home the hooks consult is known to be
the one the test sets.
Decisions recorded, not made
收敛/重触发/边界用例/反向用例count as evidence for layer (a) as
well as convergence markers; their English counterparts are markers only, so a
Chinese收敛:schema key passes layer (a) on its own. Narrowing the evidence
set is a strictness increase for Chinese replies; documented inI18N.mdand
ARCHITECTURE.md§2.5, left to the maintainer.- The four entry scripts run as
__main__and are recompiled on every call
(1.6–5.8 ms each); a shim that moved their bodies underlib/would cache the
bytecode at the cost of the documented four-entry-point layout. Not done. CHANGELOG.mdcarries two## [0.11.0]headings (the first is a roadmap
note recorded at the time); left as history.