claudectx 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.
- package/LICENSE +21 -0
- package/README.md +276 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3026 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +3008 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +96 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Horilla
|
|
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
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>claudectx</h1>
|
|
3
|
+
<p><strong>Reduce Claude Code token usage by up to 80% — with zero workflow changes.</strong></p>
|
|
4
|
+
|
|
5
|
+
<a href="https://npmjs.com/package/claudectx"><img src="https://img.shields.io/npm/v/claudectx.svg?style=flat-square" alt="npm version" /></a>
|
|
6
|
+
<a href="https://github.com/Horilla/claudectx/stargazers"><img src="https://img.shields.io/github/stars/Horilla/claudectx?style=flat-square" alt="GitHub Stars" /></a>
|
|
7
|
+
<img src="https://img.shields.io/npm/dm/claudectx.svg?style=flat-square" alt="npm downloads" />
|
|
8
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square" alt="MIT License" /></a>
|
|
9
|
+
<a href="https://github.com/Horilla/claudectx/actions"><img src="https://img.shields.io/github/actions/workflow/status/Horilla/claudectx/ci.yml?style=flat-square" alt="CI" /></a>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<br />
|
|
13
|
+
|
|
14
|
+
<div align="center">
|
|
15
|
+
<img src="docs/demo.gif" alt="claudectx demo" width="700" />
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Why claudectx?
|
|
21
|
+
|
|
22
|
+
A typical Claude Code session costs **$2–$15 in tokens**. Most of it is wasted:
|
|
23
|
+
|
|
24
|
+
| Problem | Impact | Fix |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| Bloated `CLAUDE.md` injected every request | 6,000–14,000 extra tokens/request | `claudectx optimize --claudemd` |
|
|
27
|
+
| No `.claudeignore` — reads `node_modules/` | 40–60% of search tokens wasted | `claudectx optimize --ignorefile` |
|
|
28
|
+
| Full file reads for small questions | 70% overhead from unnecessary lines | `claudectx mcp` |
|
|
29
|
+
| No prompt caching configured | Paying 10× for static context | `claudectx optimize --cache` |
|
|
30
|
+
| No cross-session memory | Repeating the same context every session | `claudectx compress` |
|
|
31
|
+
|
|
32
|
+
### Where your tokens actually go
|
|
33
|
+
|
|
34
|
+
| Component | Typical Tokens | % of Total | Fixable? |
|
|
35
|
+
|---|---|---|---|
|
|
36
|
+
| Claude Code system prompt | 4,200 | 14% | No |
|
|
37
|
+
| Tool definitions (built-in) | 2,100 | 7% | No |
|
|
38
|
+
| MCP tool schemas | 1,980 | 7% | Partially |
|
|
39
|
+
| **CLAUDE.md** | **6,800–14,000** | **22–46%** | **YES — biggest win** |
|
|
40
|
+
| MEMORY.md / memory files | 3,300 | 11% | YES |
|
|
41
|
+
| Conversation history (grows) | 2,000–40,000 | 7–57% | YES |
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Quick Start
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
# No install needed — try it immediately
|
|
49
|
+
npx claudectx analyze
|
|
50
|
+
|
|
51
|
+
# Fix everything automatically
|
|
52
|
+
npx claudectx optimize --apply
|
|
53
|
+
|
|
54
|
+
# See what's happening in real time while Claude is coding
|
|
55
|
+
claudectx watch
|
|
56
|
+
|
|
57
|
+
# After your session: compress it into a tiny MEMORY.md entry
|
|
58
|
+
claudectx compress
|
|
59
|
+
|
|
60
|
+
# Review your token spend for the last 7 days
|
|
61
|
+
claudectx report
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
npm install -g claudectx
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## Commands
|
|
73
|
+
|
|
74
|
+
### `claudectx analyze` — See exactly where your tokens go
|
|
75
|
+
|
|
76
|
+
```
|
|
77
|
+
╔══════════════════════════════════════════════════════════════╗
|
|
78
|
+
║ claudectx — Context Analysis ║
|
|
79
|
+
║ Project: /Users/you/my-project ║
|
|
80
|
+
╠══════════════════════════════════════════════════════════════╣
|
|
81
|
+
║ Tokens per request: 18,432 Est. session cost: $1.84 ║
|
|
82
|
+
║ Model: claude-sonnet-4-6 Context used: 1.8% of 1M ║
|
|
83
|
+
╠═══════════════════════════════╦══════════╦═══════╦══════════╣
|
|
84
|
+
║ Component ║ Tokens ║ Cost ║ Status ║
|
|
85
|
+
╠═══════════════════════════════╬══════════╬═══════╬══════════╣
|
|
86
|
+
║ System prompt (built-in) ║ 4,200 ║ $0.01 ║ ✓ ║
|
|
87
|
+
║ Tool definitions (built-in) ║ 2,100 ║ $0.01 ║ ✓ ║
|
|
88
|
+
║ CLAUDE.md (./CLAUDE.md) ║ 7,841 ║ $0.02 ║ ⚠ ║
|
|
89
|
+
║ MEMORY.md ║ 2,551 ║ $0.01 ║ ✓ ║
|
|
90
|
+
╠═══════════════════════════════╬══════════╬═══════╬══════════╣
|
|
91
|
+
║ TOTAL (per request) ║ 18,432 ║ $0.06 ║ ║
|
|
92
|
+
╚═══════════════════════════════╩══════════╩═══════╩══════════╝
|
|
93
|
+
|
|
94
|
+
⚠ 3 optimization opportunities found:
|
|
95
|
+
|
|
96
|
+
[1] CLAUDE.md is 7,841 tokens — 292% over the 2,000 token recommendation
|
|
97
|
+
→ Run `claudectx optimize --claudemd` to split into demand-loaded files
|
|
98
|
+
→ Potential savings: ~5,841 tokens/request (~$3.51/hour at 60 req/hr)
|
|
99
|
+
|
|
100
|
+
[2] No .claudeignore file found
|
|
101
|
+
→ Run `claudectx optimize --ignorefile` to generate one
|
|
102
|
+
|
|
103
|
+
[3] CLAUDE.md contains dynamic timestamp on line 3
|
|
104
|
+
→ Breaks prompt caching — run `claudectx optimize --cache` to fix
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
claudectx analyze # Analyze current directory
|
|
109
|
+
claudectx analyze --path /path/to/proj # Analyze specific path
|
|
110
|
+
claudectx analyze --json # Raw JSON output
|
|
111
|
+
claudectx analyze --model sonnet # Calculate for specific model
|
|
112
|
+
claudectx analyze --watch # Re-run on file changes
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
### `claudectx optimize` — Auto-fix token waste
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
claudectx optimize # Interactive — confirm each change
|
|
121
|
+
claudectx optimize --apply # Apply all fixes without prompting
|
|
122
|
+
claudectx optimize --dry-run # Preview changes without applying
|
|
123
|
+
claudectx optimize --claudemd # Only optimize CLAUDE.md
|
|
124
|
+
claudectx optimize --ignorefile # Only generate .claudeignore
|
|
125
|
+
claudectx optimize --cache # Only fix cache-busting content
|
|
126
|
+
claudectx optimize --hooks # Only install session hooks
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
What it does:
|
|
130
|
+
|
|
131
|
+
- **CLAUDE.md splitter** — Parses your CLAUDE.md by `##` sections, keeps core rules inline (<2K tokens), moves reference docs to `.claude/` loaded on demand with `@file` references.
|
|
132
|
+
- **.claudeignore generator** — Detects your project type (Node, Python, Rust, Go) and generates a `.claudeignore` with sensible defaults.
|
|
133
|
+
- **Cache advisor** — Finds date strings, timestamps, and other patterns that break prompt caching and comments them out.
|
|
134
|
+
- **Hooks installer** — Installs a `PostToolUse` hook in `.claude/settings.local.json` so `claudectx watch` can track files in real time.
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
### `claudectx watch` — Live token dashboard
|
|
139
|
+
|
|
140
|
+
Real-time terminal UI showing token burn rate, cache hit rate, and most-read files while Claude Code is running.
|
|
141
|
+
|
|
142
|
+
```bash
|
|
143
|
+
claudectx watch # Launch dashboard
|
|
144
|
+
claudectx watch --session <id> # Watch a specific session
|
|
145
|
+
claudectx watch --clear # Clear the read log and exit
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The dashboard auto-refreshes every 2 seconds and updates instantly when a new file is read (requires hooks from `claudectx optimize --hooks`).
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
### `claudectx mcp` — Smart MCP server
|
|
153
|
+
|
|
154
|
+
An MCP server that lets Claude read just one function or class from a file instead of the whole thing — **up to 97% fewer tokens per read**.
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
claudectx mcp # Start MCP server (stdio)
|
|
158
|
+
claudectx mcp --install # Auto-add to .claude/settings.json
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Tools provided to Claude:**
|
|
162
|
+
- **`smart_read`** — Read a specific symbol (function, class, method) by name, or a line range
|
|
163
|
+
- **`search_symbols`** — Find where a symbol is defined without reading any files
|
|
164
|
+
- **`index_project`** — Build the symbol index for the current project
|
|
165
|
+
|
|
166
|
+
Configure manually in `.claude/settings.json`:
|
|
167
|
+
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"mcpServers": {
|
|
171
|
+
"claudectx": {
|
|
172
|
+
"command": "claudectx",
|
|
173
|
+
"args": ["mcp"],
|
|
174
|
+
"type": "stdio"
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
---
|
|
181
|
+
|
|
182
|
+
### `claudectx compress` — Session memory compression
|
|
183
|
+
|
|
184
|
+
Compress the full session JSONL into a compact MEMORY.md entry at the end of your session. Uses `claude-haiku` if `ANTHROPIC_API_KEY` is set, otherwise falls back to a structured heuristic summary.
|
|
185
|
+
|
|
186
|
+
```bash
|
|
187
|
+
claudectx compress # Compress most recent session
|
|
188
|
+
claudectx compress --session <id> # Compress specific session
|
|
189
|
+
claudectx compress --auto # Non-interactive (for hooks)
|
|
190
|
+
claudectx compress --prune --days 30 # Also prune entries older than 30 days
|
|
191
|
+
claudectx compress --api-key <key> # Provide API key explicitly
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
A typical 8,000-token session compresses to ~180 tokens — **97.8% reduction**.
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
### `claudectx report` — Usage analytics
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
claudectx report # Last 7 days (plain text)
|
|
202
|
+
claudectx report --days 30 # Last 30 days
|
|
203
|
+
claudectx report --json # JSON output
|
|
204
|
+
claudectx report --markdown # Markdown output
|
|
205
|
+
claudectx report --model opus # Cost estimate for a different model
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
claudectx report — 7-day summary (2026-04-04 → 2026-04-11)
|
|
210
|
+
══════════════════════════════════════════════════════════════════════
|
|
211
|
+
|
|
212
|
+
TOTALS
|
|
213
|
+
────────────────────────────
|
|
214
|
+
Sessions: 23
|
|
215
|
+
Requests: 847
|
|
216
|
+
Input tokens: 2,341,200
|
|
217
|
+
Output tokens: 318,400
|
|
218
|
+
Cache reads: 1,204,000 (51% hit rate)
|
|
219
|
+
Total cost (est.): $4.87
|
|
220
|
+
Avg cost/session: $0.21
|
|
221
|
+
Avg tokens/request: 2,766
|
|
222
|
+
|
|
223
|
+
DAILY USAGE
|
|
224
|
+
────────────────────────────
|
|
225
|
+
2026-04-11 ████████████████░░ 412K in $1.02 (5 sess)
|
|
226
|
+
2026-04-10 █████████░░░░░░░░░ 234K in $0.58 (4 sess)
|
|
227
|
+
...
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## How it all fits together
|
|
233
|
+
|
|
234
|
+
```
|
|
235
|
+
Before claudectx: After claudectx:
|
|
236
|
+
───────────────────────────── ─────────────────────────────
|
|
237
|
+
Every request: Every request:
|
|
238
|
+
CLAUDE.md: 12,400 tokens → CLAUDE.md core: 1,800 tokens
|
|
239
|
+
No caching: pay full price → Cache hit rate: 70%+
|
|
240
|
+
Full file reads every time → smart_read: symbol-level only
|
|
241
|
+
|
|
242
|
+
End of session: End of session:
|
|
243
|
+
Session forgotten → claudectx compress → 187 tokens
|
|
244
|
+
Start from scratch next time → MEMORY.md carries key context forward
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## Token Savings — Share Your Results
|
|
250
|
+
|
|
251
|
+
Join the **[Token Savings Hall of Fame](https://github.com/Horilla/claudectx/discussions)** — share your before/after numbers.
|
|
252
|
+
|
|
253
|
+
---
|
|
254
|
+
|
|
255
|
+
## Contributing
|
|
256
|
+
|
|
257
|
+
PRs welcome. Please read [CONTRIBUTING.md](CONTRIBUTING.md) first.
|
|
258
|
+
|
|
259
|
+
```bash
|
|
260
|
+
git clone https://github.com/Horilla/claudectx.git
|
|
261
|
+
cd claudectx
|
|
262
|
+
npm install
|
|
263
|
+
npm run build
|
|
264
|
+
npm test # 199 tests, should all pass
|
|
265
|
+
npm run lint # 0 errors expected
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
MIT — see [LICENSE](LICENSE)
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
<div align="center">
|
|
275
|
+
<sub>Built by <a href="https://github.com/Horilla">Horilla</a> · If claudectx saved you money, a ⭐ helps more developers find it!</sub>
|
|
276
|
+
</div>
|
package/dist/index.d.mts
ADDED
package/dist/index.d.ts
ADDED