@alexgreensh/token-optimizer 0.0.0-stage → 5.13.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/.claude-plugin/marketplace.json +76 -0
  2. package/.claude-plugin/plugin.json +21 -0
  3. package/LICENSE +130 -0
  4. package/LICENSE-SMALL-BUSINESS.md +62 -0
  5. package/PRIVACY.md +200 -0
  6. package/README.md +13 -2
  7. package/hooks/codex-hooks.json +4 -0
  8. package/hooks/hooks.json +182 -0
  9. package/hooks/module_runner.py +149 -0
  10. package/hooks/posttooluse_runner.py +1110 -0
  11. package/hooks/python-launcher.sh +816 -0
  12. package/hooks/run.py +776 -0
  13. package/hooks/sessionstart_runner.py +629 -0
  14. package/hooks/stop_runner.py +408 -0
  15. package/hooks/userpromptsubmit_runner.py +722 -0
  16. package/hooks/windows-launcher.py +163 -0
  17. package/install-cloud.sh +23 -0
  18. package/package.json +29 -4
  19. package/skills/fleet-auditor/SKILL.md +150 -0
  20. package/skills/fleet-auditor/references/fleet-systems.md +167 -0
  21. package/skills/fleet-auditor/references/report-template.md +50 -0
  22. package/skills/fleet-auditor/references/waste-patterns.md +126 -0
  23. package/skills/fleet-auditor/scripts/fleet.py +3612 -0
  24. package/skills/fleet-auditor/scripts/shared.py +277 -0
  25. package/skills/resume-checkpoint/SKILL.md +52 -0
  26. package/skills/resume-checkpoint/scripts/pull_checkpoint.py +188 -0
  27. package/skills/token-coach/SKILL.md +129 -0
  28. package/skills/token-coach/assets/coach-dashboard-tab.html +45 -0
  29. package/skills/token-coach/examples/coaching-session-agentic.md +62 -0
  30. package/skills/token-coach/examples/coaching-session-heavy-setup.md +46 -0
  31. package/skills/token-coach/examples/coaching-session-new-project.md +38 -0
  32. package/skills/token-coach/references/agentic-systems.md +147 -0
  33. package/skills/token-coach/references/coach-patterns.md +120 -0
  34. package/skills/token-coach/references/coaching-scripts.md +146 -0
  35. package/skills/token-coach/references/deterministic-stages.md +102 -0
  36. package/skills/token-coach/references/keepwarm-consent.md +48 -0
  37. package/skills/token-coach/references/quick-reference.md +155 -0
  38. package/skills/token-dashboard/SKILL.md +72 -0
  39. package/skills/token-optimizer/SKILL.md +150 -0
  40. package/skills/token-optimizer/assets/dashboard.html +7251 -0
  41. package/skills/token-optimizer/examples/claude-md-optimized.md +40 -0
  42. package/skills/token-optimizer/examples/hooks-starter.json +179 -0
  43. package/skills/token-optimizer/examples/permissions-deny-template.json +24 -0
  44. package/skills/token-optimizer/pricing/prices.json +695 -0
  45. package/skills/token-optimizer/references/agent-prompts.md +687 -0
  46. package/skills/token-optimizer/references/cli-reference.md +92 -0
  47. package/skills/token-optimizer/references/codex-workflow.md +188 -0
  48. package/skills/token-optimizer/references/cursor-workflow.md +74 -0
  49. package/skills/token-optimizer/references/error-recovery.md +37 -0
  50. package/skills/token-optimizer/references/implementation-playbook.md +416 -0
  51. package/skills/token-optimizer/references/keepwarm-consent.md +48 -0
  52. package/skills/token-optimizer/references/opencode-workflow.md +72 -0
  53. package/skills/token-optimizer/references/optimization-checklist.md +714 -0
  54. package/skills/token-optimizer/references/phase0-setup.md +142 -0
  55. package/skills/token-optimizer/references/presentation-workflow.md +72 -0
  56. package/skills/token-optimizer/references/session-continuity.md +19 -0
  57. package/skills/token-optimizer/references/token-flow-architecture.md +629 -0
  58. package/skills/token-optimizer/scripts/activity_tracker.py +143 -0
  59. package/skills/token-optimizer/scripts/antigravity_doctor.py +548 -0
  60. package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +511 -0
  61. package/skills/token-optimizer/scripts/antigravity_install.py +376 -0
  62. package/skills/token-optimizer/scripts/antigravity_proto.py +413 -0
  63. package/skills/token-optimizer/scripts/antigravity_session.py +346 -0
  64. package/skills/token-optimizer/scripts/antigravity_state.py +486 -0
  65. package/skills/token-optimizer/scripts/archive_result.py +1725 -0
  66. package/skills/token-optimizer/scripts/bash_compress.py +2490 -0
  67. package/skills/token-optimizer/scripts/bash_compress_hook.py +766 -0
  68. package/skills/token-optimizer/scripts/bash_hook.py +61 -0
  69. package/skills/token-optimizer/scripts/bash_whitelist.py +243 -0
  70. package/skills/token-optimizer/scripts/benchmark.py +1765 -0
  71. package/skills/token-optimizer/scripts/build_output_compress.py +776 -0
  72. package/skills/token-optimizer/scripts/cloud_kit.py +991 -0
  73. package/skills/token-optimizer/scripts/codex_command_compress.py +434 -0
  74. package/skills/token-optimizer/scripts/codex_compact_prompt.py +273 -0
  75. package/skills/token-optimizer/scripts/codex_doctor.py +454 -0
  76. package/skills/token-optimizer/scripts/codex_hook_bridge.py +311 -0
  77. package/skills/token-optimizer/scripts/codex_install.py +810 -0
  78. package/skills/token-optimizer/scripts/codex_io.py +119 -0
  79. package/skills/token-optimizer/scripts/codex_log_index.py +219 -0
  80. package/skills/token-optimizer/scripts/codex_models.py +34 -0
  81. package/skills/token-optimizer/scripts/codex_session.py +1186 -0
  82. package/skills/token-optimizer/scripts/codex_state.py +707 -0
  83. package/skills/token-optimizer/scripts/codex_statusline.py +303 -0
  84. package/skills/token-optimizer/scripts/command_filters.py +386 -0
  85. package/skills/token-optimizer/scripts/compression_backfill.py +600 -0
  86. package/skills/token-optimizer/scripts/compression_log.py +230 -0
  87. package/skills/token-optimizer/scripts/context_intel.py +331 -0
  88. package/skills/token-optimizer/scripts/context_pressure.py +115 -0
  89. package/skills/token-optimizer/scripts/copilot_doctor.py +406 -0
  90. package/skills/token-optimizer/scripts/copilot_hook_bridge.py +709 -0
  91. package/skills/token-optimizer/scripts/copilot_install.py +277 -0
  92. package/skills/token-optimizer/scripts/copilot_session.py +496 -0
  93. package/skills/token-optimizer/scripts/copilot_state.py +569 -0
  94. package/skills/token-optimizer/scripts/copilot_vscode.py +832 -0
  95. package/skills/token-optimizer/scripts/cowork_doctor.py +270 -0
  96. package/skills/token-optimizer/scripts/cowork_install.py +380 -0
  97. package/skills/token-optimizer/scripts/credential_patterns.py +1514 -0
  98. package/skills/token-optimizer/scripts/cursor_doctor.py +602 -0
  99. package/skills/token-optimizer/scripts/cursor_hook_bridge.py +843 -0
  100. package/skills/token-optimizer/scripts/cursor_install.py +423 -0
  101. package/skills/token-optimizer/scripts/cursor_session.py +303 -0
  102. package/skills/token-optimizer/scripts/cursor_state.py +348 -0
  103. package/skills/token-optimizer/scripts/delta_diff.py +110 -0
  104. package/skills/token-optimizer/scripts/detectors/__init__.py +2 -0
  105. package/skills/token-optimizer/scripts/detectors/bad_decomposition.py +78 -0
  106. package/skills/token-optimizer/scripts/detectors/cache_instability.py +504 -0
  107. package/skills/token-optimizer/scripts/detectors/looping.py +88 -0
  108. package/skills/token-optimizer/scripts/detectors/output_waste.py +143 -0
  109. package/skills/token-optimizer/scripts/detectors/overpowered.py +116 -0
  110. package/skills/token-optimizer/scripts/detectors/pdf_ingestion.py +52 -0
  111. package/skills/token-optimizer/scripts/detectors/registry.py +65 -0
  112. package/skills/token-optimizer/scripts/detectors/respond_to_bash.py +76 -0
  113. package/skills/token-optimizer/scripts/detectors/retry_churn.py +83 -0
  114. package/skills/token-optimizer/scripts/detectors/tool_cascade.py +62 -0
  115. package/skills/token-optimizer/scripts/detectors/wasteful_thinking.py +75 -0
  116. package/skills/token-optimizer/scripts/detectors/weak_model.py +55 -0
  117. package/skills/token-optimizer/scripts/detectors/websearch_routing.py +72 -0
  118. package/skills/token-optimizer/scripts/deterministic_candidates.py +1458 -0
  119. package/skills/token-optimizer/scripts/devin_compress.py +790 -0
  120. package/skills/token-optimizer/scripts/devin_doctor.py +403 -0
  121. package/skills/token-optimizer/scripts/devin_hooks.py +453 -0
  122. package/skills/token-optimizer/scripts/devin_install.py +1086 -0
  123. package/skills/token-optimizer/scripts/devin_source.py +119 -0
  124. package/skills/token-optimizer/scripts/devin_state.py +330 -0
  125. package/skills/token-optimizer/scripts/devin_verify.py +67 -0
  126. package/skills/token-optimizer/scripts/grok_doctor.py +560 -0
  127. package/skills/token-optimizer/scripts/grok_hook_bridge.py +699 -0
  128. package/skills/token-optimizer/scripts/grok_install.py +397 -0
  129. package/skills/token-optimizer/scripts/grok_session.py +317 -0
  130. package/skills/token-optimizer/scripts/grok_state.py +299 -0
  131. package/skills/token-optimizer/scripts/hermes_doctor.py +479 -0
  132. package/skills/token-optimizer/scripts/hermes_hook_bridge.py +285 -0
  133. package/skills/token-optimizer/scripts/hermes_install.py +668 -0
  134. package/skills/token-optimizer/scripts/hermes_session.py +691 -0
  135. package/skills/token-optimizer/scripts/hermes_state.py +448 -0
  136. package/skills/token-optimizer/scripts/hook_io.py +120 -0
  137. package/skills/token-optimizer/scripts/hook_runtime.py +713 -0
  138. package/skills/token-optimizer/scripts/injection.py +156 -0
  139. package/skills/token-optimizer/scripts/install_reconcile.py +952 -0
  140. package/skills/token-optimizer/scripts/measure.py +58739 -0
  141. package/skills/token-optimizer/scripts/outline.py +53 -0
  142. package/skills/token-optimizer/scripts/pipeline_analyzer.py +723 -0
  143. package/skills/token-optimizer/scripts/plugin_env.py +562 -0
  144. package/skills/token-optimizer/scripts/py_trust.py +80 -0
  145. package/skills/token-optimizer/scripts/quality_cache_gate.py +320 -0
  146. package/skills/token-optimizer/scripts/read_cache.py +2489 -0
  147. package/skills/token-optimizer/scripts/recovery_output.py +110 -0
  148. package/skills/token-optimizer/scripts/refetch_fingerprint.py +236 -0
  149. package/skills/token-optimizer/scripts/refetch_guard.py +244 -0
  150. package/skills/token-optimizer/scripts/routing_advisor.py +389 -0
  151. package/skills/token-optimizer/scripts/runtime_env.py +1893 -0
  152. package/skills/token-optimizer/scripts/session_store.py +979 -0
  153. package/skills/token-optimizer/scripts/spawn_utils.py +122 -0
  154. package/skills/token-optimizer/scripts/statusline.js +660 -0
  155. package/skills/token-optimizer/scripts/structure_map.py +2880 -0
  156. package/skills/token-optimizer/scripts/structure_map_ts.py +676 -0
  157. package/skills/token-optimizer/scripts/structure_replay.py +1556 -0
  158. package/skills/token-optimizer/scripts/thrash_guard.py +604 -0
  159. package/skills/token-optimizer/scripts/token_estimate.py +80 -0
  160. package/skills/token-optimizer/scripts/tool_search_diagnostic.py +61 -0
  161. package/skills/token-optimizer/scripts/utf8_io.py +219 -0
@@ -0,0 +1,102 @@
1
+ # Which steps need a model at all
2
+
3
+ Reference for Token Coach, goal e, and for any session where the coach data lists `deterministic_candidates`.
4
+
5
+ ## Contents
6
+
7
+ - The one test
8
+ - Why it matters more than trimming config
9
+ - Finding candidates in the user's own data
10
+ - Steps that are nearly always code
11
+ - Steps that stay with the model
12
+ - The usual shape: model at the edges
13
+ - Where the code lives, per platform
14
+ - How to present it
15
+ - When to leave a step alone
16
+
17
+ ## The one test
18
+
19
+ For each step in a workflow ask: **do the inputs fully decide the output?** If two careful people given the same inputs would always produce the same result, the step is a function, and a function belongs in code. If the right result depends on reading meaning, weighing trade-offs, or writing for a person, it needs a model.
20
+
21
+ A second question catches the rest: **what would check this step's output?** If the honest answer is "a test, a schema, or a diff", the step is usually code already and the model is acting as a slow interpreter for it.
22
+
23
+ ## Why it matters more than trimming config
24
+
25
+ Config cleanup saves a fixed number of tokens once per session. A model step costs on every run:
26
+
27
+ - The whole context is read again for that turn (cached reads are cheap per token, but the context is large and the turn count is high).
28
+ - The output is generated at output-token price, the most expensive kind.
29
+ - The result joins the context and is re-read by every later turn until compaction.
30
+ - It can come back different the next time, so something downstream has to tolerate that.
31
+
32
+ A script costs no tokens, takes milliseconds, and returns the same answer every time. Moving one repeated step from a model to code often beats every setting change the coach can suggest, and it makes the workflow more reliable as a side effect. Lead with the reliability when the user's spend is small.
33
+
34
+ ## Finding candidates in the user's own data
35
+
36
+ `python3 "$MEASURE_PY" coach --json` may include `deterministic_candidates`: tool-call sequences the user repeats across sessions with the same shape, subagents launched again and again from near-identical prompts, and loops that poll or retry. Each entry carries how often it ran and what it cost. Start from those, since they are measured.
37
+
38
+ When the list is empty or missing, ask the user to describe the workflow as numbered steps, then apply the one test to each. Useful prompts for them:
39
+
40
+ - "What do you ask for in the same words most days?"
41
+ - "Which steps do you never read the reasoning for, only the result?"
42
+ - "Where does the agent wait for something?"
43
+
44
+ ## Steps that are nearly always code
45
+
46
+ | Step | Why it is a function | Typical replacement |
47
+ |------|----------------------|---------------------|
48
+ | Routing by a fixed rule (file type, label, sender, path) | A lookup | A `case` or a small table in a script |
49
+ | Counting, summing, ranking, deduplicating | Arithmetic | `jq`, SQL, a few lines of Python |
50
+ | Filling a template, formatting a report, renaming files | The shape is fixed | A template plus a script |
51
+ | Extracting fields from structured text (JSON, CSV, logs with a stable format) | A parse | A parser or a regular expression |
52
+ | Waiting, polling, "check again in a minute" | No judgement, and every poll re-reads the context | A shell loop, a scheduled job, or a background task that wakes the agent once |
53
+ | "Did it pass?" on a build, test run, or linter | The tool already returns an exit code | The exit code, with the model reading output only on failure |
54
+ | Fetching the same data at the start of every session | Same query each time | A SessionStart hook or a script whose output is piped in |
55
+ | Validation against a schema, a style rule, a naming rule | A check | A linter, a JSON schema, a pre-commit hook |
56
+ | Retrying a failed call | A policy | A retry wrapper with a limit |
57
+ | Moving results between steps | Plumbing | Files on disk, read by the next step |
58
+
59
+ ## Steps that stay with the model
60
+
61
+ - Reading intent from messy human text.
62
+ - Choosing between options with real trade-offs.
63
+ - Writing for a reader: prose, explanations, reviews.
64
+ - Diagnosing a failure nobody has seen before.
65
+ - Work where the input format changes too often for a parser to keep up.
66
+
67
+ ## The usual shape: model at the edges
68
+
69
+ Most workflows are a mix, and the gain comes from changing who does the middle:
70
+
71
+ 1. **Code gathers.** A script fetches, filters, parses and totals, then writes a compact result file.
72
+ 2. **The model judges.** It reads that small file, not the raw material, and makes the one decision or writes the one piece of text that needs it.
73
+ 3. **Code applies and checks.** A script writes the output where it belongs and validates it. The model is called again only when the check fails.
74
+
75
+ Compare the context each way. A model that reads fifty files to count something holds all fifty until compaction. A script that counts and hands over one line leaves the context almost untouched.
76
+
77
+ ## Where the code lives, per platform
78
+
79
+ | Mechanism | Use it when | Notes |
80
+ |-----------|-------------|-------|
81
+ | A script the skill or command runs | The step belongs to one workflow | Keep it beside the skill; print errors that name the fix |
82
+ | A hook (Claude Code, Codex) | The step must happen every time, whether or not the model remembers | Claude Code's exec form (`"command"` plus `"args"`, no shell) starts faster and avoids quoting problems; on Windows use the `Bash\|PowerShell` matcher so both shells are covered |
83
+ | Command text that runs a shell line before the prompt is sent | The model needs fresh data at the start | The model sees only the output |
84
+ | A scheduled job (cron, launchd, a scheduled cloud agent) | The work recurs on a clock | Call a model inside it only at the judgement step |
85
+ | A headless call (`claude -p`, `codex exec`) inside a script | A pipeline needs one judgement in the middle | Give it only the gathered result, and a cheaper model when the judgement is simple |
86
+ | A subagent | The judgement step needs to read a lot | It keeps the reading out of the main context; it is still a model call, so it does not replace code |
87
+
88
+ ## How to present it
89
+
90
+ Give the user a table of their own steps:
91
+
92
+ | Step | Today | Inputs decide the output? | Move to | What it saves |
93
+ |------|-------|---------------------------|---------|---------------|
94
+
95
+ Fill "what it saves" from measured data where there is some (runs per week and tokens per run from `deterministic_candidates`), and write "not measured" where there is none. Then offer to write the first script with them, starting with the step that runs most often.
96
+
97
+ ## When to leave a step alone
98
+
99
+ - It runs rarely. A script nobody maintains costs more than a few model calls a month.
100
+ - The input is messy enough that the parser would need its own maintenance.
101
+ - The user reads the model's reasoning for that step and values it.
102
+ - A wrong result is costly and the model is the one catching edge cases. Keep the model and add a code check after it instead.
@@ -0,0 +1,48 @@
1
+ # Keep-Warm consent
2
+
3
+ Keep-Warm pings the prompt cache before it expires so a paused session resumes warm. It pays off only for API-billed Claude Code sessions, it is off by default, and it refuses on subscription auth. Ask once.
4
+
5
+ ## 1. Check whether to ask
6
+
7
+ ```bash
8
+ python3 "$MEASURE_PY" keepwarm-consent-status # JSON: {billing_mode, consent, should_ask}
9
+ ```
10
+
11
+ `should_ask` false: say nothing. True (API-billed, not yet asked): continue.
12
+
13
+ ## 2. Compute the user's own projection
14
+
15
+ ```bash
16
+ python3 "$MEASURE_PY" keepwarm-backfill --json --no-fence # read modes."probe-only".net_usd
17
+ ```
18
+
19
+ ## 3. Pitch
20
+
21
+ When a session pauses past its cache window and resumes, the whole prefix is written again at up to 2x input. Keep-Warm pings just before expiry (about 0.1x of the prefix, at most 2 pings per pause), and a tripwire switches it off if the pings stop paying for themselves.
22
+
23
+ - `net_usd` positive: add "a replay of your own last 30 days nets about $<net_usd> per 30 days at the conservative probe-only setting".
24
+ - Backfill failed, returned nothing, or `net_usd <= 0`: leave the dollar sentence out and say the saving depends on their own pause-and-resume pattern, and the dashboard shows it once pings have fired. Never supply a number of your own.
25
+
26
+ ## 4. Record the answer, yes or no first
27
+
28
+ Recording the answer before anything else means an interrupted run never leaves an "asked" marker with no answer.
29
+
30
+ ```bash
31
+ python3 "$MEASURE_PY" keepwarm-enable # yes: records consent and installs the scheduler (macOS)
32
+ python3 "$MEASURE_PY" keepwarm-disable # no
33
+ ```
34
+
35
+ Both are final, so the user is not asked again. Only when the user neither accepts nor declines:
36
+
37
+ ```bash
38
+ python3 "$MEASURE_PY" keepwarm-consent-asked # marks the question as shown
39
+ ```
40
+
41
+ ## 5. Confirm it is armed (after a yes)
42
+
43
+ ```bash
44
+ python3 "$MEASURE_PY" keepwarm-scheduler status # installed and loaded state (macOS)
45
+ python3 "$MEASURE_PY" keepwarm-tick --dry-run # what the next tick would decide
46
+ ```
47
+
48
+ On Linux and Windows the scheduler is not shipped yet: Keep-Warm runs watchdog-only until the user wires `keepwarm-tick` to their own cron or timer. Tell them that plainly.
@@ -0,0 +1,155 @@
1
+ # Quick Reference: Hard Numbers for Token Coach
2
+
3
+ Reference file for Token Coach. The numbers the coach cites.
4
+
5
+ ---
6
+
7
+ ## Contents
8
+
9
+ - [Baseline Overhead (Fresh Session)](#baseline-overhead-fresh-session)
10
+ - [Cache and Compaction Controls](#cache-and-compaction-controls)
11
+ - [User Config Overhead (Typical Power User)](#user-config-overhead-typical-power-user)
12
+ - [Context Quality Degradation](#context-quality-degradation)
13
+ - [MCP Tool Costs (Real Examples)](#mcp-tool-costs-real-examples)
14
+ - [Token Costs Per Component](#token-costs-per-component)
15
+ - [Environment Variables](#environment-variables)
16
+ - [Subagent Costs](#subagent-costs)
17
+ - [Cache-Expiry Waste — per provider](#cache-expiry-waste--per-provider)
18
+
19
+ ---
20
+
21
+ ## Baseline Overhead (Fresh Session)
22
+
23
+ Percentages below assume a 1M-token window, the default on current Claude models (Haiku 5.5, Sonnet 5+, Opus 4.7+). On a 200K window the same token counts are 5x the percentage.
24
+
25
+ | Component | Tokens | % of a 1M window |
26
+ |-----------|--------|------------------|
27
+ | System prompt | ~3,000 | 0.3% |
28
+ | Built-in tools (18+) | ~12,000-15,000 | 1.2-1.5% |
29
+ | **Total fixed floor** | **~15,000-18,000** | **1.5-1.8%** |
30
+
31
+ With auto-compact enabled (the default), Claude Code reserves headroom inside the model's compact window; the reserved size is not documented and varies by build, so treat it as overhead you cannot spend. On 1M models compaction fires at about 967K tokens by default; on 200K models it fires near the context limit.
32
+
33
+ ## Cache and Compaction Controls
34
+
35
+ What the user can set, from the official Claude Code docs. Cache writes: a 5-minute cache costs 1.25x base input to write, a 1-hour cache 2x; cache reads cost 0.1x.
36
+
37
+ | Control | What it does | Default |
38
+ |----------|-------------|---------|
39
+ | `promptCacheTtl` (setting) | Main-conversation cache TTL: "5m" or "1h" | unset (1h on subscription billing, 5m on usage credits/API) |
40
+ | `CLAUDE_CODE_PROMPT_CACHE_TTL` (env) | Same as `promptCacheTtl`; env outranks the setting | unset |
41
+ | `subagentPromptCacheTtl` (setting) | Subagent cache TTL: "5m" or "1h" (v2.1.243+) | unset (subagents get 5m even on a subscription) |
42
+ | `CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL` (env) | Same as `subagentPromptCacheTtl`; env outranks the setting | unset |
43
+ | `experimental.cacheTtl` (agent frontmatter, v2.1.248+) | Per-subagent cache TTL, inside the `experimental:` map | unset |
44
+ | `ENABLE_PROMPT_CACHING_1H=1` (env) | Blanket 1-hour cache | unset |
45
+ | `FORCE_PROMPT_CACHING_5M` (env) | Force 5-minute caching; outranks everything above | unset |
46
+ | `/autocompact <n>` | Compact window, 100K-1M, saved per model | tuned for the model (~967K on 1M models) |
47
+ | `/autocompact auto` | Restore the tuned window | - |
48
+ | `autoCompactWindow` (setting) | Compact window, 100000-1000000, capped at the model's limit | unset (tuned per model) |
49
+ | `CLAUDE_CODE_AUTO_COMPACT_WINDOW` (env) | Same range as `autoCompactWindow`; env outranks the setting | unset |
50
+
51
+ A plugin's own settings.json cannot set the cache TTLs (only `agent` and `subagentStatusLine` take effect from plugin settings).
52
+
53
+ ## User Config Overhead (Typical Power User)
54
+
55
+ | Component | Tokens | Per-Item Cost |
56
+ |-----------|--------|---------------|
57
+ | Skills (50 installed) | ~5,000 | ~100/skill |
58
+ | Commands (30 installed) | ~1,500 | ~50/command |
59
+ | MCP tools (100 deferred) | ~1,500 | ~15/tool |
60
+ | MCP server instructions (10 servers) | ~500-1,000 | ~50-100/server |
61
+ | CLAUDE.md (global) | ~800-2,000 | Per line |
62
+ | MEMORY.md | ~600-1,400 | Per line |
63
+ | Rules (5 unscoped) | ~500 | Variable |
64
+ | @imports | Variable | Full file cost |
65
+
66
+ ## Context Quality Degradation
67
+
68
+ Token Optimizer's quality score uses a published long-context retrieval curve for Claude models, as a share of the model's window. It is an estimate, not a measurement:
69
+
70
+ | Window filled | Estimated retrieval quality |
71
+ |---------------|-----------------------------|
72
+ | 0-10% | 98 to 96 (minimal loss) |
73
+ | 10-25% | 96 to 93 |
74
+ | 25-50% | 93 to 88 |
75
+ | 50-70% | 88 to 80 |
76
+ | 70-100% | 80 to 76 |
77
+
78
+ On a 1M window those bands span far more tokens than on 200K, so the same absolute token count costs less quality on a 1M window. For when to compact, run `measure.py compact-advice`, which answers from the user's own sessions instead of a fixed percentage.
79
+
80
+ ## MCP Tool Costs (Real Examples)
81
+
82
+ | MCP Server | Tools | Tokens (eager) | Tokens (deferred) |
83
+ |------------|-------|----------------|-------------------|
84
+ | GitHub | 35 | ~26,000 | ~525 |
85
+ | Slack | 11 | ~21,000 | ~165 |
86
+ | Jira | ~20 | ~17,000 | ~300 |
87
+ | Docker | 135 | ~125,000 | ~2,025 |
88
+ | Chrome automation | ~30 | ~31,700 | ~450 |
89
+
90
+ Tool Search (on by default) reduced total MCP overhead by 85-96%.
91
+
92
+ ## Token Costs Per Component
93
+
94
+ | What | Always-Loaded Cost | On-Demand Cost |
95
+ |------|-------------------|----------------|
96
+ | Skill (installed) | ~100 tokens (frontmatter) | 2K-5K (full SKILL.md on invoke) |
97
+ | Command | ~50 tokens (frontmatter) | Full file on invoke |
98
+ | MCP tool (deferred) | ~15 tokens (name only) | Full schema on use |
99
+ | MCP tool (eager) | ~300-850 tokens (full schema) | N/A |
100
+ | MCP server instruction | ~50-100 tokens | N/A |
101
+ | CLAUDE.md line | ~15 tokens | N/A |
102
+ | @import file | Full file tokens | N/A |
103
+ | Rule (unscoped) | Full file tokens | N/A |
104
+ | Rule (path-scoped) | 0 (until path match) | Full file when matched |
105
+
106
+ ## Environment Variables
107
+
108
+ | Variable | Effect | Default |
109
+ |----------|--------|---------|
110
+ | `CLAUDE_CODE_DISABLE_GIT_INSTRUCTIONS=1` | Remove git workflow instructions (~2K tokens) | Enabled |
111
+ | `CLAUDE_CODE_DISABLE_AUTO_MEMORY=1` | Disable auto memory creation/loading | Enabled |
112
+ | `CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1` | Disable background tasks | Enabled |
113
+ | `ENABLE_CLAUDEAI_MCP_SERVERS=false` | Opt out of claude.ai cloud-synced MCP servers | Enabled |
114
+ | `CLAUDE_CODE_MAX_OUTPUT_TOKENS` | Max output tokens per response | 16,384 |
115
+ | `CLAUDE_AUTOCOMPACT_PCT_OVERRIDE` | Percent of the compact window used when auto-compaction fires (1-100); lower compacts earlier, and it cannot raise the threshold. Token Optimizer reports it and never changes it | unset |
116
+ | `includeGitInstructions: false` (setting) | Same as DISABLE_GIT env var, in settings.json | true |
117
+ | `effortLevel` (setting) | "high" maximizes quality + cost; "medium" saves 15-25% output tokens | auto |
118
+
119
+ ## Subagent Costs
120
+
121
+ | Factor | Cost |
122
+ |--------|------|
123
+ | Native agent overhead (v1.0.60+) | ~13K tokens per agent |
124
+ | Config inheritance per agent | Same as main session startup |
125
+ | 5 agents x 15K config | 75K tokens just for setup |
126
+ | Skill assigned to subagent | FULL SKILL.md at startup (not progressive) |
127
+ | Agent Teams vs single agent | ~7x token usage (Anthropic docs) |
128
+
129
+ ## Cache-Expiry Waste — per provider
130
+
131
+ Cache economics are model-AGNOSTIC: each provider has its own cache profile, so the detector resolves a session's model to a profile, not to Anthropic semantics. Two waste shapes: explicit-TTL re-WRITE (Anthropic) and automatic-discount COLLAPSE (OpenAI/Codex, Gemini, DeepSeek).
132
+
133
+ | Provider / model family | Cache kind | Cached read | Effective TTL | User TTL knob |
134
+ |---|---|---|---|---|
135
+ | Anthropic API/SDK | explicit_ttl | 0.1x input | 5 min default | yes (`ttl:"1h"`, 2x write once) |
136
+ | Claude Code | explicit_ttl | 0.1x input | 1h on subscription billing, 5m on usage credits/API | yes (see the Cache and Compaction Controls table above) |
137
+ | OpenAI / Codex | automatic_discount | 0.1x input | ~5-10 min (max ~1h) | policy only (`prompt_cache_retention="24h"`) |
138
+ | Gemini 2.5+ | explicit_storage | ~0.1x input | implicit auto | yes (`cached_content` ttl, default 1h, +storage/hr) |
139
+ | DeepSeek | automatic_discount | 0.1x input (1/10) | hours-to-days | no |
140
+ | unknown / other | none | n/a | n/a | n/a (no cache economics) |
141
+
142
+ Claude Code's main conversation requests a 1-hour cache on subscription billing; on usage credits or an API key the default is 5 minutes until a setting above raises it. Empirically the prefix survives sub-hour pauses, so the Claude Code detector counts only pauses LONGER than an hour. Subagents default to a 5-minute cache even on a subscription; `subagentPromptCacheTtl` (or the per-agent `experimental.cacheTtl`) can raise that to 1 hour. Raw Anthropic API/SDK/harness sessions (e.g. Hermes → Anthropic) keep the 5-minute default and the 1h-`cache_control` counterfactual.
143
+
144
+ Detection: explicit_ttl = gap > effective TTL (Claude Code main conversation: 1 hour; API/SDK: 5min) AND next-turn cache_creation >= 50% of prior cached prefix. automatic_discount/explicit_storage = prior cached ratio >= 0.40, gap > TTL, next ratio < 0.10 with comparable prompt → lost cached tokens re-billed at full input vs cached rate. none = honest skip (counted, never waste).
145
+
146
+ Verified remedies (per profile, exactly what the provider offers):
147
+ - Claude Code: resume inside the cache window or batch related work, so a long pause never strands the prefix. Token Optimizer can also keep it warm automatically (opt-in, API billing only): `keepwarm-enable` (records consent + installs the macOS scheduler; verify with `keepwarm-scheduler status` / `keepwarm-tick --dry-run`). It pings the cache before expiry at ~0.1x of the prefix (vs the 1.25-2x re-write), max 2 pings per pause unless promoted, with a tripwire that auto-disables if pings stop paying for themselves. Off by default; subscription auth stays off (pings would burn quota without saving dollars). To activate on a subscription/off-billing or platform-gap machine: set `ANTHROPIC_API_KEY` and run `keepwarm-enable` (on Linux/Windows, wire `keepwarm-tick` to your own cron/timer until the scheduler ships).
148
+ - Anthropic API/SDK/agent harness: `cache_control {"type":"ephemeral","ttl":"1h"}` on stable prefixes.
149
+ - OpenAI/Codex: keep prefix exact-match (>=1024 tok), resume within window; `prompt_cache_retention="24h"` for long-lived prefixes.
150
+ - Gemini: explicit `cached_content` with user `ttl` (per-hour storage billed).
151
+ - DeepSeek: automatic; keep prefixes stable while the on-disk cache is warm.
152
+
153
+ Coverage gaps (not measurable, rendered explicitly): Hermes (per-session aggregates only, cache_read unreliable), OpenClaw/OpenCode (TS engines, no Python per-turn read path), Copilot (credits-billed, no per-turn cache detail).
154
+
155
+ Surface: `measure.py cache-report [--days N] [--json]` — per-provider breakdown + coverage gaps. OPPORTUNITY-tier (observed waste, potential recovery); never counts toward realized savings.
@@ -0,0 +1,72 @@
1
+ ---
2
+ name: token-dashboard
3
+ description: Opens the Token Optimizer dashboard in the browser (context usage, quality, savings). Use when the user asks to see the dashboard.
4
+ disable-model-invocation: true
5
+ ---
6
+
7
+ # Token Optimizer Dashboard
8
+
9
+ Opens an up-to-date dashboard showing your context usage trends, quality scores, session history, and skill management.
10
+
11
+ ## Instructions
12
+
13
+ 1. **Resolve runtime and measure.py path**:
14
+ ```bash
15
+ RUNTIME="${TOKEN_OPTIMIZER_RUNTIME:-}"
16
+ if [ -z "$RUNTIME" ]; then
17
+ if [ -n "$CLAUDE_PLUGIN_ROOT" ] || [ -n "$CLAUDE_PLUGIN_DATA" ]; then
18
+ RUNTIME="claude"
19
+ elif [ -n "$OPENCODE" ] || [ -n "$OPENCODE_BIN" ] || [ -n "$OPENCODE_CONFIG_DIR" ] || [ -n "$OPENCODE_CONFIG" ]; then
20
+ RUNTIME="opencode"
21
+ elif [ -n "$CODEX_HOME" ]; then
22
+ RUNTIME="codex"
23
+ elif [ -n "$CLAUDECODE" ] || [ -n "$CLAUDE_CODE_ENTRYPOINT" ] || [ -n "$CLAUDE_CODE_SESSION_ID" ]; then
24
+ RUNTIME="claude"
25
+ elif [ -d "$HOME/.config/opencode" ] && [ ! -d "$HOME/.codex" ]; then
26
+ RUNTIME="opencode"
27
+ elif [ -d "$HOME/.codex" ]; then
28
+ RUNTIME="codex"
29
+ else
30
+ RUNTIME="claude"
31
+ fi
32
+ fi
33
+
34
+ # Resolve measure.py to the NEWEST installed copy across channels so a stale
35
+ # plugin-cache copy never shadows a fresh install. find -L follows the
36
+ # install.sh symlink under ~/.claude/skills; cd -P resolves it before reading each
37
+ # copy's plugin.json for its version. find (not bare globs) never errors under zsh.
38
+ MEASURE_PY=""; _best_ver=""
39
+ while IFS= read -r _cand; do
40
+ [ -f "$_cand" ] || continue
41
+ _root="$(cd -P -- "$(dirname -- "$_cand")/../../.." 2>/dev/null && pwd)"
42
+ _ver="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_root/.claude-plugin/plugin.json" 2>/dev/null | head -1)"
43
+ [ -n "$_ver" ] || _ver="0.0.0"
44
+ if [ -z "$_best_ver" ] || [ "$(printf '%s\n%s\n' "$_ver" "$_best_ver" | sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | tail -n1)" = "$_ver" ]; then
45
+ _best_ver="$_ver"; MEASURE_PY="$_cand"
46
+ fi
47
+ done <<EOF
48
+ $(find -L "$HOME/.claude/skills" "$HOME/.claude/plugins/cache" "$HOME/.claude/token-optimizer" "$HOME/.codex/skills" "$HOME/.codex/plugins/cache" "$HOME/.config/opencode/plugins/cache" "$HOME/.config/opencode/plugins" -type f -name measure.py -path '*token-optimizer*/scripts/measure.py' 2>/dev/null)
49
+ EOF
50
+ if [ -z "$MEASURE_PY" ]; then echo "[Error] measure.py not found. Is Token Optimizer installed?"; exit 1; fi
51
+ export TOKEN_OPTIMIZER_RUNTIME="$RUNTIME"
52
+ ```
53
+
54
+ 2. **Collect and open**:
55
+ ```bash
56
+ # TOKEN_OPTIMIZER_INTERACTIVE=1 marks this as a user-initiated open, so the 20s
57
+ # hook budget does not cut off a heavy rebuild on a large history. The user is
58
+ # waiting for this open, so it runs unbounded.
59
+ TOKEN_OPTIMIZER_INTERACTIVE=1 python3 "$MEASURE_PY" collect --quiet && \
60
+ TOKEN_OPTIMIZER_INTERACTIVE=1 python3 "$MEASURE_PY" dashboard
61
+ ```
62
+
63
+ This collects the latest session data into the trends database, regenerates the dashboard HTML, and opens it in your default browser.
64
+
65
+ 3. **Tell the user** the dashboard is open. Probe the daemon before mentioning any URL:
66
+ - Probe daemon: `python3 "$MEASURE_PY" daemon-status 2>/dev/null`
67
+ - If DAEMON_RUNNING: lead with `URL: http://localhost:24842/token-optimizer` (bookmarkable, auto-updates), then mention the file fallback.
68
+ - If DAEMON_NOT_RUNNING: do not print the `localhost:24842` URL. Tell the user the dashboard opened as a file, and suggest `python3 $MEASURE_PY setup-daemon` (macOS and Windows) if they want a bookmarkable URL.
69
+ - File path: never hardcode it. It is install-dependent. Cite the ` Dashboard: ` line from the step-2 output.
70
+ - For Codex when DAEMON_NOT_RUNNING: do not imply the Claude daemon is required; the generated file works, and Stop hooks refresh it when balanced hooks are installed.
71
+
72
+ Written for and checked on Claude Opus 5.5 and Sonnet 5.5, and GPT-5.6 on Codex.
@@ -0,0 +1,150 @@
1
+ ---
2
+ name: token-optimizer
3
+ description: Audits a Claude Code or Codex setup for context-window waste, fixes it with the user's approval, and measures the saving. Use when context feels tight, sessions degrade, or costs climb.
4
+ effort: high
5
+ ---
6
+
7
+ # Token Optimizer
8
+
9
+ Measures where a setup spends its context window, proposes fixes, applies the ones the user approves, and re-measures. The deliverable is a before-and-after the user can verify, with every change backed up. Typical recovery is 5-15% of the window from config cleanup, more when compaction and caching settings are wrong for the way the user works.
10
+
11
+ Token Optimizer's own skills (`token-optimizer`, `token-coach`, `token-dashboard`, `fleet-auditor`, `resume-checkpoint`) are the measurement layer, so leave them out of every unused-skill, archive or consolidation suggestion, however rarely they run.
12
+
13
+ ## Step 0: pick the right workflow for this runtime
14
+
15
+ The audit below reads and edits `~/.claude`, which is the wrong target anywhere but Claude Code, so settle the runtime before touching any path. Run exactly this, in this order.
16
+
17
+ **a. Environment check** (touches no file; an explicit `TOKEN_OPTIMIZER_RUNTIME` wins, and Claude plugin variables are checked before stray `OPENCODE_*` exports, the same order `detect_runtime()` uses):
18
+
19
+ ```bash
20
+ if [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "claude" ] || [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "codex" ]; then
21
+ :
22
+ elif [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "opencode" ]; then
23
+ echo "Token Optimizer — OpenCode runtime detected."
24
+ elif [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "copilot" ]; then
25
+ echo "Token Optimizer — GitHub Copilot runtime detected."
26
+ elif [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "cursor" ]; then
27
+ echo "Token Optimizer — Cursor runtime detected."
28
+ elif [ "${TOKEN_OPTIMIZER_RUNTIME:-}" = "antigravity" ]; then
29
+ echo "Token Optimizer — Google Antigravity runtime detected."
30
+ elif [ -n "${CLAUDE_PLUGIN_ROOT:-}${CLAUDE_PLUGIN_DATA:-}" ]; then
31
+ :
32
+ elif [ -n "${OPENCODE_BIN:-}${OPENCODE_CONFIG_DIR:-}${OPENCODE_DATA_DIR:-}${OPENCODE_CONFIG:-}${OPENCODE_CLIENT:-}" ]; then
33
+ echo "Token Optimizer — OpenCode runtime detected."
34
+ elif [ -n "${COPILOT_HOME:-}${TOKEN_OPTIMIZER_COPILOT_HOME:-}" ]; then
35
+ echo "Token Optimizer — GitHub Copilot runtime detected."
36
+ elif [ -n "${TOKEN_OPTIMIZER_CURSOR_HOME:-}" ]; then
37
+ echo "Token Optimizer — Cursor runtime detected."
38
+ elif [ -n "${CURSOR_PROJECT_DIR:-}" ] && [ -n "${CURSOR_VERSION:-}" ]; then
39
+ echo "Token Optimizer — Cursor runtime detected."
40
+ elif [ -n "${TOKEN_OPTIMIZER_ANTIGRAVITY_HOME:-}" ]; then
41
+ echo "Token Optimizer — Google Antigravity runtime detected."
42
+ fi
43
+ ```
44
+
45
+ | It prints | Do this |
46
+ |-----------|---------|
47
+ | "OpenCode runtime detected." | Stop. Follow `references/opencode-workflow.md` (Token Optimizer runs as a native plugin there). |
48
+ | "Cursor runtime detected." | Stop. Follow `references/cursor-workflow.md` (it runs through the Cursor hook bridge). |
49
+ | "GitHub Copilot runtime detected." | Stop. Follow the Copilot guidance in `docs/copilot.md`. |
50
+ | "Google Antigravity runtime detected." | Stop. Follow `docs/antigravity.md`. |
51
+ | nothing | Continue to b. |
52
+
53
+ **b. Resolve `$MEASURE_PY` once.** Every later command uses it:
54
+
55
+ ```bash
56
+ # Resolve measure.py to the NEWEST installed copy across channels so a stale
57
+ # plugin-cache copy never shadows a fresh install. find -L follows the
58
+ # install.sh symlink under ~/.claude/skills; cd -P resolves it before reading each
59
+ # copy's plugin.json for its version. find (not bare globs) never errors under zsh.
60
+ MEASURE_PY=""; _best_ver=""
61
+ while IFS= read -r _cand; do
62
+ [ -f "$_cand" ] || continue
63
+ _root="$(cd -P -- "$(dirname -- "$_cand")/../../.." 2>/dev/null && pwd)"
64
+ _ver="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_root/.claude-plugin/plugin.json" 2>/dev/null | head -1)"
65
+ [ -n "$_ver" ] || _ver="0.0.0"
66
+ if [ -z "$_best_ver" ] || [ "$(printf '%s\n%s\n' "$_ver" "$_best_ver" | sort -t. -k1,1n -k2,2n -k3,3n -k4,4n | tail -n1)" = "$_ver" ]; then
67
+ _best_ver="$_ver"; MEASURE_PY="$_cand"
68
+ fi
69
+ done <<EOF
70
+ $(find -L "$HOME/.claude/skills" "$HOME/.claude/plugins/cache" "$HOME/.claude/token-optimizer" "$HOME/.codex/skills" "$HOME/.codex/plugins/cache" "$HOME/.config/opencode/plugins" -type f -name measure.py -path '*token-optimizer*/scripts/measure.py' 2>/dev/null)
71
+ EOF
72
+ if [ -z "$MEASURE_PY" ]; then echo "[Error] measure.py not found. Is Token Optimizer installed?"; exit 1; fi
73
+ ```
74
+
75
+ **c. The authoritative gate.** The environment check cannot see an OpenCode started without its variables; this one scans the process tree:
76
+
77
+ ```bash
78
+ python3 "$MEASURE_PY" report 2>&1 | head -1
79
+ ```
80
+
81
+ Any "... runtime detected." line means stop and follow that runtime's file from the table above. On Codex (`TOKEN_OPTIMIZER_RUNTIME=codex` or a Codex environment) follow `references/codex-workflow.md`. Claude Code continues below.
82
+
83
+ ## The audit (Claude Code)
84
+
85
+ Work through these in order and tick each off; a skipped phase stays in the list as `skip: <reason>`.
86
+
87
+ ```
88
+ - [ ] 0. Setup references/phase0-setup.md
89
+ - [ ] 1. Parallel audit references/agent-prompts.md
90
+ - [ ] 2. Synthesis references/agent-prompts.md (Synthesis Agent)
91
+ - [ ] 3. Present, then wait for the user's decision references/presentation-workflow.md
92
+ - [ ] 4. Implement the approved changes references/implementation-playbook.md
93
+ - [ ] 5. Verify and report before/after references/agent-prompts.md (Verification Agent)
94
+ ```
95
+
96
+ **0. Setup.** Context window detection, pre-check, backup, the coordination folder (`COORD_PATH`), hook checks, daemon, smart compaction. Then, only when `python3 "$MEASURE_PY" keepwarm-consent-status` returns `should_ask: true`, follow `references/keepwarm-consent.md` exactly; it spends the user's money, so its wording and command order are fixed.
97
+
98
+ **1. Parallel audit.** Dispatch six agents in one message, each with `COORD_PATH` and its prompt from `references/agent-prompts.md`. They gather and count, so they run on the cheapest capable model; the synthesis is where judgement is spent.
99
+
100
+ | Agent | Writes | Looks at |
101
+ |-------|--------|----------|
102
+ | CLAUDE.md | `audit/claudemd.md` | Size, duplication, tiering, cache structure |
103
+ | MEMORY.md | `audit/memorymd.md` | Size, overlap with CLAUDE.md |
104
+ | Skills | `audit/skills.md` | Count, frontmatter overhead, duplicates |
105
+ | MCP | `audit/mcp.md` | Deferred tools, broken or unused servers |
106
+ | Commands | `audit/commands.md` | Count, menu overhead |
107
+ | Settings and advanced | `audit/advanced.md` | Hooks, rules, settings, @imports, cache lifetime, compaction window |
108
+
109
+ A missing output file is a gap to note, not a reason to stop.
110
+ **2. Synthesis.** One agent on the strongest available model reads every audit file and writes `{COORD_PATH}/analysis/optimization-plan.md`. If it fails, present the raw audit files.
111
+
112
+ **3. Present.** Generate the dashboard and show the findings as the presentation workflow describes, then wait:
113
+
114
+ ```bash
115
+ python3 "$MEASURE_PY" dashboard --coord-path "$COORD_PATH"
116
+ ```
117
+
118
+ **4. Implement.** Only what the user approved, one change at a time, following the playbook (actions 4A-4P: CLAUDE.md, MEMORY.md, skills, file exclusion, MCP, hooks, cache, rules, settings, descriptions, compact instructions, model routing, smart compaction, quality check, version-aware optimizations, smart routing). Templates are in `examples/`. Also offer, with the measured numbers:
119
+
120
+ - `python3 "$MEASURE_PY" recommendations`: the daily-measured usage recommendations (compact window, subagent cache lifetime), each with the user's own numbers and the exact command when the state is `recommend`. Relay those lines verbatim; Token Optimizer recommends, it never sets either key.
121
+ - `python3 "$MEASURE_PY" subagent-cache status` / `compact-advice`: the single-measurement detail behind each item. Both are estimates from the user's own history; the user decides.
122
+ - Repeated work a script could do instead of a model: hand over to `token-coach`, goal e.
123
+
124
+ **5. Verify.** The verification agent re-measures and computes the saving. Show before and after, then the habits that keep it.
125
+
126
+ If a verification number is worse than the baseline, find which change caused it, restore that file from the backup, and return to step 4.
127
+
128
+ ## Rules for changing a user's setup
129
+
130
+ These protect work the user cannot easily get back:
131
+
132
+ - Back up before every change, and show the diff before applying it.
133
+ - Archive, never delete, and archive outside the skills directory so the archive does not load.
134
+ - Check what depends on a skill, MCP server or deny rule before archiving it, and name the side effect first.
135
+ - Prefer a project-level deny rule to a global one.
136
+ - Leave the user's own settings values alone unless they approve the specific change.
137
+ - Quote measured numbers (tokens and percent of the window). Frame savings as context budget; give dollars only where `measure.py` computed them.
138
+
139
+ ## References
140
+
141
+ | Need | Read |
142
+ |------|------|
143
+ | Codex, Cursor, OpenCode workflows | `references/codex-workflow.md`, `references/cursor-workflow.md`, `references/opencode-workflow.md` |
144
+ | Setup details, Keep-Warm consent | `references/phase0-setup.md`, `references/keepwarm-consent.md` |
145
+ | Agent prompts, how tokens flow | `references/agent-prompts.md`, `references/token-flow-architecture.md` |
146
+ | Presenting findings | `references/presentation-workflow.md` |
147
+ | Implementation steps, checklist | `references/implementation-playbook.md`, `references/optimization-checklist.md`, `examples/` |
148
+ | CLI commands, session continuity, errors | `references/cli-reference.md`, `references/session-continuity.md`, `references/error-recovery.md` |
149
+
150
+ Written for and checked on Claude Opus 5.5 and Sonnet 5.5, and GPT-5.6 on Codex.