skills/tokens/SKILL.md
Token-budget observability for godmode loops. Per-round cost tracking, token-log.tsv append, session-end summary, per-skill breakdown, delta vs prior sessions.
npx skillsauth add arbazkhan971/godmode tokensInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
/godmode:tokens, "token budget", "how expensive was this loop", "context cost"GODMODE_TOKENS=0 is set in the environment, this skill is a no-op. Privacy-sensitive workflows (medical, secrets, PII sweeps) can set this to disable all round-size logging for the session. Opt-out is sticky per session; never overridden by auto-activation.Ask once, cache for the session:
session_id — stable id for the run. Default: date +%s at session start, reused across every round.skill — the skill driving the current round (read from session-state.json, not re-asked).round — monotonic counter, read from session-state.json.terse_on — boolean. 1 if $GODMODE_TERSE is non-empty, else 0.rtk_detected — 1 if command -v rtk returns zero, else 0. Logged as environment context, not used for computation.At each round boundary — specifically AFTER the DECIDE/LOG step of the Universal Protocol, so a full round has been emitted:
GODMODE_TOKENS=0. Emit nothing, write nothing.input_chars — sum of bytes of all files READ during this round plus the emit text of the prior round. Source: session-state.json's round_context_files array (maintained by the orchestrator) and .godmode/last-round-emit.txt (atomically rewritten after every round).output_chars — byte count of the current round's emit text, captured into .godmode/last-round-emit.txt as the round closes.cumulative_tokens for this session_id from the last matching row of .godmode/token-log.tsv. Default 0 for round 1..godmode/token-log.tsv with the schema in "TSV Schema".At session end (any stop_reason), emit the summary described in "Output Format".
Exact tokenization varies per model and is not worth a dependency on model-specific libraries for an observability skill. This skill uses one explicit, reproducible rule:
approx_tokens = ceil(char_count / 4)
Rationale: for English prose and code, 1 token averages ~3.8-4.2 characters across GPT-4, Claude, and Llama tokenizers. Dividing by 4 gives a stable, model-agnostic estimate that is wrong by a consistent factor. Since this skill measures trends (is my loop getting more or less expensive?), a stable-biased estimator is sufficient. It is NOT accurate enough for billing, and the skill never claims to be.
Computed with awk — no python, no tiktoken, no external tokenizer binary:
tokens=$(awk -v c="$char_count" 'BEGIN { print int((c + 3) / 4) }')
char_count is wc -c of the measured file or text. Bytes, not graphemes. This is documented here so downstream readers of token-log.tsv can reproduce the math byte-for-byte.
.godmode/token-log.tsv is append-only. Header written on first create:
timestamp session_id round skill input_tokens output_tokens total_tokens terse_on rtk_detected cumulative_tokens
Column meanings:
timestamp — ISO 8601, UTC, second precision.session_id — matches session-state.json.round — integer, 1-indexed, monotonic within a session.skill — name of the driving skill for this round (e.g. optimize, refactor).input_tokens — approximate tokens read as context during the round.output_tokens — approximate tokens emitted by the round.total_tokens — input_tokens + output_tokens.terse_on — 0 or 1. Useful for comparing terse vs. non-terse sessions.rtk_detected — 0 or 1. Useful for comparing environments that have rtk installed (input-side compression) vs. those that do not.cumulative_tokens — running total for this session_id including the current round.Never rewrite history. Never insert. One row per (session_id, round) pair. If a row already exists for that pair, SKIP — do not double-log.
At session end, emit a terse summary line (respects GODMODE_TERSE):
Terse:
Tokens: session={id} rounds={N} total={T} top={skill}({Ttop}) Δ={±pct}% vs last
Normal:
Tokens: session {id} completed {N} rounds, total {T} tokens.
Top skill: {skill} at {Ttop} tokens. Delta vs. last session for same skill: {±pct}%.
With --verbose, also print per-skill breakdown and top-3 expensive rounds:
Per-skill breakdown:
optimize 4 rounds 12800 tok
debug 2 rounds 3400 tok
Top 3 expensive rounds:
R7 optimize 4200 tok (1900 in / 2300 out)
R3 optimize 3800 tok (1700 in / 2100 out)
R5 debug 2100 tok ( 900 in / 1200 out)
Delta vs. last session is computed by scanning token-log.tsv backwards for the previous session_id whose top-skill matches, comparing total tokens, and printing signed percent.
One shell command must answer "is my session's total token consumption going up or down over time?":
awk -F'\t' 'NR>1 { sum[$2]+=$7; t[$2]=$1 } END {
for (s in sum) print t[s], s, sum[s]
}' .godmode/token-log.tsv | sort
This prints every session chronologically with its total. Piping to awk 'NR>1 { printf "%s %d delta=%+d\n", $2, $3, $3 - prev } { prev=$3 }' yields round-over-round deltas. If the last few deltas trend negative, the loop is getting cheaper (terse mode working, rtk helping, prompts tightening). If they trend positive, investigate.
.godmode/token-log.tsv, .godmode/token-log.tsv.*.gz, .godmode/last-round-emit.txt, and the session-end summary it prints to stdout. Touching any source file = abort + fail loud.GODMODE_TOKENS=0 unconditionally. Opt-out wins over every other flag, including --verbose..godmode/, which is committed with the rest of godmode state. Never gitignore token-log.tsv.awk, wc, gzip, date, and standard Unix utilities. No python, no jq, no node, no tiktoken.This skill does not keep or discard anything — it only observes. Rounds driven by other skills may themselves be kept or discarded per the Universal Protocol; the token row is logged either way, with the driving skill's final keep/discard status inferred from results.tsv (not re-measured here). Observing a discarded round is still valuable signal: expensive discards point to skills that burn context without moving the metric.
session_ended — the driving skill hit target_reached, budget_exhausted, diminishing_returns, or stuck. Emit summary, flush any pending row, exit.opted_out — GODMODE_TOKENS=0. Exit silently after the first check.rotation_failed — gzip returned non-zero or disk full. Emit stderr warning, continue without rotating, do NOT lose the active log.On any stop: the last row written is authoritative; the summary reflects exactly what is in token-log.tsv, never more.
development
Web performance optimization. Lighthouse, bundle analysis, code splitting, image optimization, critical CSS, fonts, service workers, CDN.
development
Webhook design, delivery, retry, HMAC verification, event subscriptions, dead letter queues.
development
Vue.js mastery. Composition API, Pinia, Vue Router, Nuxt SSR/SSG, Vite optimization, testing.
development
Evidence gate. Run command, read full output, confirm or deny claim. No trust, only proof.