claudekit-terminal 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +118 -2
- package/bin/claudekit-terminal.js +56 -0
- package/lib/cleanup.js +90 -0
- package/lib/cli.js +1072 -0
- package/lib/docs.js +153 -0
- package/lib/format.js +51 -0
- package/lib/insights.js +196 -0
- package/lib/license.js +77 -0
- package/lib/packs.json +205 -0
- package/lib/paths.js +46 -0
- package/lib/pro.js +118 -0
- package/lib/settings.js +82 -0
- package/lib/setup.js +172 -0
- package/lib/skills.js +116 -0
- package/lib/state.js +159 -0
- package/lib/statusline.js +208 -0
- package/lib/telemetry.js +121 -0
- package/lib/terminal-state.js +68 -0
- package/lib/tokens.js +52 -0
- package/lib/transcripts.js +296 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Avish Shah
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,119 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ClaudeKit for the terminal
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Your Claude limits, chats and prompts in the terminal. One command sets it up.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
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
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx claudekit-terminal setup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
That's it. Send a message in Claude Code and the status line appears after the first reply. Undo it all with `npx claudekit-terminal remove`.
|
|
14
|
+
|
|
15
|
+
No account, zero dependencies, Node.js 18 or newer. It's the terminal side of the [ClaudeKit browser extension](https://claudekit.app/get?utm_source=terminal&utm_medium=readme), with the same features wherever a terminal can. Seeing your limits is free; acting on them is **ClaudeKit Pro**, one licence for the terminal and the browser.
|
|
16
|
+
|
|
17
|
+
Sends anonymous usage counts (never your chats or code); turn it off with `claudekit-terminal telemetry off` or `DO_NOT_TRACK=1`. The Pro licence is checked offline.
|
|
18
|
+
|
|
19
|
+
## Free and Pro
|
|
20
|
+
|
|
21
|
+
| Free | ClaudeKit Pro |
|
|
22
|
+
| --- | --- |
|
|
23
|
+
| The status line: model, context, 5-hour and weekly use with resets, what a prompt cost, the daily budget, the "use it" nudge, the near-limit hint | The run-out forecast and replies left (status line and `usage`) |
|
|
24
|
+
| `usage`, `week`, `map`, `tokens`, `pins`, `brief`, `prompts` and the prompt packs | `notify` ("Claude is back") |
|
|
25
|
+
| `/ck-handoff`, `/ck-optimize`, `/ck-pin` and every `/ck-` prompt | `search`, `export`, `backup` (and `--auto`), `fork`, `reference`, `brief --start` |
|
|
26
|
+
|
|
27
|
+
- **Get Pro:** `claudekit-terminal pro` shows the price and opens a checkout in your browser. The key arrives by itself; if you close the terminal first, run `claudekit-terminal pro check` later. Add `monthly` for monthly.
|
|
28
|
+
- **Already have Pro in the extension?** Open its popup, choose "Use Pro in your terminal", copy the key, then run `claudekit-terminal activate <key>`. A trial key works too.
|
|
29
|
+
- Keys are checked on your computer and renew by themselves while your Pro does. `claudekit-terminal license` shows what you have.
|
|
30
|
+
- **Used ClaudeKit in the terminal before 0.3.0?** Everything stays free for you until Jan 31, 2027.
|
|
31
|
+
|
|
32
|
+
## What setup does
|
|
33
|
+
|
|
34
|
+
- Adds the status line to Claude Code's `~/.claude/settings.json`. Your old file is saved as `settings.json.claudekit-backup`. If you already have your own status line, it's kept unless you add `--force`, and `remove` puts it back.
|
|
35
|
+
- Adds `/ck-` commands to Claude Code (`~/.claude/skills/ck-*`). They run only when you type them.
|
|
36
|
+
- Run it again any time. It only updates what it added and never touches a `ck-` command you made yourself.
|
|
37
|
+
|
|
38
|
+
Options: `--packs developers,agents,marketing` (default: developers), `--no-packs`, `--auto-backup`, `--force`.
|
|
39
|
+
|
|
40
|
+
Faster status line: `npm install -g claudekit-terminal`, then `claudekit-terminal setup`. With a global install, `npx` no longer checks npm on every start.
|
|
41
|
+
|
|
42
|
+
## The status line
|
|
43
|
+
|
|
44
|
+
| Part | What it means |
|
|
45
|
+
| --- | --- |
|
|
46
|
+
| `ctx 45%` | How full this chat's context window is |
|
|
47
|
+
| `5h 62%` | Your 5-hour session limit used: green, yellow from 70%, red from 90% |
|
|
48
|
+
| `+3%` | What your current prompt has cost of the session so far |
|
|
49
|
+
| `resets 3:10 PM` | When the session resets, in your time. At 100% it says `back 3:10 PM` |
|
|
50
|
+
| `out ~2:40 PM` | Pro: when you run out at your pace over the last hour (from 20% used) |
|
|
51
|
+
| `~6 replies left` | Pro: about how many prompts are left at your pace on this model (from 50% used) |
|
|
52
|
+
| `week 41% · Thu 9:00 AM · ~13%/day` | Your weekly limit, when it resets, and a daily budget |
|
|
53
|
+
| `use it: resets in 10h` | In the last day before the weekly reset with 25% or more left: unused limit doesn't roll over |
|
|
54
|
+
| `spend 63% of $500` | A spend limit, when your plan has one |
|
|
55
|
+
| `near limit: /ck-handoff` | At 90%: save your context before you're cut off |
|
|
56
|
+
| `2 chats expire ≤3d` | Claude Code deletes chats older than `cleanupPeriodDays` (30 days by default) without a word. This says when some are due within 3 days and aren't in your backup. `usage` and `search` say it too |
|
|
57
|
+
|
|
58
|
+
Limits show for Claude Pro, Max and Ultra plans, after the first reply in a session. With an API key you see the model and context only.
|
|
59
|
+
|
|
60
|
+
Options: `--no-color` (or `NO_COLOR`), and `--no-history` (or `CLAUDEKIT_NO_HISTORY=1`) to keep no numbers. Without the numbers, the forecast, prompt cost and replies left can't be worked out.
|
|
61
|
+
|
|
62
|
+
## Commands in Claude Code
|
|
63
|
+
|
|
64
|
+
| Type | What it does |
|
|
65
|
+
| --- | --- |
|
|
66
|
+
| `/ck-handoff` | A Handoff Brief: goal, decisions, done, what's left, key facts and files, saved in `~/.claudekit/briefs`. Continue later with `claudekit-terminal brief --start` |
|
|
67
|
+
| `/ck-optimize <draft>` | Rewrites a draft prompt for a clearer result and shows the token change |
|
|
68
|
+
| `/ck-pin [text]` | Pins your last answer's key point, or what you name, for this folder |
|
|
69
|
+
| Limit Saver | `/ck-compress-and-restart`, `/ck-plan-before-building`, `/ck-short-answers-mode`, `/ck-only-what-changed` make your limit last longer |
|
|
70
|
+
| Prompt packs | The extension's free packs as commands, such as `/ck-review-a-diff`, `/ck-find-the-root-cause` and `/ck-tests-first`. Add more with `claudekit-terminal prompts pack agents` or `marketing` |
|
|
71
|
+
| Your prompts | `claudekit-terminal prompts add "Weekly report" "Summarize…"` gives you `/ck-weekly-report` |
|
|
72
|
+
|
|
73
|
+
## Commands in your terminal
|
|
74
|
+
|
|
75
|
+
Run them as `claudekit-terminal <command>` (or `npx claudekit-terminal <command>`).
|
|
76
|
+
|
|
77
|
+
**Your limits**
|
|
78
|
+
|
|
79
|
+
- `usage`: every limit with bars and reset times, what your last prompt and this chat cost, cost per model, and days without a limit. With Pro, it adds the run-out forecast and replies left.
|
|
80
|
+
- `week`: your Claude week, with weekly % used, busiest day, days active, limit hits, and a by-day chart.
|
|
81
|
+
- `notify` (Pro): at a limit, waits and sends a desktop notification when Claude is back. `--test` sends one now.
|
|
82
|
+
|
|
83
|
+
**Your chats.** Claude Code keeps every chat in `~/.claude/projects` and deletes them after 30 days by default. These commands read those files and never change them.
|
|
84
|
+
|
|
85
|
+
- `search <words>` (Pro): every chat with all the words, the matching lines, and how to reopen it.
|
|
86
|
+
- `map [chat]`: a numbered outline of a chat, one line per prompt.
|
|
87
|
+
- `export [chat]` (Pro): Markdown by default. Use `--format json` or `txt`, `--turns 3-5` (or `2,4`) for some prompts, and `--out file.md`, or `--out -` to print.
|
|
88
|
+
- `backup [folder]` (Pro): one Markdown file per chat, by project, in `~/claudekit-backup`, writing only new and changed chats. `--auto` backs up after every session; `--auto off` stops it.
|
|
89
|
+
- `fork [chat]` (Pro): opens a copy of a chat in Claude Code to try another direction, keeping the original.
|
|
90
|
+
- `reference [chat]` (Pro): saves a chat in `~/.claudekit/references`. Type `@<path>` in Claude Code to use it as context in another chat.
|
|
91
|
+
- `brief`: your last Handoff Brief for this folder. `--start` (Pro) opens a new session from it.
|
|
92
|
+
- `pins`: this folder's pins (`--all` for every folder). `pin "text"` adds one.
|
|
93
|
+
|
|
94
|
+
`[chat]` is the newest chat in this folder, a session id (or its first 4+ characters), or words from its title.
|
|
95
|
+
|
|
96
|
+
**Prompts and tokens**
|
|
97
|
+
|
|
98
|
+
- `prompts`: your `/ck-` commands, with `add`, `remove`, `show`, `packs` and `pack <name>`.
|
|
99
|
+
- `tokens [file]`: words and estimated tokens of files or piped text (`pbpaste | claudekit-terminal tokens`).
|
|
100
|
+
|
|
101
|
+
`docs` prints all of this; `help` prints the short list.
|
|
102
|
+
|
|
103
|
+
## Privacy
|
|
104
|
+
|
|
105
|
+
- It reads the JSON Claude Code passes to the status line, and Claude Code's chat files on your computer when you run a chat command.
|
|
106
|
+
- It keeps a few usage numbers in `~/.claudekit/usage.json`: readings for 8 days (percent used, reset times, when each reading was taken, the model family, and short numbers standing for the session and prompt), and one line per day for 90 days (that day's peak 5-hour and weekly %, and its limit hits). No chat text. It also keeps what you save (pins, briefs, references) and your Pro key.
|
|
107
|
+
- **Anonymous usage counts.** It sends a random id for this terminal, the version, your OS family (macOS, Windows, Linux) and Node.js major version. For each command it sends the name, the names of the flags used (never their values), the exit code and how long it took. It also sends words like `pro_gate: notify` or `key_activated: paid`, and whether a key came from the extension. Once a day it sends whether your limits show (a paid Claude plan), whether you hit a limit, and a usage band. It never sends your chats, prompts, code, file paths, project or repo names, or your key. Counts go out about once an hour from a command you run; the status line never waits on the network. The server keeps the country Cloudflare reports, not your IP address.
|
|
108
|
+
- Nothing is sent before you've seen the notice once in a command, so the status line alone never sends anything. Nothing at all is sent after `claudekit-terminal telemetry off`, with `DO_NOT_TRACK=1`, or in CI.
|
|
109
|
+
- The Pro key is checked on your computer. The network is used to send those counts, to fetch or renew a key, and by `pro` to show the price. `npx` itself may check npm for a newer version; a global install avoids that.
|
|
110
|
+
- The status line never shows ads.
|
|
111
|
+
- `claudekit-terminal remove --all` deletes `~/.claudekit`, which holds the numbers, this terminal's id and your key. Backups you made stay where you put them.
|
|
112
|
+
|
|
113
|
+
## Moving from claudekit-statusline
|
|
114
|
+
|
|
115
|
+
This package replaces `claudekit-statusline`. Run `npx claudekit-terminal setup` and it swaps the old status line for the new one.
|
|
116
|
+
|
|
117
|
+
## License
|
|
118
|
+
|
|
119
|
+
MIT
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// ClaudeKit for the terminal. With no command and JSON piped in (that's how Claude Code runs a
|
|
3
|
+
// status line), it prints the status line and always exits 0 so it can never break Claude Code.
|
|
4
|
+
// Every other command: `claudekit-terminal help`.
|
|
5
|
+
|
|
6
|
+
import { FALLBACK } from '../lib/statusline.js';
|
|
7
|
+
|
|
8
|
+
const argv = process.argv.slice(2);
|
|
9
|
+
const first = argv[0];
|
|
10
|
+
const isStatusLine = first === 'statusline' || ((!first || first.startsWith('--')) && !process.stdin.isTTY && !['--help', '-h', '--version', '-v'].includes(first));
|
|
11
|
+
|
|
12
|
+
if (isStatusLine) {
|
|
13
|
+
runStatusLine();
|
|
14
|
+
} else {
|
|
15
|
+
const { run } = await import('../lib/cli.js');
|
|
16
|
+
process.exitCode = await run(argv);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function runStatusLine() {
|
|
20
|
+
const STDIN_TIMEOUT_MS = 1000;
|
|
21
|
+
let finished = false;
|
|
22
|
+
const flags = first === 'statusline' ? argv.slice(1) : argv;
|
|
23
|
+
|
|
24
|
+
async function finish(raw) {
|
|
25
|
+
if (finished) return;
|
|
26
|
+
finished = true;
|
|
27
|
+
let line = FALLBACK;
|
|
28
|
+
try {
|
|
29
|
+
const [{ statusLineFor, defaultIo }] = await Promise.all([import('../lib/cli.js')]);
|
|
30
|
+
line = statusLineFor(raw, flags, defaultIo());
|
|
31
|
+
} catch {
|
|
32
|
+
line = FALLBACK;
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
process.stdout.write(`${line}\n`, () => process.exit(0));
|
|
36
|
+
} catch {
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
process.on('uncaughtException', () => (finished ? process.exit(0) : finish('')));
|
|
42
|
+
process.stdout.on('error', () => process.exit(0));
|
|
43
|
+
|
|
44
|
+
if (process.stdin.isTTY) {
|
|
45
|
+
finish('');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const chunks = [];
|
|
49
|
+
const done = () => finish(chunks.join(''));
|
|
50
|
+
process.stdin.setEncoding('utf8');
|
|
51
|
+
process.stdin.on('data', (chunk) => chunks.push(chunk));
|
|
52
|
+
process.stdin.on('end', done);
|
|
53
|
+
process.stdin.on('error', done);
|
|
54
|
+
// Never hang if stdin stays open.
|
|
55
|
+
setTimeout(done, STDIN_TIMEOUT_MS).unref();
|
|
56
|
+
}
|
package/lib/cleanup.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// Claude Code deletes chats silently (docs: claude-directory "Cleaned up automatically"): a session
|
|
2
|
+
// file older than `cleanupPeriodDays` (default 30, minimum 1) goes in a background sweep after a
|
|
3
|
+
// session starts. Sessions started or last continued in Claude Desktop or Cowork are kept at any
|
|
4
|
+
// age unless `desktopSessionCleanupPeriodDays` is set. This finds the chats due to go in the next
|
|
5
|
+
// few days, so ClaudeKit can say so before they're gone (free), with backup (Pro) as the way to keep them.
|
|
6
|
+
|
|
7
|
+
import { closeSync, existsSync, fstatSync, openSync, readFileSync, readSync } from 'node:fs';
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
|
|
10
|
+
import { DAY_MS } from './format.js';
|
|
11
|
+
import { defaultBackupDir, settingsPath } from './paths.js';
|
|
12
|
+
import { listSessions } from './transcripts.js';
|
|
13
|
+
|
|
14
|
+
function readDays(value) {
|
|
15
|
+
const n = Number(value);
|
|
16
|
+
return Number.isInteger(n) && n >= 1 ? n : null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The retention settings from ~/.claude/settings.json. */
|
|
20
|
+
export function retention(env = process.env) {
|
|
21
|
+
try {
|
|
22
|
+
const settings = JSON.parse(readFileSync(settingsPath(env), 'utf8'));
|
|
23
|
+
return { days: readDays(settings?.cleanupPeriodDays) ?? 30, desktopDays: readDays(settings?.desktopSessionCleanupPeriodDays) };
|
|
24
|
+
} catch {
|
|
25
|
+
return { days: 30, desktopDays: null };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The last "entrypoint" recorded in a transcript (read from its end only). */
|
|
30
|
+
export function lastEntrypoint(path) {
|
|
31
|
+
try {
|
|
32
|
+
const fd = openSync(path, 'r');
|
|
33
|
+
try {
|
|
34
|
+
const size = fstatSync(fd).size;
|
|
35
|
+
const length = Math.min(size, 256 * 1024);
|
|
36
|
+
const buf = Buffer.alloc(length);
|
|
37
|
+
readSync(fd, buf, 0, length, size - length);
|
|
38
|
+
const matches = [...buf.toString('utf8').matchAll(/"entrypoint":"([^"]{1,40})"/g)];
|
|
39
|
+
return matches.length ? matches.at(-1)[1] : null;
|
|
40
|
+
} finally {
|
|
41
|
+
closeSync(fd);
|
|
42
|
+
}
|
|
43
|
+
} catch {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const isDesktop = (entrypoint) => typeof entrypoint === 'string' && /desktop|cowork/i.test(entrypoint);
|
|
49
|
+
|
|
50
|
+
/** Chat ids already copied by `backup` into the default folder, unchanged since. */
|
|
51
|
+
function backedUp(env) {
|
|
52
|
+
try {
|
|
53
|
+
const manifest = JSON.parse(readFileSync(join(defaultBackupDir(env), '.claudekit-backup.json'), 'utf8'));
|
|
54
|
+
return manifest?.chats && typeof manifest.chats === 'object' ? manifest.chats : {};
|
|
55
|
+
} catch {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Chats Claude Code will delete within `withinDays`, not already in the backup.
|
|
62
|
+
* @returns {{ count: number, days: number, soonest: number | null }}
|
|
63
|
+
*/
|
|
64
|
+
export function expiringChats(env = process.env, now = Date.now(), withinDays = 3) {
|
|
65
|
+
const { days, desktopDays } = retention(env);
|
|
66
|
+
const kept = backedUp(env);
|
|
67
|
+
let count = 0;
|
|
68
|
+
let soonest = null;
|
|
69
|
+
for (const file of listSessions(env)) {
|
|
70
|
+
const known = kept[file.id];
|
|
71
|
+
if (known && known.size === file.size && known.mtimeMs === file.mtimeMs && existsSync(join(defaultBackupDir(env), known.file))) continue;
|
|
72
|
+
const quickest = Math.min(days, desktopDays ?? days);
|
|
73
|
+
if (file.mtimeMs + (quickest - withinDays) * DAY_MS > now) continue;
|
|
74
|
+
const desktop = isDesktop(lastEntrypoint(file.path));
|
|
75
|
+
const limit = desktop ? desktopDays : days;
|
|
76
|
+
if (limit === null) continue;
|
|
77
|
+
const goesAt = file.mtimeMs + limit * DAY_MS;
|
|
78
|
+
if (goesAt - now > withinDays * DAY_MS) continue;
|
|
79
|
+
count += 1;
|
|
80
|
+
soonest = soonest === null ? goesAt : Math.min(soonest, goesAt);
|
|
81
|
+
}
|
|
82
|
+
return { count, days, soonest };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** "Claude Code will delete 3 chats in the next 3 days (…)". '' when none. */
|
|
86
|
+
export function expiryLine(found, say, withinDays = 3) {
|
|
87
|
+
if (!found?.count) return '';
|
|
88
|
+
const chats = found.count === 1 ? '1 chat' : `${found.count} chats`;
|
|
89
|
+
return `Claude Code will delete ${chats} in the next ${withinDays} days (it keeps ${found.days} days). Keep them: ${say} backup (Pro), or raise "cleanupPeriodDays" in ~/.claude/settings.json.`;
|
|
90
|
+
}
|