1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
use clap::{Parser, Subcommand};
/// Code intelligence for Rust codebases.
#[derive(Parser)]
#[command(
name = "tokensave",
about = "Code intelligence for 15 languages — semantic graph queries instead of file reads",
version
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
}
#[derive(Subcommand)]
pub enum Commands {
/// Initialize a new TokenSave project (full index)
Init {
/// Project path (default: current directory)
path: Option<String>,
/// Folders to skip during indexing (can be repeated)
#[arg(long = "skip-folder", num_args = 1..)]
skip_folders: Vec<String>,
},
/// Incremental sync (project must already be initialized with `tokensave init`)
Sync {
/// Project path (default: current directory)
path: Option<String>,
/// Force a full re-index
#[arg(short, long)]
force: bool,
/// Folders to skip during indexing (can be repeated)
#[arg(long = "skip-folder", num_args = 1..)]
skip_folders: Vec<String>,
/// List added, modified, and removed files after sync
#[arg(long)]
doctor: bool,
/// Print per-phase diagnostics (file counts, timings) to help debug slow syncs
#[arg(short, long)]
verbose: bool,
},
/// Show project statistics
Status {
/// Project path (default: current directory)
path: Option<String>,
/// Output as JSON
#[arg(short, long)]
json: bool,
/// Show only the header (version, tokens, sync times)
#[arg(short, long)]
short: bool,
/// Show node-kind breakdown
#[arg(short, long)]
details: bool,
},
/// Search for symbols
Query {
/// Search query
search: String,
/// Project path
#[arg(short, long)]
path: Option<String>,
/// Maximum results
#[arg(short, long, default_value = "10")]
limit: usize,
},
/// Build context for a task
Context {
/// Task description
task: String,
/// Project path
#[arg(short, long)]
path: Option<String>,
/// Maximum symbols
#[arg(short = 'n', long, default_value = "20")]
max_nodes: usize,
/// Output format (markdown or json)
#[arg(short, long, default_value = "markdown")]
format: String,
},
/// List indexed files
Files {
/// Project path
#[arg(short, long)]
path: Option<String>,
/// Filter to files under this directory
#[arg(long)]
filter: Option<String>,
/// Filter files matching this glob pattern
#[arg(long)]
pattern: Option<String>,
/// Output as JSON
#[arg(short, long)]
json: bool,
},
/// Find test files affected by changed source files
Affected {
/// Changed file paths
files: Vec<String>,
/// Project path
#[arg(short, long)]
path: Option<String>,
/// Read file list from stdin (one per line)
#[arg(long)]
stdin: bool,
/// Max dependency traversal depth
#[arg(short, long, default_value = "5")]
depth: usize,
/// Custom glob filter for test files
#[arg(short, long)]
filter: Option<String>,
/// Output as JSON
#[arg(short, long)]
json: bool,
/// Only output file paths, no decoration
#[arg(short, long)]
quiet: bool,
},
/// Configure agent integration (MCP server, permissions, hooks, prompt rules)
#[command(name = "install", visible_alias = "claude-install")]
Install {
/// Agent to configure (auto-detects if omitted)
#[arg(long)]
agent: Option<String>,
},
/// Refresh settings for all already-installed agents
Reinstall,
/// Remove agent integration (MCP server, permissions, hooks, prompt rules)
#[command(name = "uninstall", visible_alias = "claude-uninstall")]
Uninstall {
/// Agent to remove (removes all if omitted)
#[arg(long)]
agent: Option<String>,
},
/// Extraction worker (spawned by tokensave itself; not for direct use).
#[command(name = "extract-worker", hide = true)]
ExtractWorker,
/// PreToolUse hook handler (called by Claude Code, not by users directly)
#[command(name = "hook-pre-tool-use", hide = true)]
HookPreToolUse,
/// UserPromptSubmit hook handler (resets session counter)
#[command(name = "hook-prompt-submit", hide = true)]
HookPromptSubmit,
/// Stop hook handler (prints session token savings)
#[command(name = "hook-stop", hide = true)]
HookStop,
/// Start MCP server over stdio
Serve {
/// Project path
#[arg(short, long)]
path: Option<String>,
},
/// Download and install the latest version from GitHub
Upgrade,
/// Show or switch the update channel (stable or beta)
Channel {
/// Target channel: "stable" or "beta" (omit to show current)
channel: Option<String>,
},
/// Show the resettable project-local token counter
#[command(name = "current-counter")]
CurrentCounter {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Reset the project-local token counter to zero
#[command(name = "reset-counter")]
ResetCounter {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Disable uploading token counts to the worldwide counter
#[command(name = "disable-upload-counter")]
DisableUploadCounter,
/// Enable uploading token counts to the worldwide counter
#[command(name = "enable-upload-counter")]
EnableUploadCounter,
/// Show or change whether .gitignore rules are respected during indexing
#[command(name = "gitignore")]
Gitignore {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
/// "on" to enable, "off" to disable, omit to show current setting
action: Option<String>,
},
/// Check tokensave installation, configuration, and agent integration
Doctor {
/// Check only this agent (default: all agents)
#[arg(long)]
agent: Option<String>,
},
/// Background file watcher daemon
Daemon {
/// Run in foreground (don't fork)
#[arg(long)]
foreground: bool,
/// Stop the running daemon
#[arg(long)]
stop: bool,
/// Show daemon status
#[arg(long)]
status: bool,
/// Install autostart service (launchd/systemd)
#[arg(long)]
enable_autostart: bool,
/// Remove autostart service
#[arg(long)]
disable_autostart: bool,
/// Override debounce duration (e.g. "2s", "15s", "1m"). Overrides config.
#[arg(long)]
debounce: Option<String>,
},
/// Token cost summary from Claude Code sessions
Cost {
/// Time range: "today", "7d", "30d", "month", or "all"
#[arg(default_value = "7d")]
range: String,
/// Group by model
#[arg(long)]
by_model: bool,
/// Group by task category
#[arg(long)]
by_task: bool,
/// Export format: csv or json
#[arg(long)]
export: Option<String>,
},
/// Run a reproducible retrieval benchmark against the current project.
Bench {
/// Path to a TOML query file (defaults to the shipped default set).
#[arg(long)]
queries: Option<String>,
/// Output as JSON instead of a markdown table.
#[arg(long)]
json: bool,
/// Project path (default: current directory).
#[arg(short, long)]
path: Option<String>,
/// Max nodes per query (default: 20).
#[arg(long, default_value = "20")]
max_nodes: usize,
},
/// Show token savings (and dollar estimates) recorded in the global ledger.
Gain {
/// Show all projects (default: only the current project).
#[arg(short, long)]
all: bool,
/// Print per-day history instead of a single total.
#[arg(long)]
history: bool,
/// Time range: "today", "7d", "30d", "month", or "all" (default: "30d").
#[arg(long, default_value = "30d")]
range: String,
/// Output as JSON.
#[arg(long)]
json: bool,
},
/// Live token savings monitor (global, all projects)
Monitor,
/// Manage multi-branch indexing
Branch {
#[command(subcommand)]
action: BranchAction,
},
/// Wipe local tokensave DBs (current folder, parents, and children)
Wipe {
/// Wipe ALL tracked projects so the global DB ends empty
#[arg(short, long)]
all: bool,
},
/// List tokensave projects (current folder, parents, and children)
List {
/// List ALL tracked projects from the global DB
#[arg(short, long)]
all: bool,
},
}
#[derive(Subcommand)]
pub enum BranchAction {
/// List tracked branches and their DB sizes
List {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Track a new branch (copies nearest ancestor DB + incremental sync)
Add {
/// Branch name to track (default: current branch)
name: Option<String>,
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Remove a tracked branch and delete its DB
Remove {
/// Branch name to remove
name: String,
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Remove all tracked branches (keeps only the default branch)
Removeall {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
/// Remove DBs for branches that no longer exist in git
Gc {
/// Project path (default: current directory)
#[arg(short, long)]
path: Option<String>,
},
}