tokentrimmer 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/README.md +20 -12
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # TokenTrimmer
2
2
 
3
+ [![npm](https://img.shields.io/npm/v/tokentrimmer)](https://www.npmjs.com/package/tokentrimmer) [![license: MIT](https://img.shields.io/npm/l/tokentrimmer)](LICENSE) ![dependencies: 0](https://img.shields.io/badge/dependencies-0-brightgreen)
4
+
3
5
  ![TokenTrimmer: a local proxy that losslessly compresses tool output, e.g. a JSON array becomes a table](docs/social-preview.png)
4
6
 
5
7
  **Reduce Claude Code token usage and LLM API cost, without losing information.** TokenTrimmer compresses tool
@@ -43,25 +45,32 @@ your own number.
43
45
  ## Run
44
46
 
45
47
  ```
46
- npm start
48
+ npx tokentrimmer
47
49
  # Anthropic SDK: ANTHROPIC_BASE_URL=http://127.0.0.1:8787
48
50
  # OpenAI SDK: OPENAI_BASE_URL=http://127.0.0.1:8787/v1
49
51
  # Dashboard: http://127.0.0.1:8787/
50
52
  ```
51
53
 
52
- Start with `DRY_RUN=1 npm start` first. Requests are measured and the dashboard
54
+ Start with `DRY_RUN=1 npx tokentrimmer` first. Requests are measured and the dashboard
53
55
  shows what you would save, but the original request is forwarded unchanged.
54
56
 
55
57
  ## Use with Claude
56
58
 
57
- Install (not on npm; nothing to `npm install`, there are no dependencies):
59
+ Run it straight from npm (Node 18+, no dependencies):
60
+
61
+ ```
62
+ npx tokentrimmer # safe (lossless) mode; leave this running
63
+ ```
64
+
65
+ Or install it once, so it starts instantly and works offline:
58
66
 
59
67
  ```
60
- git clone https://github.com/an21an21/tokentrimmer.git
61
- cd tokentrimmer
62
- npm start # safe (lossless) mode; leave this running
68
+ npm install -g tokentrimmer
69
+ tokentrimmer
63
70
  ```
64
71
 
72
+ From source: `git clone https://github.com/an21an21/tokentrimmer.git && cd tokentrimmer && npm start`.
73
+
65
74
  ### Claude Code in the terminal
66
75
 
67
76
  Works with both an API key and a Claude subscription login; the proxy forwards your auth headers unchanged.
@@ -69,8 +78,7 @@ Works with both an API key and a Claude subscription login; the proxy forwards y
69
78
  1. Terminal 1, start the proxy and leave it running:
70
79
 
71
80
  ```
72
- cd tokentrimmer
73
- npm start
81
+ npx tokentrimmer
74
82
  ```
75
83
 
76
84
  2. Terminal 2, start Claude Code through it (same for `claude -p` and `claude --resume`):
@@ -90,13 +98,13 @@ leaves your machine):
90
98
  ANTHROPIC_BASE_URL=http://127.0.0.1:8787 ANTHROPIC_CUSTOM_HEADERS="x-tokentrimmer-mode: balanced" claude
91
99
  ```
92
100
 
93
- A shell shortcut that starts the proxy in the background when needed (add to `~/.zshrc` or `~/.bashrc`,
94
- and change `~/tokentrimmer` to where you cloned it):
101
+ A shell shortcut that starts the proxy in the background when needed. Install it once with
102
+ `npm install -g tokentrimmer`, then add this to `~/.zshrc` or `~/.bashrc`:
95
103
 
96
104
  ```sh
97
105
  claude-trim() {
98
106
  curl -sf http://127.0.0.1:8787/health >/dev/null ||
99
- (cd ~/tokentrimmer && nohup npm start >/tmp/tokentrimmer.log 2>&1 &)
107
+ (nohup tokentrimmer >/tmp/tokentrimmer.log 2>&1 &)
100
108
  until curl -sf http://127.0.0.1:8787/health >/dev/null; do sleep 0.2; done
101
109
  ANTHROPIC_BASE_URL=http://127.0.0.1:8787 claude "$@"
102
110
  }
@@ -123,7 +131,7 @@ client = anthropic.Anthropic(base_url="http://127.0.0.1:8787")
123
131
  const client = new Anthropic({ baseURL: 'http://127.0.0.1:8787' });
124
132
  ```
125
133
 
126
- Which mode: the default, `safe`, is lossless. `balanced` and `aggressive` (`TOKENTRIMMER_MODE=balanced npm start`)
134
+ Which mode: the default, `safe`, is lossless. `balanced` and `aggressive` (`TOKENTRIMMER_MODE=balanced npx tokentrimmer`)
127
135
  drop content; see the accuracy results below before turning them on for coding work. `TOKENTRIMMER_MODE=balanced
128
136
  TOKENTRIMMER_STALE_AFTER=10 TOKENTRIMMER_RETRIEVE=1` (stale results need a lossy mode) saves the most on long sessions and lets Claude fetch shortened results back; it
129
137
  is experimental.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokentrimmer",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Cut Claude Code, Anthropic and OpenAI token usage and API cost: a local proxy that losslessly compresses tool output (JSON, logs, grep) before it reaches the API. Prompt-cache safe, zero dependencies.",
5
5
  "keywords": [
6
6
  "claude",