Environment Health
Diagnose the user's Claude Code environment health. Outputs either an inline markdown
report or a self-contained interactive HTML dashboard. Covers 10 diagnostic areas — 6
graded scores against official thresholds (§4 splits into §4a at-rest and §4b post-compact;
§9 Skill Security Scan uses security baselines rather than docs-cited thresholds)
plus 5 observational areas (raw numbers, no tier).
Instructions
Input Parsing
Parse these arguments:
| Flag |
Values |
Default |
Meaning |
--format |
html | md |
html |
Output mode. html generates a full interactive dashboard (default — recommended). md produces an inline markdown report for non-browser contexts or chat pasting |
--lang |
ISO code (en, ko, fr, etc.) |
detected |
Report language. Falls back to detecting the user message language, then en |
--paste-context |
(flag) |
off |
Ask the user to paste their /context output and use it to correct the estimated startup load |
--use-instructions-loaded-hook |
(flag) |
off |
Guide the user through temporarily enabling the InstructionsLoaded hook for file-level ground-truth data, then offer to revert it |
Phase 1 — Data Collection
Determine the context window size. The scan subprocess cannot detect the active
session's window from process.env. Derive it from the active model ID:
- Model ID contains
[1m] (e.g. claude-opus-4-6[1m]) → 1000000
- Any other model ID →
200000
Pass this as --window-size=<N> so the scan records it and downstream formulas use
the correct denominator.
Run the scan:
node ${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/scripts/env-health-scan.js --window-size=<N>
The script writes a JSON blob to stdout with these sections:
scan_date, context_window_size, env_and_settings (normalized
enable_tool_search per mcp.md's 5-value table, agent_teams_enabled,
anthropic_base_url)
installed_plugins ({plugins, orphan_count, orphans}), disabled_plugins
installed_skills, installed_commands, local_skills (each entry carries
desc_chars, when_to_use_chars, combined_chars, disabled, user_invocable)
skill_bodies (at-rest 500-line flag + post-compact 5K-token flag)
hook_inventory (type counts, event collisions, llm_hooks — includes inline
hooks from plugin.json's hooks field: schema_issues and schema_issue_counts
for hook schema validation)
skill_security (scanned_count, findings with confidence levels, counts_by_severity,
counts_by_category — covers 6 pattern categories: prompt_injection, data_exfil,
destructive, hardcoded_credential, obfuscation, safety_override)
context_metrics (MCP server count + source scopes — includes plugin .mcp.json
files AND inline mcpServers from plugin.json)
plugin_components (bin / monitors / lsp_servers / output_styles /
channels per plugin + totals)
subagent_preloads (agents with skills: frontmatter that preload bodies at start)
plugin_options (per-plugin option keys only, values omitted — sensitive)
claude_md (walks cwd → filesystem root + ~/.claude/CLAUDE.md, plus enumerates
lazy-loaded nested files below cwd; respects claudeMdExcludes; each entry carries
scope, load_mode, compact_resilient)
rules, memory
Save to /tmp/env-health-<pid>/scan.json.
Optional ground truth refinement:
- If
--paste-context is set: use AskUserQuestion to ask for the /context output,
parse the reported always-loaded token counts, and override the estimates in the
report. Clear the estimate-caveat when doing so.
- If
--use-instructions-loaded-hook is set: walk the user through adding a temporary
command-type InstructionsLoaded hook to ~/.claude/settings.json that logs to
/tmp/env-health-<pid>/instructions-loaded.log. Instruct them to start a new Claude
Code session so the hook fires, then parse the log for exact per-file loading. Offer
to revert the hook after reading the log.
Phase 2 — Analysis
Read ${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/references/health-criteria.md
for the full threshold specification. Apply it as follows:
Compute the effective description budget:
effective_budget = env_and_settings.desc_budget_override
?? max(8000, floor(context_window_size * 0.01))
Graded areas (§3, §4a, §4b, §7, §8, §9): classify into
🟢 healthy / 🟡 attention / 🔴 critical using the rules in health-criteria.md. Every
threshold you apply must cite its docs source. (§9 Skill Security Scan is an exception —
graded on security baselines without docs-cited thresholds; see health-criteria.md §9.)
Observational areas (§1 Plugin Inventory, §2 Startup Context Budget aggregate,
§5 Trigger Collisions, §6 Hook Complexity, §10 Plugin Components): do NOT assign a
tier. Emit raw numbers and info-level notes only. Delegate individual component
grading in §2 to the owner area per the status-delegation table.
Trigger collisions (§5): delegate to the trigger-collision-inspector subagent.
Build the input inventory by concatenating every installed skill and command
description, one per line:
[plugin-name] skill-name: description text
Invoke the subagent via the Agent tool with subagent_type set to
trigger-collision-inspector. The subagent returns {total_descriptions_analyzed, collisions: [...]}. Surface the pairs verbatim — DUPLICATE / OVERLAP classification
is shown as reported, without aggregating into a tier (the prior 1-2 vs 3+ OVERLAP
thresholds had no official basis and were removed in favor of raw observation).
Do NOT implement Jaccard or pairwise comparison in the orchestrator or the scan
script. The subagent owns the entire comparison (direct adoption of Waza
inspector-context.md:113).
Top lever computation: rank possible actions by raw numeric impact (chars freed,
tokens saved) — not by severity — so observational areas can still surface a lever.
Examples:
- Adding
disable-model-invocation: true to the N skills with the largest
combined_chars → frees sum(combined_chars) (% of budget). Prefer skills users
invoke manually (/commit, /deploy, /release)
- Trimming entries over 1,536 chars → frees
combined_chars - 1536 per entry
- Moving body content of a 5K+ token SKILL.md to
references/ → removes it from both
at-rest and compact budgets
Pick the single lever with the largest projected savings and promote it to the
header + recommendations top card.
Phase 3 — Report Generation
Principle: HTML is the default because a dashboard renders the 10 diagnostic areas as KPI cards, bars, and collision heatmaps that markdown can't match. Only choose md when running in a non-browser context (cowork, headless CI), when the user asks for markdown explicitly, or when pasting into a chat thread is more useful than opening a file.
Mermaid generation force-loads Layer 0's semantic-tokens.md (tokens) / diagram-type-selection.md (type mapping) / diagram-density-rules.md (budget) / taste-gate.md (checklist), and is auto-validated by scripts/taste-gate.js.
Markdown mode (--format md):
Emit an inline markdown report with this structure:
# Environment Health — <scan_date>
**Graded:** N 🟢 / N 🟡 / N 🔴 (6 areas) · **Observational:** Plugin Inventory, Context Budget, Trigger Collisions, Hook Complexity, Plugin Components
**Top lever:** <one sentence>
**Estimated startup load:** ~N tokens (X% of <window> window) — *estimate, run `/context` for ground truth*
## §1 Plugin & Skill Inventory ℹ️
<raw tables, orphan/7-day-grace notes, plugin-option keys>
## §2 Startup Context Budget ℹ️
<component breakdown, delegation references>
## §3 Skill Description Obesity <status>
<numbers, truncated entries, disable-model-invocation candidates, subagent preload totals>
## §4 Skill Body Size <status>
<4a at-rest, 4b post-compact — report separately>
## §5 Trigger Collisions ℹ️
<subagent-returned DUPLICATE/OVERLAP pairs, verbatim, no tier>
## §6 Hook Complexity ℹ️
<type breakdown, event collisions, inline-vs-file sources>
## §7 MCP Overview <status>
<server count, ENABLE_TOOL_SEARCH 5-value table, effective mode, proxy fallback>
## §8 CLAUDE.md & Memory Health <status>
<file list with scope/load_mode/compact_resilient, MEMORY.md capacity, nested lazy-loaded totals>
## §9 Skill Security Scan <status>
<findings list with confidence; safe/likely_safe collapsed; hook schema_issues as info notes>
## §10 Plugin Components ℹ️
<bin / monitors / lsp_servers / output_styles / channels per plugin>
## Recommendations
<grouped by severity, top lever promoted>
Cite sources inline where a threshold fires. Keep it under 200 lines.
HTML mode (default, --format html):
Read ${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/references/section-structure.md
for the JSON schema. Then follow ${CLAUDE_PLUGIN_ROOT}/references/report-generation-workflow.md
with these parameters:
| Parameter |
Value |
{output-path} |
${CLAUDE_PLUGIN_DATA}/reports/<scan_date>-context-health-visual.html |
{template-name} |
context-health-visual.html |
{skill-prefix} |
env-health |
{expected-sections} |
10 |
{report-title} |
"Environment Health — <scan_date>" |
{aesthetic-hint} |
"Dashboard" |
{agent-prompt-data} |
The analyzed scan data, subagent collision results, computed tiers per area, top lever, and info notes. Pass the raw scan.json separately so the writer can reference exact numbers. |
The sections-data.json must set metadata.report_type = "context-health-visual" so
render-sections.js dispatches to the context-health-visual renderers (not the
plugin-visual ones).
Privacy guard (both modes): strip any raw file content before rendering. The
report emits counts, sizes, line numbers, and file paths — never CLAUDE.md body text,
MEMORY.md body text, API keys, or arbitrary file contents. Enforce this as a
pre-render pass: walk the sections-data.json tree and remove any field named body,
content, raw, text (excluding purposefully-set text fields in info_notes and
recommendation action strings, which contain only computed messages).
Cleanup
Remove the temp directory:
rm -rf /tmp/env-health-<pid>
If the user enabled the InstructionsLoaded hook, remind them to revert it now.
Gotchas
- Skill description budget is 1% of context window, not 2%. Earlier drafts used 2%
/ 16K chars. The official number (skills.md — "Skill descriptions are cut short") is
1% scaling, 8,000-char fallback. Use the effective budget formula:
SLASH_COMMAND_TOOL_CHAR_BUDGET ?? max(8000, floor(context_window * 0.01)).
- Skill description loading is a 3-layer model, not a single number. Per skills.md:
(A) each entry's combined
description + when_to_use is truncated at 1,536
characters — hard per-entry cap. (B) Total across all listing-included entries is
capped at effective_budget = SLASH_COMMAND_TOOL_CHAR_BUDGET ?? max(8000, floor(window × 0.01)). When the total exceeds budget, every entry is dynamically shortened
(keywords stripped). (C) Even below saturation, a few oversize entries can dominate.
Earlier drafts cited "250 chars" — that number does not appear anywhere in the docs.
§3 of the report evaluates all three axes separately. disable-model-invocation: true
removes a skill from the listing entirely per the frontmatter table, so it contributes
zero to the budget.
- 5K/25K skill body limit is POST-COMPACT, not at-rest. The 5,000-tokens-per-skill
/ 25,000-total limit applies only to re-injection after
/compact, and only for
skills that were invoked in the session. The at-rest recommendation is separate:
keep SKILL.md under 500 lines (skills.md tip). Report them as two distinct
sections (§4a and §4b) — do not conflate.
- Skill descriptions are NOT re-injected after compact. Only invoked skills
survive compaction. The always-loaded description budget vanishes after compact,
which changes what "always-loaded cost" means mid-session. Mention this caveat in
the report.
- Auto-compaction can enter a thrashing state and halt. Per how-claude-code-works.md:
"If a single file or tool output is so large that context refills immediately after
each summary, Claude Code stops auto-compacting after a few attempts and shows an
error." The scan cannot detect thrashing directly, but it can surface its
ingredients — large SKILL.md bodies, many rules without
paths:, and large
CLAUDE.md chains all amplify the risk. When all three co-occur, flag it in the
report and link users to
https://code.claude.com/docs/en/troubleshooting#auto-compaction-stops-with-a-thrashing-error.
- Trigger collision uses a subagent, not inline orchestrator logic. The
trigger-collision-inspector subagent owns the entire comparison (Waza-style). Do
NOT add Jaccard code in the scanner or do the comparison in the main orchestrator —
both would bloat main-session context and duplicate the subagent's job. If accuracy
becomes a problem, revise the subagent prompt before adding deterministic pre-filter
stages (YAGNI).
- Context budget is always-loaded only. Don't count deferred items in the
always-loaded budget unless
ENABLE_TOOL_SEARCH is auto (with pressure) or
false. Report deferred items separately so users see both views.
/context is ground truth, not the scan's estimate. The scan uses public
formulas but Claude Code's actual context accounting can drift per version. The
report must say "Estimated — run /context for ground truth" and optionally
accept pasted /context output via --paste-context.
InstructionsLoaded hook is the file-level ground truth. For users who want
exact per-file instruction loading data, recommend temporarily enabling the
InstructionsLoaded hook (hooks.md) to log which CLAUDE.md / rules / skills files
actually loaded. Offered as --use-instructions-loaded-hook.
- Skill body tokens are estimated (chars/4). Actual tokenization varies. Flag as
approximate.
- MEMORY.md path varies by project. The encoded path format can vary. The scan
script tries multiple paths — if none match, report "no memory file found" rather
than erroring.
- prompt/agent hooks cost tokens per event. Unlike command/http hooks,
prompt/agent hook types invoke an LLM call each time they fire. This is a per-event
runtime cost, not a startup cost.
ENABLE_TOOL_SEARCH changes the MCP cost model. The default (deferred) means
only tool names in context. auto may load schemas upfront if they fit in 10% of
context. false always loads them. The scan reads this env var and adjusts the
MCP budget line accordingly.
claudeMdExcludes and --add-dir CLAUDE.md loading. Respect
claudeMdExcludes (exclude matching paths from CLAUDE.md total) and
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1 (include CLAUDE.md from --add-dir
paths). Both affect the always-loaded budget.
- Privacy. The scan reads CLAUDE.md, MEMORY.md, and settings files, but the
report must emit counts and sizes only — never file contents, API keys, or memory
body text. Enforce as a pre-render guard that strips raw content fields before
producing sections-data.json.
- Context window size is not self-detectable from the scan. The
node env-health-scan.js subprocess has no way to know the current session's window size
(200K vs 1M). Detect it from the active model ID (e.g. claude-opus-4-6[1m] →
- and pass via
--window-size=<N>. Without this, percentage-of-window
calculations default to 200K and will be wrong on 1M sessions.
- Shell-level env vars only — child process inheritance. The scan reads
SLASH_COMMAND_TOOL_CHAR_BUDGET, ENABLE_TOOL_SEARCH,
CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD, CLAUDE_CODE_DISABLE_AUTO_MEMORY
from process.env. These are only visible to the Node subprocess if the user
exported them from their shell init. Env vars set only inside a Claude Code
session (not exported before CC launched) are invisible. Surface this caveat next
to any env-var-derived field.
- CLAUDE.md walk scope: cwd → filesystem root, plus
~/.claude/CLAUDE.md. Per
memory.md, Claude Code loads CLAUDE.md from every ancestor directory above cwd plus
~/.claude/CLAUDE.md. The docs do NOT specify a $HOME boundary. The scan walks up
to the filesystem root so that projects under /tmp, /var, or other non-home
locations still get a complete ancestor chain. Scope is reported as one of
project-root / ancestor / ancestor-local / nested / local-root / user.
- Nested CLAUDE.md files are lazy-loaded and NOT re-injected after
/compact.
Per memory.md, nested CLAUDE.md files (below cwd) load only when files in their
subtree are read. Unlike project-root ./CLAUDE.md / ./.claude/CLAUDE.md, they
don't survive compaction — only always-loaded project-root files are re-injected.
The scan reports load_mode and compact_resilient per file, and keeps
nested_lines / nested_bytes / nested_est_tokens separate from always-loaded
totals so the report doesn't exaggerate startup load.
- Observational areas never contribute to the tally. §1 and §2 emit raw numbers
and info-level notes only. They are counted separately from the graded tally. A
report showing
0 critical means zero critical among graded areas — observational
areas may still have info-level observations worth surfacing.
- Skill security scan uses heuristic confidence, not binary safe/unsafe. Every
finding is kept in the output — nothing is silently discarded. A
confidence field
adjusts how prominently findings are shown: safe / likely_safe findings are
collapsed by default (temp-path cleanup, loopback-only calls, frontmatter metadata
lines, and scanner self-references do not warrant loud alerts). Grade is driven only
by uncertain / suspicious findings. When multiple heuristics apply to one finding,
the most cautious level (lowest confidence) is used.
- Self-exclusion by frontmatter
name:, not by path. The scanner skips the skill
whose name: frontmatter field equals context-health-visual. Path-based exclusion
would break across install locations (cache vs local). Scope is this skill only —
other vision-powers skills (plugin-visual, doc-visual, fact-check, etc.) remain
in-scope so any legitimate security findings surface.
- Hook schema validation applies only to tool-gated events.
PreToolUse and
PostToolUse entries are flagged when they lack a matcher field. Other events
(SessionStart, UserPromptSubmit, Stop, etc.) don't use matchers — flagging
them would be noise. This scope is hard-coded in env-health-scan.js; update the
MATCHER_EVENTS set if future docs add more tool-gated event types.
Reference Files
references/health-criteria.md — Grading thresholds (cites every docs source) and
recommendation templates
references/section-structure.md — JSON schema for the 10-section HTML report
agents/trigger-collision-inspector.md — Subagent spec for trigger collision
detection (Waza-adapted)
scripts/env-health-scan.js — Data collection script
../../references/report-generation-workflow.md — Shared HTML generation pipeline
(render → assemble → validate → log → open)
../../references/design-system/semantic-tokens.md — Color and font semantic tokens
../../references/design-system/diagram-type-selection.md — 13-type selection guide
../../references/design-system/diagram-density-rules.md — Complexity budget per type
../../references/design-system/taste-gate.md — Pre-output quality checklist
1---
2name: context-health-visual
3disable-model-invocation: true
4description: >
5 Diagnose Claude Code environment health — context budget, description obesity,
6 trigger collisions, hooks, MCP, plugins, CLAUDE.md, memory, and skill-security scan.
7 Use when asked to audit the environment, check context budget, review plugins,
8 or scan installed skills for risky patterns.
9argument-hint: "[--format html|md] [--lang <code>] [--paste-context] [--use-instructions-loaded-hook]"
10allowed-tools: Read, Glob, Grep, Agent, AskUserQuestion, Bash(node *), Bash(open *), Bash(rm -rf /tmp/env-health-*)
11metadata:
12 source: https://skillmd.com/skills/aibot88/context-health-visual
13---
14
15# Environment Health
16
17Diagnose the user's Claude Code environment health. Outputs either an inline markdown
18report or a self-contained interactive HTML dashboard. Covers 10 diagnostic areas — 6
19graded scores against official thresholds (§4 splits into §4a at-rest and §4b post-compact;
20§9 Skill Security Scan uses security baselines rather than docs-cited thresholds)
21plus 5 observational areas (raw numbers, no tier).
22
23## Instructions
24
25### Input Parsing
26
27Parse these arguments:
28
29| Flag | Values | Default | Meaning |
30|------|--------|---------|---------|
31| `--format` | `html` \| `md` | `html` | Output mode. `html` generates a full interactive dashboard (default — recommended). `md` produces an inline markdown report for non-browser contexts or chat pasting |
32| `--lang` | ISO code (`en`, `ko`, `fr`, etc.) | detected | Report language. Falls back to detecting the user message language, then `en` |
33| `--paste-context` | (flag) | off | Ask the user to paste their `/context` output and use it to correct the estimated startup load |
34| `--use-instructions-loaded-hook` | (flag) | off | Guide the user through temporarily enabling the `InstructionsLoaded` hook for file-level ground-truth data, then offer to revert it |
35
36### Phase 1 — Data Collection
37
38**Determine the context window size.** The scan subprocess cannot detect the active
39session's window from `process.env`. Derive it from the active model ID:
40
41- Model ID contains `[1m]` (e.g. `claude-opus-4-6[1m]`) → `1000000`
42- Any other model ID → `200000`
43
44Pass this as `--window-size=<N>` so the scan records it and downstream formulas use
45the correct denominator.
46
47**Run the scan:**
48
49```bash
50node ${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/scripts/env-health-scan.js --window-size=<N>
51```
52
53The script writes a JSON blob to stdout with these sections:
54
55- `scan_date`, `context_window_size`, `env_and_settings` (normalized
56 `enable_tool_search` per mcp.md's 5-value table, `agent_teams_enabled`,
57 `anthropic_base_url`)
58- `installed_plugins` (`{plugins, orphan_count, orphans}`), `disabled_plugins`
59- `installed_skills`, `installed_commands`, `local_skills` (each entry carries
60 `desc_chars`, `when_to_use_chars`, `combined_chars`, `disabled`, `user_invocable`)
61- `skill_bodies` (at-rest 500-line flag + post-compact 5K-token flag)
62- `hook_inventory` (type counts, event collisions, `llm_hooks` — includes inline
63 hooks from `plugin.json`'s `hooks` field: `schema_issues` and `schema_issue_counts`
64 for hook schema validation)
65- `skill_security` (scanned_count, findings with confidence levels, counts_by_severity,
66 counts_by_category — covers 6 pattern categories: prompt_injection, data_exfil,
67 destructive, hardcoded_credential, obfuscation, safety_override)
68- `context_metrics` (MCP server count + source scopes — includes plugin `.mcp.json`
69 files AND inline `mcpServers` from `plugin.json`)
70- `plugin_components` (`bin` / `monitors` / `lsp_servers` / `output_styles` /
71 `channels` per plugin + totals)
72- `subagent_preloads` (agents with `skills:` frontmatter that preload bodies at start)
73- `plugin_options` (per-plugin option **keys only**, values omitted — sensitive)
74- `claude_md` (walks cwd → filesystem root + `~/.claude/CLAUDE.md`, plus enumerates
75 lazy-loaded nested files below cwd; respects `claudeMdExcludes`; each entry carries
76 `scope`, `load_mode`, `compact_resilient`)
77- `rules`, `memory`
78
79Save to `/tmp/env-health-<pid>/scan.json`.
80
81**Optional ground truth refinement:**
82
83- If `--paste-context` is set: use `AskUserQuestion` to ask for the `/context` output,
84 parse the reported always-loaded token counts, and override the estimates in the
85 report. Clear the estimate-caveat when doing so.
86- If `--use-instructions-loaded-hook` is set: walk the user through adding a temporary
87 command-type `InstructionsLoaded` hook to `~/.claude/settings.json` that logs to
88 `/tmp/env-health-<pid>/instructions-loaded.log`. Instruct them to start a new Claude
89 Code session so the hook fires, then parse the log for exact per-file loading. Offer
90 to revert the hook after reading the log.
91
92### Phase 2 — Analysis
93
94Read `${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/references/health-criteria.md`
95for the full threshold specification. Apply it as follows:
96
97**Compute the effective description budget:**
98
99```
100effective_budget = env_and_settings.desc_budget_override
101 ?? max(8000, floor(context_window_size * 0.01))
102```
103
104**Graded areas** (§3, §4a, §4b, §7, §8, §9): classify into
105🟢 healthy / 🟡 attention / 🔴 critical using the rules in `health-criteria.md`. Every
106threshold you apply must cite its docs source. (§9 Skill Security Scan is an exception —
107graded on security baselines without docs-cited thresholds; see health-criteria.md §9.)
108
109**Observational areas** (§1 Plugin Inventory, §2 Startup Context Budget aggregate,
110§5 Trigger Collisions, §6 Hook Complexity, §10 Plugin Components): do NOT assign a
111tier. Emit raw numbers and info-level notes only. Delegate individual component
112grading in §2 to the owner area per the status-delegation table.
113
114**Trigger collisions (§5):** delegate to the `trigger-collision-inspector` subagent.
115Build the input inventory by concatenating every installed skill and command
116description, one per line:
117
118```
119[plugin-name] skill-name: description text
120```
121
122Invoke the subagent via the `Agent` tool with `subagent_type` set to
123`trigger-collision-inspector`. The subagent returns `{total_descriptions_analyzed,
124collisions: [...]}`. Surface the pairs verbatim — DUPLICATE / OVERLAP classification
125is shown as reported, without aggregating into a tier (the prior 1-2 vs 3+ OVERLAP
126thresholds had no official basis and were removed in favor of raw observation).
127
128Do NOT implement Jaccard or pairwise comparison in the orchestrator or the scan
129script. The subagent owns the entire comparison (direct adoption of Waza
130`inspector-context.md:113`).
131
132**Top lever computation:** rank possible actions by raw numeric impact (chars freed,
133tokens saved) — not by severity — so observational areas can still surface a lever.
134Examples:
135
136- Adding `disable-model-invocation: true` to the N skills with the largest
137 `combined_chars` → frees `sum(combined_chars)` (% of budget). Prefer skills users
138 invoke manually (`/commit`, `/deploy`, `/release`)
139- Trimming entries over 1,536 chars → frees `combined_chars - 1536` per entry
140- Moving body content of a 5K+ token SKILL.md to `references/` → removes it from both
141 at-rest and compact budgets
142
143Pick the single lever with the largest projected savings and promote it to the
144header + recommendations top card.
145
146### Phase 3 — Report Generation
147
148**Principle:** HTML is the default because a dashboard renders the 10 diagnostic areas as KPI cards, bars, and collision heatmaps that markdown can't match. Only choose `md` when running in a non-browser context (cowork, headless CI), when the user asks for markdown explicitly, or when pasting into a chat thread is more useful than opening a file.
149
150Mermaid generation force-loads Layer 0's semantic-tokens.md (tokens) / diagram-type-selection.md (type mapping) / diagram-density-rules.md (budget) / taste-gate.md (checklist), and is auto-validated by `scripts/taste-gate.js`.
151
152**Markdown mode (`--format md`):**
153
154Emit an inline markdown report with this structure:
155
156```
157# Environment Health — <scan_date>
158
159**Graded:** N 🟢 / N 🟡 / N 🔴 (6 areas) · **Observational:** Plugin Inventory, Context Budget, Trigger Collisions, Hook Complexity, Plugin Components
160
161**Top lever:** <one sentence>
162
163**Estimated startup load:** ~N tokens (X% of <window> window) — *estimate, run `/context` for ground truth*
164
165## §1 Plugin & Skill Inventory ℹ️
166<raw tables, orphan/7-day-grace notes, plugin-option keys>
167
168## §2 Startup Context Budget ℹ️
169<component breakdown, delegation references>
170
171## §3 Skill Description Obesity <status>
172<numbers, truncated entries, disable-model-invocation candidates, subagent preload totals>
173
174## §4 Skill Body Size <status>
175<4a at-rest, 4b post-compact — report separately>
176
177## §5 Trigger Collisions ℹ️
178<subagent-returned DUPLICATE/OVERLAP pairs, verbatim, no tier>
179
180## §6 Hook Complexity ℹ️
181<type breakdown, event collisions, inline-vs-file sources>
182
183## §7 MCP Overview <status>
184<server count, ENABLE_TOOL_SEARCH 5-value table, effective mode, proxy fallback>
185
186## §8 CLAUDE.md & Memory Health <status>
187<file list with scope/load_mode/compact_resilient, MEMORY.md capacity, nested lazy-loaded totals>
188
189## §9 Skill Security Scan <status>
190<findings list with confidence; safe/likely_safe collapsed; hook schema_issues as info notes>
191
192## §10 Plugin Components ℹ️
193<bin / monitors / lsp_servers / output_styles / channels per plugin>
194
195## Recommendations
196<grouped by severity, top lever promoted>
197```
198
199Cite sources inline where a threshold fires. Keep it under 200 lines.
200
201**HTML mode (default, `--format html`):**
202
203Read `${CLAUDE_PLUGIN_ROOT}/skills/context-health-visual/references/section-structure.md`
204for the JSON schema. Then follow `${CLAUDE_PLUGIN_ROOT}/references/report-generation-workflow.md`
205with these parameters:
206
207| Parameter | Value |
208|-----------|-------|
209| `{output-path}` | `${CLAUDE_PLUGIN_DATA}/reports/<scan_date>-context-health-visual.html` |
210| `{template-name}` | `context-health-visual.html` |
211| `{skill-prefix}` | `env-health` |
212| `{expected-sections}` | `10` |
213| `{report-title}` | `"Environment Health — <scan_date>"` |
214| `{aesthetic-hint}` | `"Dashboard"` |
215| `{agent-prompt-data}` | The analyzed scan data, subagent collision results, computed tiers per area, top lever, and info notes. Pass the raw `scan.json` separately so the writer can reference exact numbers. |
216
217The sections-data.json must set `metadata.report_type = "context-health-visual"` so
218`render-sections.js` dispatches to the context-health-visual renderers (not the
219plugin-visual ones).
220
221**Privacy guard (both modes):** strip any raw file content before rendering. The
222report emits counts, sizes, line numbers, and file paths — never CLAUDE.md body text,
223MEMORY.md body text, API keys, or arbitrary file contents. Enforce this as a
224pre-render pass: walk the sections-data.json tree and remove any field named `body`,
225`content`, `raw`, `text` (excluding purposefully-set `text` fields in `info_notes` and
226recommendation `action` strings, which contain only computed messages).
227
228### Cleanup
229
230Remove the temp directory:
231
232```bash
233rm -rf /tmp/env-health-<pid>
234```
235
236If the user enabled the `InstructionsLoaded` hook, remind them to revert it now.
237
238## Gotchas
239
240- **Skill description budget is 1% of context window, not 2%.** Earlier drafts used 2%
241 / 16K chars. The official number (skills.md — "Skill descriptions are cut short") is
242 1% scaling, 8,000-char fallback. Use the effective budget formula:
243 `SLASH_COMMAND_TOOL_CHAR_BUDGET ?? max(8000, floor(context_window * 0.01))`.
244- **Skill description loading is a 3-layer model, not a single number.** Per skills.md:
245 (A) each entry's combined `description` + `when_to_use` is truncated at **1,536
246 characters** — hard per-entry cap. (B) Total across all listing-included entries is
247 capped at `effective_budget = SLASH_COMMAND_TOOL_CHAR_BUDGET ?? max(8000, floor(window
248 × 0.01))`. When the total exceeds budget, every entry is **dynamically shortened**
249 (keywords stripped). (C) Even below saturation, a few oversize entries can dominate.
250 Earlier drafts cited "250 chars" — that number does not appear anywhere in the docs.
251 §3 of the report evaluates all three axes separately. `disable-model-invocation: true`
252 removes a skill from the listing entirely per the frontmatter table, so it contributes
253 zero to the budget.
254- **5K/25K skill body limit is POST-COMPACT, not at-rest.** The 5,000-tokens-per-skill
255 / 25,000-total limit applies only to re-injection after `/compact`, and only for
256 skills that were **invoked** in the session. The at-rest recommendation is separate:
257 keep `SKILL.md` under 500 lines (skills.md tip). Report them as two distinct
258 sections (§4a and §4b) — do not conflate.
259- **Skill descriptions are NOT re-injected after compact.** Only invoked skills
260 survive compaction. The always-loaded description budget vanishes after compact,
261 which changes what "always-loaded cost" means mid-session. Mention this caveat in
262 the report.
263- **Auto-compaction can enter a thrashing state and halt.** Per how-claude-code-works.md:
264 "If a single file or tool output is so large that context refills immediately after
265 each summary, Claude Code stops auto-compacting after a few attempts and shows an
266 error." The scan cannot detect thrashing directly, but it can surface its
267 ingredients — large SKILL.md bodies, many rules without `paths:`, and large
268 CLAUDE.md chains all amplify the risk. When all three co-occur, flag it in the
269 report and link users to
270 `https://code.claude.com/docs/en/troubleshooting#auto-compaction-stops-with-a-thrashing-error`.
271- **Trigger collision uses a subagent, not inline orchestrator logic.** The
272 `trigger-collision-inspector` subagent owns the entire comparison (Waza-style). Do
273 NOT add Jaccard code in the scanner or do the comparison in the main orchestrator —
274 both would bloat main-session context and duplicate the subagent's job. If accuracy
275 becomes a problem, revise the subagent prompt before adding deterministic pre-filter
276 stages (YAGNI).
277- **Context budget is always-loaded only.** Don't count deferred items in the
278 always-loaded budget unless `ENABLE_TOOL_SEARCH` is `auto` (with pressure) or
279 `false`. Report deferred items separately so users see both views.
280- **`/context` is ground truth, not the scan's estimate.** The scan uses public
281 formulas but Claude Code's actual context accounting can drift per version. The
282 report must say _"Estimated — run `/context` for ground truth"_ and optionally
283 accept pasted `/context` output via `--paste-context`.
284- **`InstructionsLoaded` hook is the file-level ground truth.** For users who want
285 exact per-file instruction loading data, recommend temporarily enabling the
286 `InstructionsLoaded` hook (hooks.md) to log which CLAUDE.md / rules / skills files
287 actually loaded. Offered as `--use-instructions-loaded-hook`.
288- **Skill body tokens are estimated (chars/4).** Actual tokenization varies. Flag as
289 approximate.
290- **MEMORY.md path varies by project.** The encoded path format can vary. The scan
291 script tries multiple paths — if none match, report "no memory file found" rather
292 than erroring.
293- **prompt/agent hooks cost tokens per event.** Unlike command/http hooks,
294 prompt/agent hook types invoke an LLM call each time they fire. This is a per-event
295 runtime cost, not a startup cost.
296- **`ENABLE_TOOL_SEARCH` changes the MCP cost model.** The default (`deferred`) means
297 only tool names in context. `auto` may load schemas upfront if they fit in 10% of
298 context. `false` always loads them. The scan reads this env var and adjusts the
299 MCP budget line accordingly.
300- **`claudeMdExcludes` and `--add-dir` CLAUDE.md loading.** Respect
301 `claudeMdExcludes` (exclude matching paths from CLAUDE.md total) and
302 `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD=1` (include CLAUDE.md from `--add-dir`
303 paths). Both affect the always-loaded budget.
304- **Privacy.** The scan reads CLAUDE.md, MEMORY.md, and settings files, but the
305 report must emit counts and sizes only — never file contents, API keys, or memory
306 body text. Enforce as a pre-render guard that strips raw content fields before
307 producing sections-data.json.
308- **Context window size is not self-detectable from the scan.** The `node
309 env-health-scan.js` subprocess has no way to know the current session's window size
310 (200K vs 1M). Detect it from the active model ID (e.g. `claude-opus-4-6[1m]` →
311 1000000) and pass via `--window-size=<N>`. Without this, percentage-of-window
312 calculations default to 200K and will be wrong on 1M sessions.
313- **Shell-level env vars only — child process inheritance.** The scan reads
314 `SLASH_COMMAND_TOOL_CHAR_BUDGET`, `ENABLE_TOOL_SEARCH`,
315 `CLAUDE_CODE_ADDITIONAL_DIRECTORIES_CLAUDE_MD`, `CLAUDE_CODE_DISABLE_AUTO_MEMORY`
316 from `process.env`. These are only visible to the Node subprocess if the user
317 `export`ed them from their shell init. Env vars set only inside a Claude Code
318 session (not exported before CC launched) are invisible. Surface this caveat next
319 to any env-var-derived field.
320- **CLAUDE.md walk scope: cwd → filesystem root, plus `~/.claude/CLAUDE.md`.** Per
321 memory.md, Claude Code loads CLAUDE.md from every ancestor directory above cwd plus
322 `~/.claude/CLAUDE.md`. The docs do NOT specify a `$HOME` boundary. The scan walks up
323 to the filesystem root so that projects under `/tmp`, `/var`, or other non-home
324 locations still get a complete ancestor chain. Scope is reported as one of
325 `project-root` / `ancestor` / `ancestor-local` / `nested` / `local-root` / `user`.
326- **Nested CLAUDE.md files are lazy-loaded and NOT re-injected after `/compact`.**
327 Per memory.md, nested CLAUDE.md files (below cwd) load only when files in their
328 subtree are read. Unlike project-root `./CLAUDE.md` / `./.claude/CLAUDE.md`, they
329 don't survive compaction — only always-loaded project-root files are re-injected.
330 The scan reports `load_mode` and `compact_resilient` per file, and keeps
331 `nested_lines` / `nested_bytes` / `nested_est_tokens` separate from always-loaded
332 totals so the report doesn't exaggerate startup load.
333- **Observational areas never contribute to the tally.** §1 and §2 emit raw numbers
334 and info-level notes only. They are counted separately from the graded tally. A
335 report showing `0 critical` means zero critical among graded areas — observational
336 areas may still have info-level observations worth surfacing.
337- **Skill security scan uses heuristic confidence, not binary safe/unsafe.** Every
338 finding is kept in the output — nothing is silently discarded. A `confidence` field
339 adjusts how prominently findings are shown: `safe` / `likely_safe` findings are
340 collapsed by default (temp-path cleanup, loopback-only calls, frontmatter metadata
341 lines, and scanner self-references do not warrant loud alerts). Grade is driven only
342 by `uncertain` / `suspicious` findings. When multiple heuristics apply to one finding,
343 the most cautious level (lowest confidence) is used.
344- **Self-exclusion by frontmatter `name:`, not by path.** The scanner skips the skill
345 whose `name:` frontmatter field equals `context-health-visual`. Path-based exclusion
346 would break across install locations (cache vs local). Scope is this skill only —
347 other vision-powers skills (plugin-visual, doc-visual, fact-check, etc.) remain
348 in-scope so any legitimate security findings surface.
349- **Hook schema validation applies only to tool-gated events.** `PreToolUse` and
350 `PostToolUse` entries are flagged when they lack a `matcher` field. Other events
351 (`SessionStart`, `UserPromptSubmit`, `Stop`, etc.) don't use matchers — flagging
352 them would be noise. This scope is hard-coded in `env-health-scan.js`; update the
353 `MATCHER_EVENTS` set if future docs add more tool-gated event types.
354
355## Reference Files
356
357- `references/health-criteria.md` — Grading thresholds (cites every docs source) and
358 recommendation templates
359- `references/section-structure.md` — JSON schema for the 10-section HTML report
360- `agents/trigger-collision-inspector.md` — Subagent spec for trigger collision
361 detection (Waza-adapted)
362- `scripts/env-health-scan.js` — Data collection script
363- `../../references/report-generation-workflow.md` — Shared HTML generation pipeline
364 (render → assemble → validate → log → open)
365- `../../references/design-system/semantic-tokens.md` — Color and font semantic tokens
366- `../../references/design-system/diagram-type-selection.md` — 13-type selection guide
367- `../../references/design-system/diagram-density-rules.md` — Complexity budget per type
368- `../../references/design-system/taste-gate.md` — Pre-output quality checklist