@alexgreensh/token-optimizer 0.0.0-stage → 5.13.51

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 +448 -0
  10. package/hooks/posttooluse_runner.py +1110 -0
  11. package/hooks/python-launcher.sh +816 -0
  12. package/hooks/run.py +788 -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 +149 -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 +3633 -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 +141 -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 +93 -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 +379 -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 +1011 -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 +288 -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 +426 -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 +400 -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 +716 -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 +59531 -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 +1923 -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,92 @@
1
+ # CLI Reference
2
+
3
+ ## Core Commands
4
+
5
+ - `measure.py report` -- Token overhead report with per-component breakdown
6
+ - `measure.py snapshot [label]` -- Save a measurement snapshot
7
+ - `measure.py compare` -- Compare before/after snapshots
8
+ - `measure.py dashboard [--coord-path PATH]` -- Generate interactive HTML dashboard
9
+ - `measure.py setup-daemon [--uninstall]` -- Bookmarkable dashboard URL (macOS/Windows)
10
+ - `measure.py trends [--days N] [--json]` -- Skill adoption, model mix, overhead over time
11
+ - `measure.py health` -- Session hygiene: stale/zombie sessions, version checks
12
+
13
+ ## Quality & Compaction
14
+
15
+ - `measure.py quality [session-id|current]` -- 7-signal quality score (0-100)
16
+ - `measure.py setup-smart-compact [--dry-run|--status|--uninstall]` -- Smart Compaction hooks
17
+ - `measure.py compact-capture` -- Internal: checkpoint before compaction
18
+ - `measure.py compact-restore` -- Internal: restore after compaction
19
+ - `measure.py compact-instructions [--json]` -- Generate project-specific compaction guidance
20
+ - `measure.py list-checkpoints [--cwd PATH] [--max-age MINUTES]` -- List session checkpoints
21
+
22
+ ## Active Compression (v5)
23
+
24
+ - `measure.py v5 status` -- Show all features with current state
25
+ - `measure.py v5 enable|disable <feature>` -- Toggle a feature
26
+ - `measure.py v5 info <feature>` -- Full details for one feature
27
+ - `measure.py compression-stats [--days N]` -- Measured savings from local telemetry
28
+
29
+ ## Context Tools
30
+
31
+ - `measure.py git-context [--json]` -- Suggest files based on git state
32
+ - `measure.py read-cache-stats --session ID` -- Cache stats for a session
33
+ - `measure.py read-cache-clear` -- Clear all caches
34
+ - `measure.py attention-score` -- Score CLAUDE.md attention placement
35
+ - `measure.py attention-optimize --dry-run` -- Preview optimized section order
36
+ - `measure.py memory-review [--json|--apply|--stale-days N]` -- MEMORY.md structural audit
37
+
38
+ ## Model Routing
39
+
40
+ - `measure.py inject-routing [--dry-run]` -- Inject model routing block into CLAUDE.md
41
+ - `measure.py setup-coach-injection [--uninstall]` -- Inject coaching block
42
+
43
+ ## Deterministic Candidates
44
+
45
+ - `measure.py deterministic-candidates [--days N] [--json] [--budget SECONDS] [--max-sessions N] [--no-cache]` -- Parts of your workflow that could be plain code instead of model calls: repeated tool-call sequences (3+ calls in 3+ sessions), templated subagent launches (5+), polling loops (the same literal command, or a `sleep`-and-recheck pattern, 4+ times with no edit between), parameter sweeps (one normalised command shape run 4+ times over distinct parameters), and passing test/build/lint turns whose reply was short. Local, read-only, no model calls; every figure is "measured on your transcripts". `tokens` and `cost_usd` are what the turns that ran those calls used (whole-turn input including cache reads, plus output; API-equivalent dollars), not what a script would save: moving a step to code removes those turns, so the saving is at most this much. An inline script (`python3 - <<'EOF'`, `python3 -c`, `bash -c`, `node -e`, `ruby -e`, `perl -e`, here-strings) counts as the same command only when its body matches, examples are credential-redacted command shapes, top 10 by tokens. Default window 30 days; the progress line goes to stderr, at most every 2 s, and only when stderr is a terminal; results are cached in the Token Optimizer data dir keyed by the newest transcript. `measure.py coach --json` carries the same block as `deterministic_candidates` (8 s budget, `"partial": true` if it ran out). Claude Code and Codex are measurable; other runtimes return `not measurable on <runtime>`.
46
+
47
+ ## JSONL Toolkit
48
+
49
+ - `measure.py jsonl-inspect` -- Stats, record counts, largest records
50
+ - `measure.py jsonl-trim --dry-run` -- Preview trimming large tool results
51
+ - `measure.py jsonl-dedup --dry-run` -- Preview removing duplicate reminders
52
+
53
+ ## Other
54
+
55
+ - `measure.py savings` -- Cumulative dollar savings report
56
+ - `measure.py expand [--list|<tool-use-id>|--search <query>]` -- Retrieve archived tool results, or search by keyword/lineage
57
+ - `measure.py setup-hook [--uninstall]` -- SessionEnd tracking hook
58
+ - `measure.py setup-quality-bar [--uninstall]` -- Terminal status line
59
+ - `measure.py plugin-cleanup` -- Detect duplicate skills and archive overlaps
60
+ - `measure.py check-hook` -- Check if SessionEnd hook is installed
61
+ - `measure.py recommendations [status|refresh] [--json]` -- The daily-measured usage recommendations record (compact window, subagent cache lifetime): `status` (default) prints it, `refresh` re-measures now in a bounded run. Advice only; never writes either setting (Claude Code)
62
+
63
+ ## Codex Commands
64
+
65
+ - `measure.py codex-install --project PATH [--profile balanced|quiet|telemetry|aggressive]`
66
+ - `measure.py codex-doctor --project PATH [--json]`
67
+ - `measure.py codex-compact-prompt [--install|--uninstall|--status]`
68
+ - `measure.py codex-skill [enable|disable] NAME`
69
+ - `measure.py codex-mcp [enable|disable] NAME`
70
+
71
+ ## Cursor Commands
72
+
73
+ - `measure.py cursor-install` -- Wire Token Optimizer into `~/.cursor/hooks.json` (read-merge-write)
74
+ - `measure.py cursor-uninstall` -- Remove only Token Optimizer's hook entries + payload
75
+ - `measure.py cursor-doctor [--json]` -- Readiness report (binary, home, hooks, payload, data planes, daemon port 24846)
76
+ - `measure.py cursor-doctor --probe` -- Replay each wired event through the installed command
77
+ - `TOKEN_OPTIMIZER_RUNTIME=cursor measure.py cursor-summary` -- Token/quality session summary (no cost headline by design)
78
+ - `TOKEN_OPTIMIZER_RUNTIME=cursor measure.py cursor-rollup` -- Ingest Cursor sessions into the trends DB
79
+
80
+ ## Feature Controls
81
+
82
+ ### Read-Cache
83
+ - Default ON (warn mode). Disable: `TOKEN_OPTIMIZER_READ_CACHE=0`
84
+ - Modes: `TOKEN_OPTIMIZER_READ_CACHE_MODE=warn` (default) or `=block`
85
+ - Decisions log: `~/.claude/token-optimizer/read-cache/decisions/`
86
+
87
+ ### Efficiency Grading
88
+ Grades: S (90-100), A (80-89), B (70-79), C (55-69), D (40-54), F (0-39).
89
+ Shown in status line (`ContextQ:A(82)`), dashboard, coach, and CLI.
90
+
91
+ ### .contextignore
92
+ Create `.contextignore` in project root or `~/.claude/.contextignore` (global). Uses gitignore-style glob patterns. Hard-blocks regardless of read-cache mode.
@@ -0,0 +1,188 @@
1
+ # Codex Runtime: Chat-First Workflow
2
+
3
+ If this skill is running in Codex, use this section instead of the Claude Code phases. The user is not asking for a dashboard first. They are asking for a coach who can tell them:
4
+
5
+ - What is my status?
6
+ - What is my setup?
7
+ - What is wasteful or risky?
8
+ - What should we fix, and what should we leave alone?
9
+ - What behavior should I change during long Codex sessions?
10
+
11
+ ## Contents
12
+
13
+ - [0. Resolve `measure.py` for Codex](#0-resolve-measurepy-for-codex)
14
+ - [1. Start With Chat Status](#1-start-with-chat-status)
15
+ - [2. Codex Setup Fixes](#2-codex-setup-fixes)
16
+ - [3. Codex Optimization Actions](#3-codex-optimization-actions)
17
+ - [4. Codex Runtime Optimizations That Work Now](#4-codex-runtime-optimizations-that-work-now)
18
+ - [5. Codex Features That Are Not Full Parity Yet](#5-codex-features-that-are-not-full-parity-yet)
19
+ - [6. Codex Chat Close](#6-codex-chat-close)
20
+
21
+ ---
22
+
23
+ ## 0. Resolve `measure.py` for Codex
24
+
25
+ ```bash
26
+ # Resolve measure.py to the NEWEST installed copy across channels so a stale
27
+ # plugin-cache copy never shadows a fresh install. find -L follows the
28
+ # install.sh symlink; cd -P resolves it before reading each copy's plugin.json for
29
+ # its version. find (not bare globs) never errors under zsh. measure.py's own
30
+ # behavior is scoped by $TOKEN_OPTIMIZER_RUNTIME, not by which path loaded it.
31
+ MEASURE_PY=""; _best_ver=""
32
+ while IFS= read -r _cand; do
33
+ [ -f "$_cand" ] || continue
34
+ _root="$(cd -P -- "$(dirname -- "$_cand")/../../.." 2>/dev/null && pwd)"
35
+ _ver="$(sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$_root/.claude-plugin/plugin.json" 2>/dev/null | head -1)"
36
+ [ -n "$_ver" ] || _ver="0.0.0"
37
+ 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
38
+ _best_ver="$_ver"; MEASURE_PY="$_cand"
39
+ fi
40
+ done <<EOF
41
+ $(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)
42
+ EOF
43
+ if [ -z "$MEASURE_PY" ]; then echo "[Error] measure.py not found. Is Token Optimizer installed?"; exit 1; fi
44
+ echo "Using: $MEASURE_PY"
45
+ ```
46
+
47
+ Use `TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" ...` for Codex commands.
48
+
49
+ ## 1. Start With Chat Status
50
+
51
+ Run these before giving advice:
52
+
53
+ ```bash
54
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" report
55
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" coach --json
56
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" quality current --json
57
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-state --json
58
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-doctor --project "$PWD" --json
59
+ ```
60
+
61
+ `codex-state` reads Codex's versioned SQLite state read-only (`state_*.sqlite`, `goals_*.sqlite`): subagent count and token cost (with leaked/never-closed subagents), memory overhead from `stage1_outputs`, and goal budget utilization. It is empty-safe when those tables have no rows yet.
62
+
63
+ If `quality current` has no parseable session, continue without it. Do not block the audit.
64
+
65
+ Present the result conversationally:
66
+
67
+ ```
68
+ Here is your Codex Token Optimizer status:
69
+
70
+ STATUS
71
+ - Health score: X/100
72
+ - Startup overhead: X tokens, Y% of your Codex window
73
+ - Usable context after overhead/buffer: ~X tokens
74
+ - Current session quality: grade/score, if available
75
+
76
+ SETUP
77
+ - AGENTS.md: X tokens
78
+ - Codex memory: X tokens of densified memory (state_*.sqlite stage1_outputs)
79
+ - Subagents: X total, Y leaked (open + stale), Z tokens of subagent cost
80
+ - Goals: X active, any budget-limited/usage-limited
81
+ - Skills/plugin skills: X active, Y tokens of discovery surface
82
+ - MCP: X servers
83
+ - Hooks: balanced / quiet / missing / custom
84
+ - Compact prompt: installed / missing / custom
85
+ - Status line: installed / missing / custom
86
+
87
+ GOOD NEWS
88
+ - [2-3 things that are already healthy]
89
+
90
+ TOP FIXES
91
+ 1. [fix, estimated value, risk]
92
+ 2. [fix, estimated value, risk]
93
+ 3. [fix, estimated value, risk]
94
+
95
+ BEHAVIOR COACHING
96
+ - [how to compact/clear/batch/use subagents for this user]
97
+ ```
98
+
99
+ Be plainspoken. Avoid selling features. Tell the user what matters for their setup.
100
+
101
+ ## 2. Codex Setup Fixes
102
+
103
+ Use `codex-doctor` as the setup truth source.
104
+
105
+ If hooks are missing or stale:
106
+
107
+ ```bash
108
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-install --project "$PWD" --dry-run
109
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-install --project "$PWD"
110
+ ```
111
+
112
+ Default to the balanced profile. Balanced means:
113
+
114
+ - `SessionStart`: recovery context when Codex can use it.
115
+ - `UserPromptSubmit`: prompt-quality and loop nudges.
116
+ - `SubagentStart`/`SubagentStop`: silent subagent counting with a sprawl nudge when too many run concurrently (opt out with `--no-subagent-hooks`).
117
+ - `Stop`: throttled dashboard refresh and continuity checkpoints.
118
+ - Codex compact prompt in `~/.codex/config.toml`.
119
+
120
+ Only suggest these when the user accepts the tradeoff:
121
+
122
+ ```bash
123
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-install --project "$PWD" --profile quiet
124
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-install --project "$PWD" --profile telemetry
125
+ TOKEN_OPTIMIZER_RUNTIME=codex python3 "$MEASURE_PY" codex-install --project "$PWD" --profile aggressive
126
+ ```
127
+
128
+ Quiet is Stop-only. Telemetry adds visible PostToolUse rows. Aggressive enables all current hooks, including experimental Bash PreToolUse. Do not make aggressive the default.
129
+
130
+ ## 3. Codex Optimization Actions
131
+
132
+ Use these as the Codex equivalent of Phase 4:
133
+
134
+ | Action | What To Inspect | Safe Fix |
135
+ |---|---|---|
136
+ | AGENTS.md | Global/project `AGENTS.md` and `AGENTS.override.md` size, duplication, volatile content | Keep root guidance lean; move long workflows into skills or referenced docs |
137
+ | Codex memory | `codex-state` memory overhead (densified `stage1_outputs` in `state_*.sqlite`; the legacy `~/.codex/memories/` dir is deprecated) | Memory is auto-densified by Codex; flag only when overhead is large relative to the window |
138
+ | Subagent sprawl | `codex-state` subagent count, token cost, and leaked (open + stale) subagents | Close finished subagents; consolidate work; high leaked counts mean agents never closed cleanly |
139
+ | Goal budgets | `codex-state` goal utilization and budget-limited/usage-limited status | When a goal is budget/usage limited, raise its budget deliberately or split the work |
140
+ | Skills/plugin skills | `coach`, `report`, dashboard Manage data | Disable stale user skills with `measure.py codex-skill disable`; do not edit plugin cache directly |
141
+ | MCP servers | Codex config MCP inventory | Disable unused servers with `measure.py codex-mcp disable NAME` after checking whether the user actually uses them |
142
+ | Hooks | `codex-doctor`, `.codex/hooks.json` | Install/update balanced hooks; keep per-tool hooks opt-in |
143
+ | Compact guidance | `codex-compact-prompt --status` | Install `measure.py codex-compact-prompt --install`; use compact around phase boundaries |
144
+ | Quality/session rot | `quality current`, `coach` | Recommend `/compact`, `/clear`, rereads, or batching based on the actual score |
145
+ | Cost/model behavior | Trends/model mix when available | Codex uses intelligence levels (Low/Medium/High/Extra High) and model selection (GPT-5.6 Sol/Terra/Luna, GPT-5.5, GPT-5.4, GPT-5.4-Mini, GPT-5.3-Codex, GPT-5.2). Advise on reasoning effort settings, using Luna or Terra for routine tasks, and using lower intelligence for simple operations |
146
+
147
+ Always explain side effects before changing config. Prefer dry-runs before writes.
148
+
149
+ ## 4. Codex Runtime Optimizations That Work Now
150
+
151
+ - Real Codex status in chat via `report` and `coach`.
152
+ - Context quality scoring from Codex JSONL where logs expose enough data, including OpenAI/GPT-5.6 long-context calibration.
153
+ - Balanced hooks for prompt-quality nudges, topic-relevant continuity hints, session continuity, and dashboard refresh.
154
+ - Quality-aware checkpoints that preserve score, weakest signals, model/window metadata, decisions, files, and next step.
155
+ - Stop-time backfill of large/high-signal Codex tool outputs into the local archive and SQLite session store, without enabling noisy per-tool hooks by default.
156
+ - Read-only Codex state metrics via `codex-state`: subagent token cost and leak detection (`thread_spawn_edges` + `threads`), memory overhead (`stage1_outputs`), and goal budget utilization (`thread_goals`). Historical and complete, no hooks required.
157
+ - Modern subagent parsing from `collab_agent_spawn_end`/`collab_close_end` events plus legacy `spawn_agent`, so multi-agent Codex sessions are no longer invisible.
158
+ - Compaction compression measured per session (post-compaction context vs. pre-compaction occupancy from `compacted.replacement_history` + per-turn token counts).
159
+ - Rate-limit, per-turn effort, and tool/turn duration signals parsed from the Codex transcript.
160
+ - Optional `SubagentStart`/`SubagentStop` hooks for real-time sprawl nudges.
161
+ - Compact prompt installation in `~/.codex/config.toml`.
162
+ - Codex native `[tui]` status line configuration (coexists with the v0.131+ blended-token display; never clobbers a custom config without `--force`).
163
+ - Skill/plugin/MCP inventory and enable/disable commands.
164
+ - Bounded log parsing so huge Codex transcripts do not burn CPU.
165
+ - Explicit file outline tools (`outline.py`, structure helpers) when the user asks to inspect a large file before rereading it.
166
+
167
+ ## 5. Codex Features That Are Not Full Parity Yet
168
+
169
+ Be honest about these. Do not imply they are working invisibly:
170
+
171
+ - Delta read substitution is not active in Codex.
172
+ - Structure-map substitution is not active in Codex.
173
+ - Invisible Bash command rewriting/compression is not reliable in current Codex; keep it experimental and opt-in.
174
+ - Claude-style `PreCompact`/`PostCompact` hook parity is approximated with compact prompts and checkpoints; compaction quality is now measured after the fact from the transcript.
175
+ - Cache-write TTL breakdowns are limited by what Codex logs expose.
176
+ - Tool-result archiving in balanced mode happens at Stop, not immediately after each tool call.
177
+ - For generic Codex runtime/auth/network health, defer to the native `codex doctor`; Token Optimizer's `codex-doctor` focuses on token and optimization setup.
178
+
179
+ ## 6. Codex Chat Close
180
+
181
+ After presenting status, ask for a concrete next step:
182
+
183
+ ```
184
+ My recommendation: fix [one thing] first because it gives the most value with the least risk.
185
+ Want me to apply that, or do you want the conservative cleanup list first?
186
+ ```
187
+
188
+ Do not end with only a dashboard link. The dashboard is supporting evidence, not the main experience.
@@ -0,0 +1,74 @@
1
+ # Cursor Runtime
2
+
3
+ You reached this file because the token-optimizer skill was invoked from inside
4
+ **Cursor** (IDE or `agent` CLI). Cursor loads `~/.claude/skills` by default, so
5
+ it can pick up this Claude Code skill even though the user is not in Claude Code.
6
+
7
+ **Do not run the Claude Code audit/fix phases.** They scan and modify `~/.claude`
8
+ (skills, plugins, settings, MEMORY.md). When the user is working in Cursor,
9
+ mutating `~/.claude` is the wrong target. Token Optimizer's own Cursor data lives
10
+ under `~/.cursor/token-optimizer/` (override with `TOKEN_OPTIMIZER_CURSOR_HOME`),
11
+ never `~/.claude`.
12
+
13
+ ## How Token Optimizer works on Cursor
14
+
15
+ Cursor support is a hook bridge, not this Python audit. Once installed, the
16
+ bridge wires six Cursor hook events and runs automatically:
17
+
18
+ | Event | What Token Optimizer does |
19
+ |-------|---------------------------|
20
+ | `sessionStart` | Injects per-workspace continuity restore context (if a rollup produced one) |
21
+ | `preToolUse` (Shell) | Bash compression rewrite; fails closed (emits nothing) on any uncertainty |
22
+ | `postToolUse` | Updates the durable session tally; emits context-growth nudges |
23
+ | `preCompact` | Captures a compaction checkpoint in the tally |
24
+ | `stop` | Detached rollup (throttled to once per 120s per machine) |
25
+ | `sessionEnd` | Detached rollup + dashboard refresh |
26
+
27
+ All hooks are fail-open: they never block or deny a Cursor session, and every
28
+ event appends one line to `~/.cursor/token-optimizer/observed-events.jsonl` so
29
+ readiness is provable without a live Cursor.
30
+
31
+ ## Commands
32
+
33
+ The audit phases do not run under Cursor. Use the Cursor-native commands
34
+ instead. Manual `cursor-summary` / `cursor-rollup` require the runtime prefix
35
+ (the bridge sets it automatically):
36
+
37
+ ```bash
38
+ python3 "$MEASURE_PY" cursor-install # wire Token Optimizer into ~/.cursor/hooks.json
39
+ python3 "$MEASURE_PY" cursor-doctor # readiness report (checks + fix hints)
40
+ python3 "$MEASURE_PY" cursor-doctor --probe # replay each wired event through the installed command
41
+ TOKEN_OPTIMIZER_RUNTIME=cursor python3 "$MEASURE_PY" cursor-summary
42
+ TOKEN_OPTIMIZER_RUNTIME=cursor python3 "$MEASURE_PY" cursor-rollup
43
+ python3 "$MEASURE_PY" cursor-uninstall # remove only Token Optimizer's entries + payload
44
+ ```
45
+
46
+ Install from a checkout with `bash install.sh --cursor` (merges into Cursor's
47
+ shared `~/.cursor/hooks.json`, preserving other tools' entries).
48
+
49
+ ## Honest posture
50
+
51
+ Cursor stores no local billing data, so Token Optimizer reports **no cost /
52
+ savings headline** for Cursor (`cost_source = "cursor_no_cost_data"`). Bash
53
+ compression events are still counted. Token counts are best-effort: the hook
54
+ tally is authoritative for calls/turns/compactions; tokens come from
55
+ `state.vscdb` (IDE) or a chars-over-four transcript estimate (CLI).
56
+
57
+ ## Why the Python skill stops here
58
+
59
+ - The audit is Claude Code / Codex specific: it scans `~/.claude` structure.
60
+ - Cursor stores config under `~/.cursor` with a different layout. A Claude-shaped
61
+ audit would either error or mutate the wrong home.
62
+ - The bridge's data dir is `~/.cursor/token-optimizer/`, never `~/.claude`.
63
+
64
+ ## Escape hatch
65
+
66
+ If the user genuinely wants to audit a Claude Code setup *from* Cursor (rare),
67
+ they can force the runtime:
68
+
69
+ ```bash
70
+ TOKEN_OPTIMIZER_RUNTIME=claude python3 "$MEASURE_PY" report
71
+ ```
72
+
73
+ This is opt-in and explicit. The default under Cursor is to never touch
74
+ `~/.claude`.
@@ -0,0 +1,37 @@
1
+ # Error Handling & Recovery
2
+
3
+ This file covers the Claude Code audit phases (0-5). For Codex error handling, see `codex-workflow.md`.
4
+
5
+ ## Error Handling
6
+
7
+ - **Agent timeout/failure**: Note the gap and continue. Do not retry. Synthesis handles missing files.
8
+ - **No CLAUDE.md found**: Report 0 tokens, skip to skills audit.
9
+ - **No skills directory**: Report 0 tokens, note as "fresh setup."
10
+ - **measure.py not found**: Fall back to manual estimation (line count x 15 for prose, x 8 for YAML).
11
+ - **Coordination folder write failure**: Abort and report. Do not proceed without audit storage.
12
+ - **Backup write failure**: Warn user and ask whether to proceed without backup.
13
+ - **mktemp failure**: Print error and abort. Check write permission on the project folder.
14
+ - **Synthesis agent failure**: Present raw audit files to user. Do not proceed to Phase 4 blindly.
15
+ - **Verification agent failure**: Fall back to `measure.py snapshot after` + `measure.py compare`.
16
+ - **Snapshot file corrupt**: Re-run `measure.py snapshot [label]` to regenerate.
17
+ - **Stale snapshot warning**: If "before" snapshot is >24h old, warn. Consider re-taking.
18
+
19
+ ## Restoring Backups
20
+
21
+ ```bash
22
+ ls -ltd ~/.claude/_backups/token-optimizer-* | head -5
23
+
24
+ BACKUP="$HOME/.claude/_backups/token-optimizer-TIMESTAMP"
25
+ cp "$BACKUP/CLAUDE.md" ~/.claude/CLAUDE.md
26
+ cp "$BACKUP/settings.json" ~/.claude/settings.json
27
+ cp -r "$BACKUP/commands" ~/.claude/commands
28
+ for f in "$BACKUP"/MEMORY-*.md; do
29
+ [ -f "$f" ] || continue
30
+ projname="${f##*/MEMORY-}"; projname="${projname%.md}"
31
+ case "$projname" in *..* | */* ) echo "[Warning] Skipping suspicious backup: $f"; continue ;; esac
32
+ [ -d "$HOME/.claude/projects/${projname}/memory" ] || continue
33
+ cp "$f" "$HOME/.claude/projects/${projname}/memory/MEMORY.md"
34
+ done
35
+ ```
36
+
37
+ Backups are never automatically deleted. They accumulate in `~/.claude/_backups/`.