Expand description
Shared accounting for the rules files an agent auto-loads each session.
A “rules file” (CLAUDE.md, AGENTS.md, .cursor/rules/*.mdc, …) is injected
into every session as fixed context — it costs tokens before lean-ctx saves
anything. This module enumerates those files, attributes the lean-ctx-owned
share of each, and flags clients that load the same guidance more than once.
Used by lean-ctx doctor overhead (fixed-cost board) and lean-ctx tools health (token-budget / rot report, #848). Lives in core so neither caller
has to depend on the other.
Structs§
- Duplicate
Channel - One host whose session receives lean-ctx rules (the tool mapping) through more than one channel (A3: exactly one channel per host).
- Rules
File Cost - One rules file a client auto-loads into context.
Functions§
- collect_
rules_ files - Collects every rules file that an agent auto-loads for work in
project: global per-client files, the project root, and the parent chain up tohome(Cursor merges parent.cursor/rules/and AGENTS.md in monorepos). - duplicate_
channels - Hosts that load the lean-ctx rules block more than once per session:
several auto-loaded files carrying it, or one such file plus the full
MCP instructions skeleton (the server only collapses it to the anchor
when the host’s canonical carrier holds the block,
rules_channel::client_autoloads_rules).instruction_tokens_forprices the skeleton a client receives (doctor passes the live builder). - duplicate_
clients - Clients that auto-load more than one file carrying a full lean-ctx payload — the same guidance billed multiple times per session (#578/#684).