claudekit-terminal 0.2.0 → 0.3.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.
- package/README.md +34 -16
- package/lib/cleanup.js +90 -0
- package/lib/cli.js +386 -17
- package/lib/docs.js +60 -27
- package/lib/license.js +77 -0
- package/lib/pro.js +118 -0
- package/lib/state.js +28 -2
- package/lib/statusline.js +2 -0
- package/lib/telemetry.js +121 -0
- package/lib/terminal-state.js +68 -0
- package/package.json +3 -3
package/lib/docs.js
CHANGED
|
@@ -11,32 +11,39 @@ Set up (one command):
|
|
|
11
11
|
${say} remove undo it (--all also deletes ~/.claudekit)
|
|
12
12
|
|
|
13
13
|
Your limits:
|
|
14
|
-
usage every limit, run-out forecast,
|
|
14
|
+
usage every limit, what prompts cost (Pro: run-out forecast, replies left)
|
|
15
15
|
week your Claude week: busiest day, days active, limit hits
|
|
16
|
-
notify
|
|
16
|
+
notify Pro wait, then tell you when Claude is back after a limit
|
|
17
17
|
|
|
18
18
|
Your chats (Claude Code's own files on this computer):
|
|
19
|
-
search
|
|
19
|
+
search Pro search every chat
|
|
20
20
|
map [chat] numbered outline of a chat
|
|
21
|
-
export
|
|
22
|
-
backup
|
|
23
|
-
fork
|
|
24
|
-
reference
|
|
25
|
-
brief your last Handoff Brief (--start: a new session from it)
|
|
21
|
+
export Pro save a chat as Markdown (--format json|txt, --turns 3-5, --out file)
|
|
22
|
+
backup Pro every chat as Markdown in ~/claudekit-backup (--auto: after each session)
|
|
23
|
+
fork Pro open a copy of a chat to try another direction
|
|
24
|
+
reference Pro save a chat to bring into another one with @
|
|
25
|
+
brief your last Handoff Brief (--start, Pro: a new session from it)
|
|
26
26
|
pins what you pinned with /ck-pin (pin "text" adds one)
|
|
27
27
|
|
|
28
28
|
Prompts:
|
|
29
29
|
prompts your /ck- commands (add, remove, show, packs, pack <name>)
|
|
30
30
|
tokens [file] count words and tokens (or pipe text in)
|
|
31
31
|
|
|
32
|
+
ClaudeKit Pro (one licence with the browser extension):
|
|
33
|
+
pro get Pro from the terminal (checkout opens in your browser)
|
|
34
|
+
activate <key> use a key copied from the ClaudeKit popup
|
|
35
|
+
license what Pro this terminal has
|
|
36
|
+
telemetry off stop the anonymous usage counts (or DO_NOT_TRACK=1)
|
|
37
|
+
|
|
32
38
|
docs every feature, explained
|
|
33
39
|
|
|
34
40
|
Run each as: ${say} <command>
|
|
35
41
|
[chat] is the newest chat in this folder unless you give a session id or words from its title.`;
|
|
36
42
|
|
|
37
43
|
export const DOCS = (say = 'claudekit-terminal') => `ClaudeKit for the terminal ${VERSION}
|
|
38
|
-
Your Claude limits, chats and prompts in the terminal
|
|
39
|
-
|
|
44
|
+
Your Claude limits, chats and prompts in the terminal, with the ClaudeKit browser extension
|
|
45
|
+
(claudekit.app). No account. Seeing your limits is free; acting on them is ClaudeKit Pro, one
|
|
46
|
+
licence for the terminal and the browser.
|
|
40
47
|
|
|
41
48
|
SET UP
|
|
42
49
|
npx claudekit-terminal setup
|
|
@@ -51,18 +58,35 @@ SET UP
|
|
|
51
58
|
~/.claudekit. Chat backups are never deleted.
|
|
52
59
|
Faster start: npm install -g claudekit-terminal, then claudekit-terminal setup.
|
|
53
60
|
|
|
61
|
+
FREE AND PRO
|
|
62
|
+
Free: the status line (model, context, 5-hour and weekly use and resets, what a prompt cost, the
|
|
63
|
+
daily budget, the "use it" nudge, the near-limit hint), usage, week, prompts and packs,
|
|
64
|
+
/ck- commands, tokens, pins, map, brief.
|
|
65
|
+
Pro: the run-out forecast and replies left (status line and usage), notify, search, export,
|
|
66
|
+
backup (and --auto), fork, reference, brief --start.
|
|
67
|
+
If you used ClaudeKit in the terminal before 0.3.0, everything stays free for you until
|
|
68
|
+
Jan 31, 2027.
|
|
69
|
+
pro shows the price and opens a checkout in your browser; the key arrives by itself
|
|
70
|
+
(or later: ${say} pro check). pro monthly for monthly.
|
|
71
|
+
activate <key> a key from the ClaudeKit popup (Use Pro in your terminal). Keys are checked on
|
|
72
|
+
your computer and renew by themselves while your Pro does.
|
|
73
|
+
license what Pro this terminal has (--forget removes the key)
|
|
74
|
+
|
|
54
75
|
THE STATUS LINE (inside Claude Code)
|
|
55
76
|
Opus 5.5 · ctx 45% │ 5h 62% +3% · resets 3:10 PM · out ~2:40 PM · ~6 replies left │ week 41% · Thu 9:00 AM · ~13%/day
|
|
56
77
|
ctx 45% how full this chat's context window is
|
|
57
78
|
5h 62% your 5-hour session limit used (green, yellow from 70%, red from 90%)
|
|
58
79
|
+3% what your current prompt has cost of the session so far
|
|
59
80
|
resets 3:10 PM when the session resets, in your time (at 100%: "back 3:10 PM")
|
|
60
|
-
out ~2:40 PM when you run out at your pace over the last hour (from 20% used)
|
|
61
|
-
~6 replies left about how many prompts are left at your pace on this model (from 50% used)
|
|
81
|
+
out ~2:40 PM Pro: when you run out at your pace over the last hour (from 20% used)
|
|
82
|
+
~6 replies left Pro: about how many prompts are left at your pace on this model (from 50% used)
|
|
62
83
|
week 41% your weekly limit, when it resets, and a daily budget (~13%/day)
|
|
63
84
|
use it in the last day before the weekly reset with 25%+ left: unused limit doesn't roll over
|
|
64
85
|
spend 63% a spend limit, when your plan has one
|
|
65
86
|
near limit at 90%: type /ck-handoff to save your context before you're cut off
|
|
87
|
+
chats expire Claude Code deletes chats older than cleanupPeriodDays (30 by default) without a
|
|
88
|
+
word; this says when some are due within 3 days and aren't backed up (usage and
|
|
89
|
+
search say it too)
|
|
66
90
|
Limits show for Claude Pro, Max and Ultra plans, after the first reply in a session.
|
|
67
91
|
Options: --no-color (or NO_COLOR), --no-history (or CLAUDEKIT_NO_HISTORY=1) keeps no numbers.
|
|
68
92
|
|
|
@@ -78,28 +102,28 @@ COMMANDS IN CLAUDE CODE (type them; Claude never runs them on its own)
|
|
|
78
102
|
Your prompts ${say} prompts add "name" "the prompt" → /ck-name
|
|
79
103
|
|
|
80
104
|
YOUR LIMITS
|
|
81
|
-
usage every limit with bars and reset times,
|
|
82
|
-
|
|
105
|
+
usage every limit with bars and reset times, what your last prompt and this chat
|
|
106
|
+
cost, per-model cost, days without a limit (Pro: run-out forecast, replies left)
|
|
83
107
|
week your Claude week: weekly % used, busiest day, days active, limit hits, by day
|
|
84
|
-
notify
|
|
108
|
+
notify Pro at a limit, waits and sends a desktop notification when Claude is back
|
|
85
109
|
(--test sends one now)
|
|
86
110
|
|
|
87
111
|
YOUR CHATS
|
|
88
112
|
Claude Code keeps every chat in ~/.claude/projects and deletes them after 30 days by default.
|
|
89
113
|
These commands read those files; they never change them.
|
|
90
|
-
search
|
|
114
|
+
search Pro every chat that has all the words, with the matching lines and how to reopen it
|
|
91
115
|
map [chat] a numbered outline: one line per prompt
|
|
92
|
-
export
|
|
116
|
+
export Pro Markdown (default), --format json or txt; --turns 3-5 or 2,4 for some prompts;
|
|
93
117
|
--out file.md, or --out - to print it
|
|
94
|
-
backup
|
|
118
|
+
backup Pro one Markdown file per chat, by project, in ~/claudekit-backup; only new and
|
|
95
119
|
changed chats are written. --auto turns on a backup after every session,
|
|
96
120
|
--auto off turns it off
|
|
97
|
-
fork
|
|
121
|
+
fork Pro opens a copy of the chat in Claude Code (claude --resume <id> --fork-session),
|
|
98
122
|
so you can try another direction and keep the original. --print shows the command
|
|
99
|
-
reference
|
|
123
|
+
reference Pro saves the chat in ~/.claudekit/references; type @<path> in Claude Code to use
|
|
100
124
|
it as context in another chat (--out - prints it)
|
|
101
|
-
brief shows your last Handoff Brief for this folder; --
|
|
102
|
-
|
|
125
|
+
brief shows your last Handoff Brief for this folder; --path prints where it is;
|
|
126
|
+
--start (Pro) opens a new session from it
|
|
103
127
|
pins this folder's pins (--all: every folder); pin "text" adds one by hand
|
|
104
128
|
[chat] is the newest chat in this folder, or a session id (or its first 4+ characters), or
|
|
105
129
|
words from its title.
|
|
@@ -109,11 +133,20 @@ TOKENS
|
|
|
109
133
|
The same estimator as the extension; Claude counts tokens its own way.
|
|
110
134
|
|
|
111
135
|
PRIVACY
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
136
|
+
It reads the JSON Claude Code passes to the status line and Claude Code's chat files on your
|
|
137
|
+
computer, and keeps usage numbers in ~/.claudekit/usage.json: readings for 8 days (percent used,
|
|
138
|
+
reset times, when, the model family, short numbers standing for the session and prompt) and one
|
|
139
|
+
line a day for 90 days (peak 5-hour and weekly %, limit hits). No chat text. Plus what you save
|
|
140
|
+
(pins, briefs, references) and your Pro key.
|
|
141
|
+
It sends anonymous usage counts: a random id for this terminal, the version, OS family and Node
|
|
142
|
+
major version; per command its name, flag names (never values), exit code and duration; words
|
|
143
|
+
like "pro_gate: notify"; and once a day whether limits show (a paid Claude plan), a limit hit and
|
|
144
|
+
a usage band. Never your chats, prompts, code, file paths, project or repo names, or your key.
|
|
145
|
+
Counts go out about once an hour from a command; the status line never waits on the network. Nothing is sent before you've seen the notice once, and nothing at all after
|
|
146
|
+
${say} telemetry off, with DO_NOT_TRACK=1, or in CI.
|
|
147
|
+
The Pro key is checked on your computer. The network is used to send those counts, to fetch or
|
|
148
|
+
renew a key, and by pro to show the price. npx itself may check npm for a newer version; a
|
|
149
|
+
global install avoids that.
|
|
117
150
|
|
|
118
151
|
ON CLAUDE.AI TOO
|
|
119
152
|
The ClaudeKit extension shows your limits, forecasts and more right on claude.ai:
|
package/lib/license.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// The ClaudeKit Pro licence in the terminal (Terminal Pro, Dec 2026): one Pro for the browser
|
|
2
|
+
// extension and the terminal. A key looks like "ckp1.<payload>.<signature>": Ed25519, signed by
|
|
3
|
+
// ClaudeKit's backend, checked here offline against the public key below. No network is needed to
|
|
4
|
+
// check it; fetching or refreshing a key is the only time the network is used for the licence.
|
|
5
|
+
|
|
6
|
+
import { createPublicKey, verify } from 'node:crypto';
|
|
7
|
+
import { mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { kitDir } from './paths.js';
|
|
11
|
+
|
|
12
|
+
// The public half of the backend's TERMINAL_LICENSE_PRIVATE_KEY (SPKI, DER, base64).
|
|
13
|
+
export const LICENSE_PUBLIC_KEY = 'MCowBQYDK2VwAyEA+Hi+LLjwwx+O8TQUXrQPlQvvvgpv8s/5C+1R8SN2xko=';
|
|
14
|
+
|
|
15
|
+
const PREFIX = 'ckp1';
|
|
16
|
+
let publicKey = null;
|
|
17
|
+
let testPublicKey = null;
|
|
18
|
+
|
|
19
|
+
/** Tests only: check keys against another public key (the real one is above). */
|
|
20
|
+
export function useLicensePublicKeyForTests(pub) {
|
|
21
|
+
testPublicKey = pub;
|
|
22
|
+
publicKey = null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function key(pub) {
|
|
26
|
+
if (pub) return createPublicKey({ key: Buffer.from(pub, 'base64'), format: 'der', type: 'spki' });
|
|
27
|
+
publicKey ??= createPublicKey({ key: Buffer.from(testPublicKey ?? LICENSE_PUBLIC_KEY, 'base64'), format: 'der', type: 'spki' });
|
|
28
|
+
return publicKey;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Check a key. Pure apart from the crypto.
|
|
33
|
+
* @returns {{ ok: true, payload: { kid: string, trial: boolean, exp: string } } | { ok: false, reason: 'format' | 'signature' | 'expired', payload?: object }}
|
|
34
|
+
*/
|
|
35
|
+
export function checkKey(token, now = Date.now(), pub) {
|
|
36
|
+
if (typeof token !== 'string') return { ok: false, reason: 'format' };
|
|
37
|
+
const parts = token.trim().split('.');
|
|
38
|
+
if (parts.length !== 3 || parts[0] !== PREFIX) return { ok: false, reason: 'format' };
|
|
39
|
+
let payload;
|
|
40
|
+
try {
|
|
41
|
+
payload = JSON.parse(Buffer.from(parts[1], 'base64url').toString('utf8'));
|
|
42
|
+
} catch {
|
|
43
|
+
return { ok: false, reason: 'format' };
|
|
44
|
+
}
|
|
45
|
+
if (!payload || typeof payload !== 'object' || typeof payload.exp !== 'string' || typeof payload.kid !== 'string') return { ok: false, reason: 'format' };
|
|
46
|
+
let signed = false;
|
|
47
|
+
try {
|
|
48
|
+
signed = verify(null, Buffer.from(`${parts[0]}.${parts[1]}`), key(pub), Buffer.from(parts[2], 'base64url'));
|
|
49
|
+
} catch {
|
|
50
|
+
signed = false;
|
|
51
|
+
}
|
|
52
|
+
if (!signed) return { ok: false, reason: 'signature' };
|
|
53
|
+
const exp = Date.parse(payload.exp);
|
|
54
|
+
const clean = { kid: payload.kid, trial: payload.trial === true, exp: payload.exp };
|
|
55
|
+
if (!Number.isFinite(exp) || exp <= now) return { ok: false, reason: 'expired', payload: clean };
|
|
56
|
+
return { ok: true, payload: clean };
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const licensePath = (env) => join(kitDir(env), 'license.json');
|
|
60
|
+
|
|
61
|
+
export function readKey(env = process.env) {
|
|
62
|
+
try {
|
|
63
|
+
const data = JSON.parse(readFileSync(licensePath(env), 'utf8'));
|
|
64
|
+
return typeof data?.key === 'string' ? data.key : null;
|
|
65
|
+
} catch {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function saveKey(token, env = process.env) {
|
|
71
|
+
mkdirSync(kitDir(env), { recursive: true });
|
|
72
|
+
writeFileSync(licensePath(env), `${JSON.stringify({ key: token.trim() })}\n`, { mode: 0o600 });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function forgetKey(env = process.env) {
|
|
76
|
+
rmSync(licensePath(env), { force: true });
|
|
77
|
+
}
|
package/lib/pro.js
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
// ClaudeKit Pro in the terminal (Terminal Pro, Dec 2026): "see your limits free; act on them with
|
|
2
|
+
// Pro", the same rule as the browser extension, and one licence for both.
|
|
3
|
+
// Free: the status line's numbers, usage, week, prompts and packs, tokens, pins, map, docs, brief,
|
|
4
|
+
// the run-out time once a limit is 70% used, and search and export of the last 7 days.
|
|
5
|
+
// Pro: the run-out time from 20% and replies left, notify, all-time search and export, JSON
|
|
6
|
+
// export and --turns ranges, backup (and --auto), fork, reference, brief --start.
|
|
7
|
+
// (Split changed Dec 4 by the owner, after the Competitors thread: free rivals give a run-out time,
|
|
8
|
+
// search and export; developers pay for history.)
|
|
9
|
+
// People who used ClaudeKit in the terminal before 0.3.0 keep everything until Jan 31, 2027.
|
|
10
|
+
|
|
11
|
+
import { checkKey, readKey, saveKey } from './license.js';
|
|
12
|
+
import { apiBase } from './telemetry.js';
|
|
13
|
+
import { grandfathered } from './terminal-state.js';
|
|
14
|
+
|
|
15
|
+
export const PRO_FEATURES = {
|
|
16
|
+
forecast: 'The early run-out forecast and replies left',
|
|
17
|
+
notify: '"Claude is back" notifications',
|
|
18
|
+
search_history: 'Searching chats older than 7 days',
|
|
19
|
+
export_history: 'Exporting chats older than 7 days',
|
|
20
|
+
export: 'JSON export and --turns ranges',
|
|
21
|
+
backup: 'Chat backups',
|
|
22
|
+
backup_warning: 'Chat backups',
|
|
23
|
+
backup_auto: 'Automatic chat backups',
|
|
24
|
+
fork: 'Forking a chat',
|
|
25
|
+
reference: 'Reference chats',
|
|
26
|
+
brief_start: 'Starting a session from a brief',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const REFRESH_BEFORE_MS = 5 * 24 * 60 * 60 * 1000;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What Pro this terminal has, offline.
|
|
33
|
+
* @returns {{ pro: boolean, via: 'key' | 'grandfather' | null, trial: boolean, exp: string | null, key: 'none' | 'ok' | 'expired' | 'invalid' }}
|
|
34
|
+
*/
|
|
35
|
+
export function proStatus(env, state, now = Date.now()) {
|
|
36
|
+
const token = readKey(env);
|
|
37
|
+
const checked = token ? checkKey(token, now) : null;
|
|
38
|
+
const keyState = !token ? 'none' : checked.ok ? 'ok' : checked.reason === 'expired' ? 'expired' : 'invalid';
|
|
39
|
+
if (checked?.ok) return { pro: true, via: 'key', trial: checked.payload.trial, exp: checked.payload.exp, key: keyState };
|
|
40
|
+
if (grandfathered(state, now)) return { pro: true, via: 'grandfather', trial: false, exp: state.grandfatherUntil, key: keyState };
|
|
41
|
+
return { pro: false, via: null, trial: Boolean(checked?.payload?.trial), exp: checked?.payload?.exp ?? null, key: keyState };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function fetchJson(fetchImpl, url, init = {}, timeoutMs = 4000) {
|
|
45
|
+
if (typeof fetchImpl !== 'function') return null;
|
|
46
|
+
const controller = new AbortController();
|
|
47
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
48
|
+
try {
|
|
49
|
+
const response = await fetchImpl(url, { ...init, signal: controller.signal });
|
|
50
|
+
const body = await response.json().catch(() => null);
|
|
51
|
+
return { status: response.status, body };
|
|
52
|
+
} catch {
|
|
53
|
+
return null;
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A key that has ended, or ends within 5 days, gets a new expiry if its Pro is still on. Quiet. */
|
|
60
|
+
export async function refreshKeyIfDue(env, fetchImpl, now = Date.now()) {
|
|
61
|
+
const token = readKey(env);
|
|
62
|
+
if (!token) return false;
|
|
63
|
+
const checked = checkKey(token, now);
|
|
64
|
+
const exp = checked.payload ? Date.parse(checked.payload.exp) : NaN;
|
|
65
|
+
if (checked.reason === 'signature' || checked.reason === 'format') return false;
|
|
66
|
+
if (Number.isFinite(exp) && exp - now > REFRESH_BEFORE_MS) return false;
|
|
67
|
+
const result = await fetchJson(fetchImpl, `${apiBase(env)}/v1/terminal/refresh`, {
|
|
68
|
+
method: 'POST',
|
|
69
|
+
headers: { 'content-type': 'application/json' },
|
|
70
|
+
body: JSON.stringify({ key: token }),
|
|
71
|
+
}, 2500);
|
|
72
|
+
const fresh = result?.body?.key;
|
|
73
|
+
if (typeof fresh === 'string' && checkKey(fresh, now).ok) {
|
|
74
|
+
saveKey(fresh, env);
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Ask the backend for this install's key (after a checkout from the terminal). */
|
|
81
|
+
export async function fetchKeyFor(env, fetchImpl, installId) {
|
|
82
|
+
const result = await fetchJson(fetchImpl, `${apiBase(env)}/v1/terminal/key?installId=${encodeURIComponent(installId)}`);
|
|
83
|
+
const key = result?.body?.key;
|
|
84
|
+
return typeof key === 'string' ? key : null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The running yearly offer and prices, for `pro` (null offline). */
|
|
88
|
+
export async function fetchOffer(env, fetchImpl) {
|
|
89
|
+
const result = await fetchJson(fetchImpl, `${apiBase(env)}/v1/offer`, {}, 2500);
|
|
90
|
+
return result?.body && typeof result.body === 'object' ? result.body : null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const dollars = (cents) => (cents % 100 === 0 ? `$${cents / 100}` : `$${(cents / 100).toFixed(2)}`);
|
|
94
|
+
|
|
95
|
+
/** "Holiday price: $20 for your first year (then $28/year), until Dec 31." or today's prices. */
|
|
96
|
+
export function offerLine(offer) {
|
|
97
|
+
const prices = offer?.prices;
|
|
98
|
+
const yearly = Number(prices?.yearlyCents);
|
|
99
|
+
const monthly = Number(prices?.monthlyCents);
|
|
100
|
+
const yo = offer?.yearlyOffer;
|
|
101
|
+
if (yo && Number.isFinite(Number(yo.priceCents)) && Date.parse(yo.endsAt) > Date.now()) {
|
|
102
|
+
const ends = new Date(yo.endsAt).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
|
|
103
|
+
return `${yo.name}: ${dollars(Number(yo.priceCents))} for your first year${Number.isFinite(yearly) ? ` (then ${dollars(yearly)}/year)` : ''}, until ${ends}.${Number.isFinite(monthly) ? ` Or ${dollars(monthly)}/month.` : ''}`;
|
|
104
|
+
}
|
|
105
|
+
if (Number.isFinite(yearly) && Number.isFinite(monthly)) return `${dollars(yearly)}/year or ${dollars(monthly)}/month.`;
|
|
106
|
+
return 'See prices at claudekit.app/pricing.';
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** The lines a Pro command prints when this terminal doesn't have Pro. */
|
|
110
|
+
const PLURAL = new Set(['forecast', 'notify', 'export', 'backup', 'backup_warning', 'backup_auto', 'reference']);
|
|
111
|
+
|
|
112
|
+
export function gateLines(feature, say, status) {
|
|
113
|
+
const what = PRO_FEATURES[feature] ?? 'This';
|
|
114
|
+
const lines = [`${what} ${PLURAL.has(feature) ? 'are' : 'is'} part of ClaudeKit Pro: one licence for the terminal and the browser extension.`];
|
|
115
|
+
if (status.key === 'expired') lines.push(`Your Pro key ended on ${new Date(status.exp).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' })}. Copy a new one from the ClaudeKit popup, or keep Pro: ${say} pro`);
|
|
116
|
+
else lines.push(`Get it: ${say} pro · Have a key? ${say} activate <key>`);
|
|
117
|
+
return lines;
|
|
118
|
+
}
|
package/lib/state.js
CHANGED
|
@@ -13,10 +13,19 @@ import { usagePath } from './paths.js';
|
|
|
13
13
|
const KEEP_MS = 8 * DAY_MS;
|
|
14
14
|
const MAX_READINGS = 4000;
|
|
15
15
|
const MAX_HITS = 100;
|
|
16
|
+
// One summary per day, kept 90 days (Competitors, Dec 4: history can't be filled in later): the
|
|
17
|
+
// day's peak 5-hour and weekly %, and its limit hits. Numbers only.
|
|
18
|
+
const KEEP_DAYS = 90;
|
|
16
19
|
const QUIET_MS = 10 * 60 * 1000; // an unchanged reading is kept again only after this long
|
|
17
20
|
|
|
18
21
|
export function emptyState() {
|
|
19
|
-
return { v: 1, readings: [], hits: [] };
|
|
22
|
+
return { v: 1, readings: [], hits: [], days: [] };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** "2026-12-04" in this computer's time zone. */
|
|
26
|
+
export function localDay(ms) {
|
|
27
|
+
const d = new Date(ms);
|
|
28
|
+
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
|
|
20
29
|
}
|
|
21
30
|
|
|
22
31
|
export function historyEnabled(argv = [], env = {}) {
|
|
@@ -32,6 +41,7 @@ export function loadState(env = process.env) {
|
|
|
32
41
|
v: 1,
|
|
33
42
|
readings: Array.isArray(data.readings) ? data.readings.filter((r) => r && Number.isFinite(r.t)) : [],
|
|
34
43
|
hits: Array.isArray(data.hits) ? data.hits.filter((h) => h && Number.isFinite(h.r)) : [],
|
|
44
|
+
days: Array.isArray(data.days) ? data.days.filter((d) => d && typeof d.d === 'string') : [],
|
|
35
45
|
};
|
|
36
46
|
} catch {
|
|
37
47
|
return emptyState();
|
|
@@ -107,12 +117,28 @@ export function addReading(state, reading) {
|
|
|
107
117
|
if (hits.some((h) => h.k === k && sameWindow(h.r, reset))) return;
|
|
108
118
|
hits.push({ k, at: now, r: reset });
|
|
109
119
|
};
|
|
120
|
+
const before = hits.length;
|
|
110
121
|
noteHit('5h', reading.h, reading.hr);
|
|
111
122
|
noteHit('week', reading.w, reading.wr);
|
|
123
|
+
// The day's summary: peaks and limit hits.
|
|
124
|
+
const days = Array.isArray(state.days) ? state.days.map((d) => ({ ...d })) : [];
|
|
125
|
+
if (hasLimits) {
|
|
126
|
+
const key = localDay(now);
|
|
127
|
+
let today = days.find((d) => d.d === key);
|
|
128
|
+
if (!today) {
|
|
129
|
+
today = { d: key, h: null, w: null, hits: 0 };
|
|
130
|
+
days.push(today);
|
|
131
|
+
}
|
|
132
|
+
if (reading.h !== null) today.h = Math.max(today.h ?? 0, reading.h);
|
|
133
|
+
if (reading.w !== null) today.w = Math.max(today.w ?? 0, reading.w);
|
|
134
|
+
today.hits += hits.length - before;
|
|
135
|
+
}
|
|
136
|
+
const oldest = localDay(now - KEEP_DAYS * DAY_MS);
|
|
112
137
|
return {
|
|
113
138
|
v: 1,
|
|
114
139
|
readings: readings.slice(-MAX_READINGS),
|
|
115
140
|
hits: hits.slice(-MAX_HITS),
|
|
141
|
+
days: days.filter((d) => d.d > oldest).sort((a, b) => (a.d < b.d ? -1 : 1)).slice(-KEEP_DAYS),
|
|
116
142
|
};
|
|
117
143
|
}
|
|
118
144
|
|
|
@@ -121,7 +147,7 @@ export function recordReading(data, now, env = process.env) {
|
|
|
121
147
|
const reading = readingFromInput(data, now);
|
|
122
148
|
const before = loadState(env);
|
|
123
149
|
const after = addReading(before, reading);
|
|
124
|
-
if (after.readings.length !== before.readings.length || after.hits.length !== before.hits.length || after.readings.at(-1) !== before.readings.at(-1)) {
|
|
150
|
+
if (after.readings.length !== before.readings.length || after.hits.length !== before.hits.length || after.readings.at(-1) !== before.readings.at(-1) || JSON.stringify(after.days.at(-1)) !== JSON.stringify(before.days?.at(-1))) {
|
|
125
151
|
saveState(after, env);
|
|
126
152
|
}
|
|
127
153
|
return { state: after, reading };
|
package/lib/statusline.js
CHANGED
|
@@ -173,6 +173,7 @@ function spendPart(rateLimits, now, opts) {
|
|
|
173
173
|
* @param {(d: Date) => string} [options.formatWeekday] e.g. "Thu"
|
|
174
174
|
* @param {{promptCost?: number|null, forecast?: object|null, repliesLeft?: number|null}} [options.insights]
|
|
175
175
|
* @param {boolean} [options.handoffHint] show "/ck-handoff" near a limit (the command is installed)
|
|
176
|
+
* @param {string|null} [options.notice] a short notice for the end of the line (the Jan 31 carve-out)
|
|
176
177
|
*/
|
|
177
178
|
export function formatStatusLine(input, options = {}) {
|
|
178
179
|
let model = FALLBACK;
|
|
@@ -199,6 +200,7 @@ export function formatStatusLine(input, options = {}) {
|
|
|
199
200
|
if (spend) segments.push(spend);
|
|
200
201
|
const top = Math.max(session?.used ?? 0, weekly?.used ?? 0);
|
|
201
202
|
if (options.handoffHint && top >= 90 && top < 100) segments.push('near limit: /ck-handoff');
|
|
203
|
+
if (typeof options.notice === 'string' && options.notice) segments.push(options.notice);
|
|
202
204
|
return segments.join(SEP);
|
|
203
205
|
} catch {
|
|
204
206
|
return model;
|
package/lib/telemetry.js
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// Anonymous usage counts (Terminal Pro, Dec 2026; the owner asked to measure the terminal funnel).
|
|
2
|
+
// What is sent: this terminal's random id, the package version, and allowlisted words such as
|
|
3
|
+
// "command: search" or "pro_gate: notify". Never prompts, chat text, file paths, project names or
|
|
4
|
+
// the licence key. Nothing is sent until the notice has been shown once in a command (never from the
|
|
5
|
+
// status line alone), and nothing at all with `claudekit-terminal telemetry off`, DO_NOT_TRACK=1,
|
|
6
|
+
// CLAUDEKIT_TELEMETRY=0 or in CI.
|
|
7
|
+
|
|
8
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
9
|
+
import { join } from 'node:path';
|
|
10
|
+
|
|
11
|
+
import { kitDir } from './paths.js';
|
|
12
|
+
|
|
13
|
+
const MAX_QUEUE = 200;
|
|
14
|
+
const queuePath = (env) => join(kitDir(env), 'events.json');
|
|
15
|
+
|
|
16
|
+
export const TELEMETRY_NOTICE = (say) =>
|
|
17
|
+
`ClaudeKit for the terminal sends anonymous usage counts (which commands run and when a Pro feature is asked for; never your chats, code, file paths or keys) so we can make it better. Turn it off any time: ${say} telemetry off (or set DO_NOT_TRACK=1).`;
|
|
18
|
+
|
|
19
|
+
export function apiBase(env = process.env) {
|
|
20
|
+
return (env.CLAUDEKIT_API || 'https://api.claudekit.app').replace(/\/$/, '');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function truthy(value) {
|
|
24
|
+
return typeof value === 'string' && value !== '' && value !== '0' && value.toLowerCase() !== 'false';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Whether counts may be sent at all (the notice must have been shown, too). */
|
|
28
|
+
export function telemetryAllowed(env, state) {
|
|
29
|
+
if (truthy(env.DO_NOT_TRACK) || truthy(env.CI) || env.CLAUDEKIT_TELEMETRY === '0') return false;
|
|
30
|
+
if (state?.telemetry === false) return false;
|
|
31
|
+
return state?.noticeShown?.telemetry === true;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function readQueue(env) {
|
|
35
|
+
try {
|
|
36
|
+
const list = JSON.parse(readFileSync(queuePath(env), 'utf8'));
|
|
37
|
+
return Array.isArray(list) ? list : [];
|
|
38
|
+
} catch {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function writeQueue(env, list) {
|
|
44
|
+
try {
|
|
45
|
+
mkdirSync(kitDir(env), { recursive: true });
|
|
46
|
+
writeFileSync(queuePath(env), JSON.stringify(list.slice(-MAX_QUEUE)));
|
|
47
|
+
} catch {
|
|
48
|
+
// Never in the way.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Queue one count, if allowed. `extra` may add a command's exit code (c), duration (ms) and the
|
|
54
|
+
* names of the flags it was run with (f), never their values.
|
|
55
|
+
*/
|
|
56
|
+
export function track(env, state, event, detail = null, now = Date.now(), extra = {}) {
|
|
57
|
+
if (!telemetryAllowed(env, state)) return;
|
|
58
|
+
const list = readQueue(env);
|
|
59
|
+
list.push({ e: event, ...(detail ? { d: detail } : {}), at: now, ...extra });
|
|
60
|
+
writeQueue(env, list);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The flag names in argv ("--limit=5" → "limit"), never values or other words. */
|
|
64
|
+
export function flagNames(argv) {
|
|
65
|
+
return [...new Set((argv ?? []).filter((a) => typeof a === 'string' && a.startsWith('--')).map((a) => a.slice(2).split('=')[0]))].slice(0, 10);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** OS family and Node major version, sent with each batch. */
|
|
69
|
+
export function runtimeInfo(platform = process.platform, nodeVersion = process.versions.node) {
|
|
70
|
+
const os = platform === 'darwin' ? 'mac' : platform === 'win32' ? 'win' : platform === 'linux' ? 'linux' : 'other';
|
|
71
|
+
return { os, node: Number.parseInt(String(nodeVersion), 10) || null };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const HOUR_MS = 60 * 60 * 1000;
|
|
75
|
+
|
|
76
|
+
/** Whether a command run should send now: about once an hour, sooner when 50 are queued. */
|
|
77
|
+
export function flushDue(env, state, now = Date.now()) {
|
|
78
|
+
if (!telemetryAllowed(env, state)) return false;
|
|
79
|
+
const last = Date.parse(state?.lastFlush ?? '');
|
|
80
|
+
return !Number.isFinite(last) || now - last >= HOUR_MS || readQueue(env).length >= 50;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Drop anything queued (telemetry off). */
|
|
84
|
+
export function clearQueue(env) {
|
|
85
|
+
writeQueue(env, []);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Send what is queued, 50 at a time. Never throws; gives up after `timeoutMs`. */
|
|
89
|
+
export async function flush(env, state, version, fetchImpl, timeoutMs = 2000) {
|
|
90
|
+
if (!telemetryAllowed(env, state) || typeof fetchImpl !== 'function') return 0;
|
|
91
|
+
const list = readQueue(env);
|
|
92
|
+
if (list.length === 0) return 0;
|
|
93
|
+
const batch = list.slice(0, 50);
|
|
94
|
+
const controller = new AbortController();
|
|
95
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
96
|
+
try {
|
|
97
|
+
const response = await fetchImpl(`${apiBase(env)}/v1/terminal/events`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: { 'content-type': 'application/json' },
|
|
100
|
+
body: JSON.stringify({ tid: state.id, v: version, ...runtimeInfo(), events: batch }),
|
|
101
|
+
signal: controller.signal,
|
|
102
|
+
});
|
|
103
|
+
if (!response.ok) return 0;
|
|
104
|
+
writeQueue(env, readQueue(env).slice(batch.length));
|
|
105
|
+
return batch.length;
|
|
106
|
+
} catch {
|
|
107
|
+
return 0;
|
|
108
|
+
} finally {
|
|
109
|
+
clearTimeout(timer);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The status line's coarse daily signals: paid Claude plan or API, a limit hit, a usage band. */
|
|
114
|
+
export function statusSignals(data) {
|
|
115
|
+
const limits = data?.rate_limits && typeof data.rate_limits === 'object' ? data.rate_limits : null;
|
|
116
|
+
if (!limits) return ['plan_api'];
|
|
117
|
+
const pct = (w) => (w && Number.isFinite(Number(w.used_percentage)) ? Number(w.used_percentage) : 0);
|
|
118
|
+
const top = Math.max(pct(limits.five_hour), pct(limits.seven_day));
|
|
119
|
+
const band = top >= 90 ? 'band_90' : top >= 75 ? 'band_75' : top >= 50 ? 'band_50' : top >= 25 ? 'band_25' : 'band_0';
|
|
120
|
+
return ['plan_paid', band, ...(top >= 100 ? ['limit_hit'] : [])];
|
|
121
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// ~/.claudekit/terminal.json: this terminal's own settings.
|
|
2
|
+
// id random "ckt_…" id for the anonymous usage counts (never tied to a person)
|
|
3
|
+
// telemetry false once turned off
|
|
4
|
+
// noticeShown { telemetry, grandfather }: one-time notices already shown
|
|
5
|
+
// grandfatherUntil set for people who used ClaudeKit in the terminal before 0.3.0: every
|
|
6
|
+
// feature stays free for them until then (Terminal Pro, Dec 2026)
|
|
7
|
+
// hints { command: 'YYYY-MM-DD' }: the last day a "Pro: …" hint was shown for it
|
|
8
|
+
// installId the id a terminal checkout used, so `pro` can pick up its key later
|
|
9
|
+
// lastDaily 'YYYY-MM-DD' of the status line's last daily count
|
|
10
|
+
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { randomBytes } from 'node:crypto';
|
|
13
|
+
import { join } from 'node:path';
|
|
14
|
+
|
|
15
|
+
import { installedPath, kitDir, usagePath } from './paths.js';
|
|
16
|
+
|
|
17
|
+
/** Existing users keep every feature until the end of this day (UTC). */
|
|
18
|
+
export const GRANDFATHER_UNTIL = '2027-01-31T23:59:59.000Z';
|
|
19
|
+
|
|
20
|
+
const statePath = (env) => join(kitDir(env), 'terminal.json');
|
|
21
|
+
|
|
22
|
+
export function newTerminalId() {
|
|
23
|
+
return `ckt_${randomBytes(16).toString('hex')}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function read(env) {
|
|
27
|
+
try {
|
|
28
|
+
const data = JSON.parse(readFileSync(statePath(env), 'utf8'));
|
|
29
|
+
return data && typeof data === 'object' ? data : null;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* This terminal's state, created on first use. Someone who already had ClaudeKit files from before
|
|
37
|
+
* 0.3.0 (setup done, or usage numbers kept) is an existing user: grandfathered until Jan 31.
|
|
38
|
+
*/
|
|
39
|
+
export function loadTerminal(env = process.env, now = Date.now()) {
|
|
40
|
+
const existing = read(env);
|
|
41
|
+
if (existing && typeof existing.id === 'string') {
|
|
42
|
+
return { noticeShown: {}, hints: {}, ...existing };
|
|
43
|
+
}
|
|
44
|
+
const existingUser = existsSync(installedPath(env)) || existsSync(usagePath(env));
|
|
45
|
+
const state = {
|
|
46
|
+
id: newTerminalId(),
|
|
47
|
+
created: new Date(now).toISOString(),
|
|
48
|
+
firstVersion: existingUser ? 'before-0.3.0' : null,
|
|
49
|
+
grandfatherUntil: existingUser && now < Date.parse(GRANDFATHER_UNTIL) ? GRANDFATHER_UNTIL : null,
|
|
50
|
+
noticeShown: {},
|
|
51
|
+
hints: {},
|
|
52
|
+
};
|
|
53
|
+
saveTerminal(state, env);
|
|
54
|
+
return state;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function saveTerminal(state, env = process.env) {
|
|
58
|
+
try {
|
|
59
|
+
mkdirSync(kitDir(env), { recursive: true });
|
|
60
|
+
writeFileSync(statePath(env), `${JSON.stringify(state, null, 2)}\n`);
|
|
61
|
+
} catch {
|
|
62
|
+
// Never in the way of a command.
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function grandfathered(state, now = Date.now()) {
|
|
67
|
+
return typeof state?.grandfatherUntil === 'string' && Date.parse(state.grandfatherUntil) > now;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "claudekit-terminal",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Your Claude limits, chats and prompts in the terminal: a status line
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Your Claude limits, chats and prompts in the terminal: a status line for Claude Code, usage and week, prompt packs and /ck- commands free; forecasts, notify, search, export, backup and fork with ClaudeKit Pro. One command sets it up. Zero dependencies; anonymous usage counts you can turn off.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"claudekit-terminal": "bin/claudekit-terminal.js"
|
|
@@ -29,6 +29,6 @@
|
|
|
29
29
|
"anthropic",
|
|
30
30
|
"cli"
|
|
31
31
|
],
|
|
32
|
-
"homepage": "https://claudekit.app/
|
|
32
|
+
"homepage": "https://claudekit.app/terminal?utm_source=npm&utm_medium=terminal",
|
|
33
33
|
"license": "MIT"
|
|
34
34
|
}
|