refactor(claude): global context diet — 148.6 KB → 99.0 KB always-loaded, budget test, hook noise fixes#300
Merged
Conversation
Claude Code creates these runtime files at the top level of ~/.claude. Unlisted top-level entries in the exact_ tree are deleted on chezmoi apply, so register them before they get silently removed. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy
Seven rules in exact_dot_claude/rules/ (~28 KB) were loaded globally in every session but only apply when working in this repo. Move them to the project-scoped .claude/rules/ so other projects stop paying the context cost: - chezmoi-conventions.md (17 KB — global sessions keep the CLAUDE.md one-liner and the chezmoi-expert skill) - testing.md, shell-completions.md, development.md, document-management.md, zshrc-keybindings.md, fzf-picker-colorize-align.md Split dependency-management.md: the Homebrew profile and MCP server registry sections (backed by .chezmoidata) move to the new repo rule package-registries.md; the cross-project mise guidance stays global. Add paths: frontmatter to three global rules that only matter for specific file types (zsh-pattern-expansion-extended-glob, docker-build-context, rustfmt-gate-onboarding) so they lazy-load. Update the chezmoi guard hooks and tui-keybinding rule to point at the new chezmoi-conventions.md location. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy
Pin the always-loaded global Claude context so repo-specific or bloated rules can't silently re-accumulate in exact_dot_claude/ after the PR #300 cleanup. Four checks: - Total budget: unconditional rules + CLAUDE.md <= 160 KB (baseline 148.6 KB at introduction; ratchet down as cleanups land) - Per-file cap: no unconditional rule over 10 KB (chezmoi-conventions hit 17 KB before it was migrated out) - Repo-specific markers: .chezmoidata / dot_zshrc / mise run lint / etc. in a global rule fail unless consciously allowlisted - Frontmatter validity: path-scoped rules must declare a non-empty paths: list with a closed frontmatter block Wired as a pre-commit local hook (runs in CI via pre-commit run --all-files in smoke.yml) and as mise task test:context-budget, added to the test task's depends. Red-path verified with canary fixtures: all four checks fail on injected violations. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy
Contributor
|
| Status | Count |
|---|---|
| 🔍 Total | 163 |
| ✅ Successful | 153 |
| ⏳ Timeouts | 0 |
| 🔀 Redirected | 0 |
| 👻 Excluded | 9 |
| ❓ Unknown | 0 |
| 🚫 Errors | 1 |
Errors per input
Errors in docs/adrs/0013-nixos-declarative-system-configuration.md
- [ERROR] https://nixos.org/manual/nixos/stable/ | Failed: Network error: error sending request for url (https://nixos.org/manual/nixos/stable/)
Full Github Actions output
Please fix the broken links before merging.
…s-loaded Second wave of the context diet (audit via meta-context-diet): - Capture ~/.claude/rules/verify-machine-facts-before-publishing.md into source — it was written directly to the target, loading every turn while invisible to the source tree and the budget test. - Merge the six git merge-hazard rules (branch-merge-detection, branch-from-pushed-main, stacked-pr-merge-order, squash-merge-orphans, textual-merge-duplicates, git-add-atomic-pathspec; 21.3 KB) into one distilled git-hazards.md (4.7 KB): per-hazard invariant + check + fix; narratives live in git history. - Merge taskwarrior-tracking + taskwarrior-cross-session (near-duplicates) into one taskwarrior-tracking.md. - Path-scope claude-code-auto-mode.md and claude-plugins-freshness.md to settings-file globs (12.4 KB off the unconditional surface). - Distill to their invariants, pointing at the plugin skills that own the full playbooks: diagrams (d2-diagrams skill), disk-full-recovery (macos-disk-usage), telegram-communication (telegram skill), kitty-agent-interaction, mise-stale-tool-copies, orbstack-gui-quit (macos-plugin skills), development-process (blueprint/testing plugins). - Drop private_reporters.md (testing-plugin skills encode reporter flags) and dependency-management's install-priority list (verbatim duplicate of CLAUDE.md — now a pointer). - Ratchet the budget test: 160 KB → 110 KB against the new 98,956-byte baseline; swap the marker allowlist entry to git-hazards.md. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy
…ebounce Two per-turn noise sources found while auditing hooks: - chezmoi-drift-guard matched `*chezmoi*apply*` as a substring over the whole command, so git commits and gh pr edits whose message text merely mentioned "chezmoi apply" triggered the heads-up on nearly every call. Anchor the match to an actual chezmoi invocation (line start or after ;|&|`|$() and name the drifted files in the message so it's actionable (verified: commit-message and PR-body mentions no longer fire; real apply invocations, bare or chained, still do). - chezmoi-workflow-nudge repeated the identical reminder on every Edit/Write under exact_dot_claude/ (nine copies in one session). Add a per-class stamp-file debounce (default 30 min, CHEZMOI_NUDGE_DEBOUNCE_SECS to override). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy
This was referenced Jul 4, 2026
[Feature] tools-plugin: promote huggingface-downloads rule to a skill
laurigates/claude-plugins#1966
Closed
laurigates
added a commit
that referenced
this pull request
Jul 5, 2026
…301) ## What Session distill from the #300 context diet: document in `.claude/rules/chezmoi-conventions.md` that **non-`exact_` subdirs neither purge orphaned targets nor flag them** — the flip side of the existing per-directory-level note. - Moving/deleting a source file out of `exact_dot_claude/rules/` leaves the old target orphaned in `~/.claude/rules/`, still loading into every session, with **no `D` line in `chezmoi status`** to reveal it. Manual target cleanup + `chezmoi source-path` verification documented. - The inverse leak too: a rule created directly in the target is never captured to source and silently loads forever — includes the unmanaged-file sweep one-liner. Both directions bit during the #300 diet (7 orphaned targets after the wave-1 moves; one 4.7 KB unmanaged rule found loading invisibly). ## Why not in #300 The commit was authored on the #300 branch during session wrap-up, but the PR had already been squash-merged — pushing would have orphaned it (hazard #2 in the freshly consolidated `git-hazards.md`, fittingly). Cherry-picked onto a fresh branch from `origin/main`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
laurigates
added a commit
that referenced
this pull request
Jul 5, 2026
…302) ## Summary Continues the global context diet (#300). The full content of four always-loaded rules has been promoted into claude-plugins skills that load on intent; each rule shrinks to a pointer stub naming its skill. | Rule (stubbed) | Skill | Tracking | |---|---|---| | `taskwarrior-bulk-operations.md` | `taskwarrior-plugin:task-bulk-ops` | laurigates/claude-plugins#1964 / laurigates/claude-plugins#1981 | | `tui-keybinding-terminal-interception.md` | `macos-plugin:tui-keybinding-debug` | laurigates/claude-plugins#1965 / laurigates/claude-plugins#1984 | | `huggingface-downloads.md` | `tools-plugin:hf-downloads` | laurigates/claude-plugins#1966 / laurigates/claude-plugins#1982 | | `bulk-syntax-sweep-classify-matches.md` | `code-quality-plugin:bulk-sweep-classify` | laurigates/claude-plugins#1967 / laurigates/claude-plugins#1986 | Cross-references updated in the same pass: `disk-full-recovery.md` now points at the `hf-downloads` skill, `taskwarrior-tracking.md` at `task-bulk-ops`. **Impact**: always-loaded global context drops 98,956 → 73,332 bytes (`test-claude-context-budget.sh` green, −542 lines). ## Draft gate Kept as a **draft** until the four claude-plugins skill PRs (#1981, #1982, #1984, #1986) merge **and** the plugins release, so the stubs never point at skills that don't exist yet (verify-the-replacement-is-operational discipline). Mark ready + merge once `/plugin` shows the four skills installed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_017Eoq2JHmHAEe5VLmV3Kant Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A context diet for the user-global Claude configuration, in three waves on this branch, ending at 99.0 KB always-loaded (from ~153 KB including an unmanaged orphan), pinned by a regression test at a 110 KB ceiling.
Wave 1 — repo-specific rules out of the global tree
exact_dot_claude/rules/(loads everywhere) to repo-root.claude/rules/(loads only here):chezmoi-conventions.md(17 KB),testing.md,shell-completions.md,development.md,document-management.md,zshrc-keybindings.md,fzf-picker-colorize-align.md.dependency-management.md: Homebrew-profile + MCP-registry sections → new repo rulepackage-registries.md.paths:frontmatter onzsh-pattern-expansion-extended-glob,docker-build-context,rustfmt-gate-onboarding..chezmoiignore: registerpolicy-limits.json/remote-settings.json(Claude Code runtime files theexact_tree would delete).Wave 2 — regression test (
tests/test-claude-context-budget.sh)Four checks: total always-loaded budget, 10 KB per-file cap, repo-specific-marker scan with conscious allowlist,
paths:frontmatter validity. Wired as a pre-commit local hook (runs in CI viapre-commit run --all-files) andmise run test:context-budget. Red-path verified with canary fixtures — and it caught a real violation mid-branch (unallowlisted marker in the newgit-hazards.md).Wave 3 — consolidation of the remaining global rules (meta-context-diet audit)
verify-machine-facts-before-publishing.mdlived only in~/.claude/rules/, loading every turn while invisible to source and test.git-hazards.md(4.7 KB) — per-hazard invariant + check + fix.tracking+cross-session, near-duplicates) into one rule.claude-code-auto-mode.md(8.4 KB) andclaude-plugins-freshness.md(4.0 KB) to settings-file globs.d2-diagramsskill), disk-full-recovery (→macos-disk-usage), telegram, kitty, mise-stale-copies, orbstack, development-process. Droppedprivate_reporters.md(testing-plugin skills own it) and the CLAUDE.md-duplicate install-priority list.Hook noise fixes
chezmoi-drift-guard: substring*chezmoi*apply*matching fired on commit messages / PR bodies that merely mentioned "chezmoi apply" — anchored to real invocations, and the heads-up now names the drifted files. Matcher unit-checked on 6 cases.chezmoi-workflow-nudge: repeated the identical reminder per Edit (9× in one session) — added a 30-min stamp-file debounce.Session distill
chezmoi-conventions.mdnote that non-exact_subdirs neither purge orphaned targets nor flag them inchezmoi status.Why
Everything under
~/.claude/rules/withoutpaths:frontmatter is paid for on every turn in every project. Roughly a third of it was repo-specific mechanics, near-duplicate pairs, or narrative around one-paragraph invariants whose playbooks already live in plugin skills. The test makes the ceiling deterministic instead of relying on session discipline.Verification
./tests/test-claude-context-budget.sh→ PASS=4 at the 110 KB ceiling; canary red-path verified.chezmoi status ~/.claudeclean after apply; orphaned targets of deleted rules removed manually (rules/is non-exact_).bulk-syntax-sweep,taskwarrior-bulk-operations,session-plugin.local.md, guard-hook comments); shellcheck clean.Follow-up (not in this PR)
Tier-2 skill promotions are cross-repo work in
laurigates/claude-plugins— another ~27 KB once promoted, tracked as one issue each:taskwarrior-bulk-operations(8.8 KB) → taskwarrior-plugin skilltui-keybinding-terminal-interception(7.0 KB) → macos-plugin skillhuggingface-downloads(6.0 KB) → tools-plugin skillbulk-syntax-sweep-classify-matches(5.3 KB) → code-quality-plugin skill🤖 Generated with Claude Code
https://claude.ai/code/session_01RVnFBnQFMWKgd8h4kTCjZy