@alexgreensh/token-optimizer 5.13.61 → 5.13.63
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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/hooks/sessionstart_runner.py +20 -4
- package/package.json +1 -1
- package/skills/fleet-auditor/scripts/fleet.py +4 -1
- package/skills/fleet-auditor/scripts/shared.py +31 -14
- package/skills/token-optimizer/assets/dashboard.html +397 -68
- package/skills/token-optimizer/pricing/prices.json +6 -1
- package/skills/token-optimizer/scripts/adapter_hook_command.py +94 -0
- package/skills/token-optimizer/scripts/antigravity_doctor.py +12 -0
- package/skills/token-optimizer/scripts/antigravity_hook_bridge.py +4 -0
- package/skills/token-optimizer/scripts/antigravity_install.py +9 -18
- package/skills/token-optimizer/scripts/antigravity_session.py +31 -6
- package/skills/token-optimizer/scripts/codex_install.py +5 -3
- package/skills/token-optimizer/scripts/cursor_doctor.py +12 -27
- package/skills/token-optimizer/scripts/cursor_install.py +11 -19
- package/skills/token-optimizer/scripts/devin_source.py +1 -1
- package/skills/token-optimizer/scripts/grok_doctor.py +12 -24
- package/skills/token-optimizer/scripts/grok_install.py +9 -16
- package/skills/token-optimizer/scripts/measure.py +3887 -616
- package/skills/token-optimizer/scripts/read_cache.py +32 -20
- package/skills/token-optimizer/scripts/refetch_guard.py +9 -3
- package/skills/token-optimizer/scripts/session_store.py +64 -0
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"name": "token-optimizer",
|
|
14
14
|
"source": "./",
|
|
15
15
|
"description": "Audit, fix, and monitor Claude Code context window usage. Find the ghost tokens.",
|
|
16
|
-
"version": "5.13.
|
|
16
|
+
"version": "5.13.63",
|
|
17
17
|
"author": {
|
|
18
18
|
"name": "Alex Greenshpun",
|
|
19
19
|
"url": "https://linkedin.com/in/alexgreensh"
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"name": "token-optimizer-cowork",
|
|
56
56
|
"source": "./cowork/token-optimizer",
|
|
57
57
|
"description": "Token Optimizer for Claude Cowork \u2014 full skills + Cowork-native hooks (beta). Install THIS in Cowork; the standard token-optimizer entry is for desktop Claude Code.",
|
|
58
|
-
"version": "5.13.
|
|
58
|
+
"version": "5.13.63",
|
|
59
59
|
"author": {
|
|
60
60
|
"name": "Alex Greenshpun",
|
|
61
61
|
"url": "https://linkedin.com/in/alexgreensh"
|
|
@@ -8,7 +8,7 @@ runpy(measure.py)`` and repeated the interpreter and module startup work:
|
|
|
8
8
|
1. ``measure.py ensure-health --once-mark`` (timeout 15, async)
|
|
9
9
|
2. ``measure.py quality-cache --force --quiet --once-mark`` (timeout 20)
|
|
10
10
|
3. ``measure.py compact-restore --compact`` [matcher compact] (timeout 20)
|
|
11
|
-
4. ``read_cache.py --clear-compacted --quiet`` [
|
|
11
|
+
4. ``read_cache.py --clear-compacted --quiet`` [source compact|clear] (timeout 10)
|
|
12
12
|
5. ``measure.py compact-restore --new-session-only --once-mark`` (timeout 20)
|
|
13
13
|
|
|
14
14
|
This runner is invoked ONCE per session start, imports ``measure.py`` ONCE, and
|
|
@@ -197,6 +197,20 @@ def _is_compact_start(hook_input: dict) -> bool:
|
|
|
197
197
|
return source == "compact"
|
|
198
198
|
|
|
199
199
|
|
|
200
|
+
def _is_context_reset_start(hook_input: dict) -> bool:
|
|
201
|
+
"""True when this SessionStart follows a /clear or a compaction.
|
|
202
|
+
|
|
203
|
+
Both empty the model's context while the session id lives on, so the
|
|
204
|
+
"already in context" records must be dropped. Only ``compact`` also restores
|
|
205
|
+
state (``_is_compact_start``); ``clear`` is a deliberate fresh start and
|
|
206
|
+
restores nothing.
|
|
207
|
+
"""
|
|
208
|
+
if _is_compact_start(hook_input):
|
|
209
|
+
return True
|
|
210
|
+
source = str(hook_input.get("source") or "").strip().lower()
|
|
211
|
+
return source == "clear"
|
|
212
|
+
|
|
213
|
+
|
|
200
214
|
def _run_safely(name: str, fn, *args, **kwargs) -> None:
|
|
201
215
|
"""Run fn, swallow any failure to the diagnostics log, never propagate.
|
|
202
216
|
|
|
@@ -438,11 +452,11 @@ def _sub_compact_restore_compact(hook_input: dict, sink: list) -> None:
|
|
|
438
452
|
|
|
439
453
|
|
|
440
454
|
def _sub_clear_compacted(hook_input: dict) -> None:
|
|
441
|
-
"""``read_cache.py --clear-compacted --quiet`` (entry 4,
|
|
455
|
+
"""``read_cache.py --clear-compacted --quiet`` (entry 4, source ``compact`` or ``clear``).
|
|
442
456
|
|
|
443
457
|
Mirrors read_cache.main()'s --clear-compacted branch: bail loudly (stderr)
|
|
444
458
|
when the stdin payload is empty, else call handle_clear_compacted(payload,
|
|
445
|
-
quiet=True). read_cache is imported lazily so a
|
|
459
|
+
quiet=True). read_cache is imported lazily so a plain startup or resume --
|
|
446
460
|
the overwhelming majority -- never pays for the import.
|
|
447
461
|
|
|
448
462
|
Emits nothing on stdout by design (all its output, success and failure, goes
|
|
@@ -546,6 +560,7 @@ def _check_consent() -> bool:
|
|
|
546
560
|
def main() -> int:
|
|
547
561
|
hook_input = _read_hook_input()
|
|
548
562
|
is_compact = _is_compact_start(hook_input)
|
|
563
|
+
is_context_reset = _is_context_reset_start(hook_input)
|
|
549
564
|
|
|
550
565
|
# Consent gate. Pre-consolidation, run.py's exempt_commands check matched
|
|
551
566
|
# the literal "ensure-health" arg on hooks.json entry 1, so THAT entry ran
|
|
@@ -600,7 +615,7 @@ def main() -> int:
|
|
|
600
615
|
# matcher:"compact" subcommands only count on a compact start, so a normal
|
|
601
616
|
# start gives its three subcommands a third of the budget each instead of a
|
|
602
617
|
# fifth. Dispatch order matches the hooks.json entry order exactly.
|
|
603
|
-
pending =
|
|
618
|
+
pending = 3 + (1 if is_context_reset else 0) + (1 if is_compact else 0)
|
|
604
619
|
_runner_budget(8, subcommand_count_hint=pending)
|
|
605
620
|
|
|
606
621
|
_capture("ensure-health", _sub_ensure_health, hook_input)
|
|
@@ -608,6 +623,7 @@ def main() -> int:
|
|
|
608
623
|
if is_compact:
|
|
609
624
|
_capture("compact-restore --compact", _sub_compact_restore_compact,
|
|
610
625
|
hook_input, _wrapped)
|
|
626
|
+
if is_context_reset:
|
|
611
627
|
_capture("read_cache --clear-compacted", _sub_clear_compacted, hook_input)
|
|
612
628
|
_capture("compact-restore --new-session-only", _sub_compact_restore_new_session,
|
|
613
629
|
hook_input, _wrapped)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alexgreensh/token-optimizer",
|
|
3
|
-
"version": "5.13.
|
|
3
|
+
"version": "5.13.63",
|
|
4
4
|
"description": "Token Optimizer for Claude Code cloud sessions: the real plugin, installed by your cloud environment's setup script.",
|
|
5
5
|
"license": "PolyForm-Noncommercial-1.0.0",
|
|
6
6
|
"author": "Alex Greenshpun (https://linkedin.com/in/alexgreensh)",
|
|
@@ -979,7 +979,10 @@ class ClaudeCodeAdapter(BaseAdapter):
|
|
|
979
979
|
)
|
|
980
980
|
cc = usage.get("cache_creation_input_tokens", 0) or (cc_1h + cc_5m)
|
|
981
981
|
model_id = msg.get("model", "unknown")
|
|
982
|
-
|
|
982
|
+
# SDK and imported transcripts carry only the message id, which
|
|
983
|
+
# repeats across the streamed chunks of one reply the same way.
|
|
984
|
+
req_id = record.get("requestId") or (
|
|
985
|
+
msg.get("id") if isinstance(msg, dict) else None)
|
|
983
986
|
current = {
|
|
984
987
|
"input": inp_tok,
|
|
985
988
|
"output": out_tok,
|
|
@@ -58,6 +58,27 @@ _KNOWN_PROVIDER_PREFIXES = {
|
|
|
58
58
|
# Model normalization
|
|
59
59
|
# ---------------------------------------------------------------------------
|
|
60
60
|
|
|
61
|
+
_GEMINI_ALIASES = (
|
|
62
|
+
"gemini-3.1-pro-preview",
|
|
63
|
+
"gemini-3.1-flash-lite",
|
|
64
|
+
"gemini-3.5-flash",
|
|
65
|
+
"gemini-3.1-pro",
|
|
66
|
+
"gemini-3-flash",
|
|
67
|
+
"gemini-3-pro",
|
|
68
|
+
"gemini-2.5-flash-lite",
|
|
69
|
+
"gemini-2.5-flash",
|
|
70
|
+
"gemini-2.5-pro",
|
|
71
|
+
)
|
|
72
|
+
|
|
73
|
+
# A dated or numbered snapshot of a priced id: -2026-01-01, -20260101, -0613,
|
|
74
|
+
# -001 or @20260101. Any other suffix names a different model.
|
|
75
|
+
_SNAPSHOT_RE = re.compile(r"(?:-\d{4}-\d{2}-\d{2}|-\d{8}|-\d{3,4}|@\d{8})")
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _is_card_or_snapshot(model: str, alias: str) -> bool:
|
|
79
|
+
return model == alias or (model.startswith(alias) and _SNAPSHOT_RE.fullmatch(model, len(alias)) is not None)
|
|
80
|
+
|
|
81
|
+
|
|
61
82
|
def normalize_model_name(model_id: str) -> str | None:
|
|
62
83
|
"""Collapse model IDs like 'claude-sonnet-4-6' into 'sonnet'.
|
|
63
84
|
|
|
@@ -109,23 +130,19 @@ def normalize_model_name(model_id: str) -> str | None:
|
|
|
109
130
|
"o4-mini",
|
|
110
131
|
"o3",
|
|
111
132
|
):
|
|
112
|
-
if m
|
|
133
|
+
if _is_card_or_snapshot(m, alias):
|
|
113
134
|
return alias
|
|
114
|
-
if m
|
|
135
|
+
if m in ("gpt-5.6", "gpt-5.6-sol-pro") or _is_card_or_snapshot(m, "gpt-5.6"):
|
|
115
136
|
return "gpt-5.6-sol"
|
|
116
|
-
for alias in
|
|
117
|
-
|
|
118
|
-
"gemini-3.1-flash-lite",
|
|
119
|
-
"gemini-3.5-flash",
|
|
120
|
-
"gemini-3.1-pro",
|
|
121
|
-
"gemini-3-flash",
|
|
122
|
-
"gemini-3-pro",
|
|
123
|
-
"gemini-2.5-flash-lite",
|
|
124
|
-
"gemini-2.5-flash",
|
|
125
|
-
"gemini-2.5-pro",
|
|
126
|
-
):
|
|
127
|
-
if m == alias or m.startswith(alias + "-"):
|
|
137
|
+
for alias in _GEMINI_ALIASES:
|
|
138
|
+
if _is_card_or_snapshot(m, alias):
|
|
128
139
|
return alias
|
|
140
|
+
# A preview build of a priced Gemini model is the same model.
|
|
141
|
+
base = re.sub(r"-preview(?:-\d{2}-\d{2,4})?$", "", m)
|
|
142
|
+
if base != m and base.startswith("gemini-"):
|
|
143
|
+
for alias in _GEMINI_ALIASES:
|
|
144
|
+
if _is_card_or_snapshot(base, alias):
|
|
145
|
+
return alias
|
|
129
146
|
return m
|
|
130
147
|
|
|
131
148
|
|