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§
- 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_
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).
- lean_
ctx_ block_ tokens - Tokens of the lean-ctx-owned portions of a rules file: every block that
starts at a line containing
<!-- lean-ctxor the canonical rules marker and ends at<!-- /lean-ctx... -->(inclusive). Files without markers contribute 0 lean-ctx tokens (they still cost their full size).