Skip to main content

Module rules_overhead

Module rules_overhead 

Source
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§

RulesFileCost
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 to home (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-ctx or the canonical rules marker and ends at <!-- /lean-ctx... --> (inclusive). Files without markers contribute 0 lean-ctx tokens (they still cost their full size).