Skip to content

release: v4.2.0 — real token counts, race-free hooks, cost-math fixes#42

Merged
egorfedorov merged 1 commit into
mainfrom
release/v4.2.0
Jul 4, 2026
Merged

release: v4.2.0 — real token counts, race-free hooks, cost-math fixes#42
egorfedorov merged 1 commit into
mainfrom
release/v4.2.0

Conversation

@egorfedorov

Copy link
Copy Markdown
Owner

Summary

Full audit of the plugin (3 parallel deep reviews) + fixes + one new capability, shipped as v4.2.0.

Ground truth (new)

  • src/transcript-usage.js — the budget hook now reads exact API token usage from the Claude Code session transcript (transcript_path is on every hook event). Budget % and the /cco board show real context usage; chars-per-token estimation remains the fallback. Real numbers drop the ~ prefix.

Fixed

  • $NaN across the /cco-digest cost table (same bug class as fix(report): repair cco-report crash (syntax error) and $NaN cost figures #29/fix(roi): repair $NaN / [object Object] in cco-roi cost table #31, missed in digest.js)
  • /cco-export + /cco-claudemd overstated costs (hardcoded legacy $15/M vs $5/M source of truth)
  • Benchmark measured an empty structure (contents passed where a path was expected) — results.json regenerated honestly
  • Infinityx in /cco-roi at 100% waste
  • tracker/budget hook race on the shared notice ledger (parallel hooks → serialized into one command; same for SessionEnd)
  • Lost global stats when two sessions finalize concurrently (atomic mkdir file lock, stale-steal)
  • O(n²) prompt log rewrites; legacy read-cache entries killing caching; UTC shown as wall-clock

Perf

  • No more multi-MB synchronous reads on the hook hot path; Read estimates ~4× more accurate; per-session state bounded

Docs

  • Real CHANGELOG.md; README drift fixed (/cco-roi, trees, versions); sync-version.js now covers marketplace.json + docs

Test plan

  • npm test: 150/150 (was 139), incl. new regressions for the NaN class, transcript parsing, lock exclusivity/stale-steal, tracker caps
  • Hook chain simulated end-to-end with a fake PostToolUse event + fake transcript: real tokens land in budget state and warnings

🤖 Generated with Claude Code

Ground truth:
- New src/transcript-usage.js: budget hook reads exact API token usage
  from the session transcript (transcript_path); budget % and /cco show
  real context usage, chars-per-token estimation stays as fallback.

Fixes:
- /cco-digest printed $NaN in the whole cost table (tokens * MODEL_COSTS
  object) — same class as the earlier roi/report fixes; alias rows deduped,
  column alignment fixed.
- /cco-export and /cco-claudemd overstated costs 3x (hardcoded legacy $15/M).
- benchmark/run.js passed file contents where parseFileStructure() expects a
  path — every digest scenario measured an empty structure; results.json
  regenerated with honest numbers.
- /cco-roi printed Infinityx at 100% waste — clamped.
- tracker+budget hooks ran in parallel on the same PostToolUse matcher and
  raced on the shared notice ledger — serialized into one chained command
  (same for SessionEnd tracker → dashboard).
- Concurrent session finalization clobbered global-stats/patterns
  (last-writer-wins) — guarded by an atomic mkdir-based file lock with
  stale-steal.
- prompt-coach log: true appendFileSync instead of O(n²) read+rewrite.
- read-cache: legacy entries without ranges/lines no longer throw and
  silently disable caching.
- Session summaries: local wall-clock time instead of raw UTC.

Perf:
- getFileLines() estimates >1MB files from size instead of slurping them on
  the hook hot path.
- Read token estimates capped by real file size + extension-aware ratio
  (~4x more accurate).
- Bounded per-session state: budget filesLoaded (500), tracker search log
  (300).

Honesty:
- "Session pulse" goes through the notice ledger: respects the noise cap,
  counts as overhead in NET savings.

Docs/packaging:
- README: missing /cco-roi + tree entries added, stale v4.0.0 fixed here and
  in docs/index.html; POSIX-shell requirement documented.
- sync-version.js also syncs marketplace.json and docs/index.html.
- Junk CHANGELOG-notes.md removed; real CHANGELOG.md added.

Tests: 139 → 150 (NaN-class regression, size-aware estimates, transcript
usage parsing, file-lock exclusivity/stale-steal, tracker caps).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@egorfedorov egorfedorov merged commit fd92164 into main Jul 4, 2026
5 checks passed
@egorfedorov egorfedorov deleted the release/v4.2.0 branch July 4, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant