@tokelang-lite/claude-code-skill 1.0.0

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.
@@ -0,0 +1,73 @@
1
+ ---
2
+ name: tokelang-stats
3
+ description: >
4
+ Show savings for the current session — tokens compressed, % reduction, and an approximate
5
+ dollar figure at Anthropic's published input rate. Reads this session's local sidecar via
6
+ the bundled CLI; no network call. Counts only what the skill compresses (Task subagent
7
+ prompts + /tokelang-compress file runs).
8
+ Trigger: /tokelang-stats
9
+ ---
10
+
11
+ # Session savings stats
12
+
13
+ Reports what Tokelang has saved you in the current Claude Code session.
14
+
15
+ ## Trigger
16
+
17
+ - `/tokelang-stats` — explicit
18
+ - "show tokelang savings" — natural language
19
+
20
+ ## Process
21
+
22
+ 1. Resolve the current session id (Claude Code supplies it to the hooks; the sidecar is named for it).
23
+
24
+ 2. Run the bundled CLI over this session's sidecar — the file the hooks append a
25
+ `surface,orig_tokens,comp_tokens,unix_ts` line to on every compression event:
26
+ ```bash
27
+ "${CLAUDE_PLUGIN_ROOT}/bin/tokelang-cli" stats --transcript ~/.claude/.tokelang-session-<session_id>
28
+ ```
29
+ It emits JSON: `{events, original_tokens, compressed_tokens, tokens_saved, pct_saved}`. All token
30
+ counts are real cl100k (computed in-process; no network).
31
+
32
+ 3. Convert `tokens_saved` to an approximate dollar figure at the model's published input rate
33
+ (e.g. Sonnet 4.6 input $3/MTok) for display.
34
+
35
+ 4. Print summary:
36
+ ```
37
+ Tokelang — this session
38
+ Compression events: 14 (subagent prompts + any /tokelang-compress file runs)
39
+ Input tokens saved: 4,287 (32% reduction)
40
+ Estimated $ saved: ~$0.013 (input $3/MTok)
41
+ ```
42
+
43
+ > **Not counted** (be honest about scope): per-turn user input — the plugin can't rewrite it, so use
44
+ > `tokelang-cli wrap` for that; **tool results** — Claude Code's PostToolUse hook is additive-only, so
45
+ > the in-loop tool-result gap is a known v1.0.0 limitation; and model output — never post-processed.
46
+ > Stats reflect only what the skill actually compresses.
47
+
48
+ ## Lifetime stats (statusline)
49
+
50
+ The statusline shows **lifetime** cumulative savings across all your Claude Code sessions — different from this command which shows current-session only. Lifetime stats live in `~/.claude/.tokelang-lifetime.json` and update on every `Stop` hook.
51
+
52
+ ## Why both per-session AND lifetime?
53
+
54
+ - Per-session — useful when debugging "did Tokelang actually compress my last turn?"
55
+ - Lifetime — useful when justifying ROI ("$X.XX saved last month")
56
+
57
+ ## What this command does NOT do
58
+
59
+ - Phone home (everything is computed locally from `$CLAUDE_TRANSCRIPT_PATH`)
60
+ - Include the hosted API's compression stats (separate product)
61
+ - Predict future savings (no forecasting)
62
+
63
+ ## Example
64
+
65
+ ```
66
+ > /tokelang-stats
67
+
68
+ Tokelang — this session
69
+ Compression events: 9 (subagent prompts)
70
+ Input tokens saved: 1,840 / 5,210 (35%)
71
+ Estimated $ saved: ~$0.006 (input $3/MTok)
72
+ Lifetime savings: tracked in ~/.claude/.tokelang-lifetime.json (shown in the statusline)
73
+ ```
@@ -0,0 +1,82 @@
1
+ ---
2
+ name: tokelang-telemetry
3
+ description: >
4
+ Turn Tokelang's opt-in usage metrics on or off. OFF by default. When ON, only AGGREGATE
5
+ token-savings counts are sent (per session) — never prompt content, file paths, or session
6
+ ids. Toggling writes ~/.claude/.tokelang-telemetry.json. Trigger: /tokelang-telemetry [on|off]
7
+ ---
8
+
9
+ # Telemetry (opt-in, off by default)
10
+
11
+ Tokelang sends **nothing** unless you explicitly turn this on. When on, the Stop hook sends one
12
+ small aggregate ping per session so the project can see real-world savings in the aggregate.
13
+
14
+ ## What is / isn't sent
15
+
16
+ **Sent (aggregate only):** schema version, CLI version, level, coarse OS/arch, this session's
17
+ `tokens_saved` + event count, and lifetime `tokens_saved` + session count, plus a random
18
+ `anon_id` (generated locally at opt-in, for de-duplicating installs).
19
+
20
+ **Never sent:** prompt text, responses, file paths, file names, session ids, repo info, or
21
+ anything derived from your content. The session sidecar the ping is built from only ever stores
22
+ `surface,orig_tokens,comp_tokens,timestamp` per event — there is no content in it to leak.
23
+
24
+ Endpoint: `https://tokelang.com/v1/telemetry` (override with `TOKELANG_TELEMETRY_ENDPOINT`).
25
+ The ping is best-effort: it needs `curl`, is capped at 3s, and is fired detached so it can
26
+ never block or fail your session.
27
+
28
+ ## Trigger
29
+
30
+ - `/tokelang-telemetry on` — opt in
31
+ - `/tokelang-telemetry off` — opt out (the default state)
32
+ - `/tokelang-telemetry` (no arg) — show current status and exactly what would be sent
33
+
34
+ ## Process
35
+
36
+ Parse the argument (case-insensitive). The state lives in `~/.claude/.tokelang-telemetry.json`.
37
+
38
+ ### on
39
+ Run this (preserves an existing `anon_id`, otherwise generates a fresh random one):
40
+
41
+ ```bash
42
+ F="${HOME}/.claude/.tokelang-telemetry.json"
43
+ AID="$(jq -r '.anon_id // empty' "$F" 2>/dev/null)"
44
+ [ -z "$AID" ] && AID="$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen 2>/dev/null || python3 -c 'import uuid;print(uuid.uuid4())' 2>/dev/null || echo "anon-$(date +%s)-$RANDOM")"
45
+ mkdir -p "${HOME}/.claude"
46
+ jq -n --arg aid "$AID" '{enabled:true, anon_id:$aid}' > "$F"
47
+ echo "Telemetry ON. Aggregate token-savings metrics only — never prompt content. anon_id=$AID"
48
+ ```
49
+
50
+ ### off
51
+ Run this (keeps the file but disables it, so the same `anon_id` is reused if you later re-enable):
52
+
53
+ ```bash
54
+ F="${HOME}/.claude/.tokelang-telemetry.json"
55
+ AID="$(jq -r '.anon_id // empty' "$F" 2>/dev/null)"
56
+ mkdir -p "${HOME}/.claude"
57
+ jq -n --arg aid "$AID" '{enabled:false} + (if $aid=="" then {} else {anon_id:$aid} end)' > "$F"
58
+ echo "Telemetry OFF. Nothing will be sent."
59
+ ```
60
+
61
+ (Equivalent: just delete `~/.claude/.tokelang-telemetry.json`.)
62
+
63
+ ### status (no arg)
64
+ Read the file and report:
65
+
66
+ ```bash
67
+ F="${HOME}/.claude/.tokelang-telemetry.json"
68
+ if [ -f "$F" ] && [ "$(jq -r '.enabled // false' "$F" 2>/dev/null)" = "true" ]; then
69
+ echo "Telemetry: ON (anon_id=$(jq -r '.anon_id // "?"' "$F"))"
70
+ else
71
+ echo "Telemetry: OFF (default)"
72
+ fi
73
+ ```
74
+
75
+ Then summarize the "What is / isn't sent" section above so the user can decide.
76
+
77
+ ## Notes
78
+
79
+ - This is independent of `tokelang.level`. Turning the skill off (`/tokelang-level off`) does not
80
+ change telemetry; telemetry is governed solely by this file.
81
+ - No metrics are sent for sessions with zero compression events (the Stop hook exits early when
82
+ there is no sidecar).
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env bash
2
+ # Tokelang statusline reader
3
+ # Invoked by Claude Code statusline.command setting.
4
+ # Reads the suffix file written by stop.sh and prints to stdout.
5
+
6
+ set -euo pipefail
7
+
8
+ STATUSLINE_SUFFIX="${HOME}/.claude/.tokelang-statusline-suffix"
9
+
10
+ if [[ -f "${STATUSLINE_SUFFIX}" ]]; then
11
+ cat "${STATUSLINE_SUFFIX}"
12
+ else
13
+ # First-run: no data yet
14
+ echo "tokelang: tracking"
15
+ fi