claude_storage 1.0.0

CLI tool for exploring Claude Code filesystem storage
Documentation
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# claude_storage

CLI tool for exploring and analyzing Claude Code's filesystem-based conversation storage.

## Files

| File / Directory | Responsibility |
|------------------|----------------|
| `Cargo.toml` | Crate manifest: deps, features, build script |
| `build.rs` | Transforms YAML command definitions to static PHF registry |
| `unilang.commands.yaml` | Command definitions (9 commands) |
| `src/` | CLI pipeline, command routines, binary entry points |
| `tests/` | Integration and parameter validation tests (242 tests) |
| `docs/` | Behavioral requirements: features, CLI reference, operation docs |
| `task/` | Crate-level task tracking |
| `examples/` | Usage examples for storage API |
| `changelog.md` | Notable changes by version |

## overview

This crate provides a command-line interface for querying Claude Code's conversation storage at `~/.claude/`. It wraps the `claude_storage_core` library with an interactive REPL and one-shot command interface.

**v1.0 Status**: Core library (`claude_storage_core`) is production-ready with comprehensive validation (122 tests, production session parsing). CLI wrapper commands `.status`, `.list`, and `.count` are fully validated. For programmatic access or advanced usage, we recommend using the `claude_storage_core` library API directly (see "library api" section below).

**Extraction context**: This is the CLI-focused crate after extracting core library functionality to `claude_storage_core` (2025-11-29).

## installation

```bash
cargo install --path . --features cli
```

Or run directly:
```bash
cargo run --features cli
```

## usage

### repl mode (interactive)

```bash
cargo run --features cli
```

```text
claude_storage> .status
Storage: "/home/user/.claude"
Projects: 230 (UUID: 14, Path: 216)
Sessions: 7546 (Main: 1061, Agent: 6485)
Entries: 323231

claude_storage> .list target::projects
UUID projects: 14
Path projects: 216

claude_storage> .count target::sessions
Total sessions: 7546

claude_storage> exit
```

### one-shot mode (scripting)

```bash
# Get storage statistics
cargo run --features cli -- .status

# Count projects
cargo run --features cli -- .count target::projects

# List projects with filtering
cargo run --features cli -- .list target::projects filter::path

# Show session details
cargo run --features cli -- .show session::abc123 verbosity::2
```

## commands

### .status

Show storage statistics (projects, sessions, entries, tokens).

**Parameters**:
- `verbosity::N` (0-5, default 1) - Detail level

**Example**:
```bash
.status verbosity::2
```

### .list

List projects or sessions with optional filtering.

**Parameters**:
- `type::{uuid|path|all}` (optional, default: all) - Filter by project type
- `verbosity::N` (0-5, default: 1) - Output detail level
- `sessions::{0|1}` (optional, auto-detected) - Show sessions (auto-enabled when session filters provided)
- `path::{value}` (optional) - Filter projects by path (supports smart resolution, see below)
- `agent::{0|1}` (optional) - Filter sessions by type (auto-enables session display)
- `min_entries::N` (optional) - Filter sessions by minimum entry count (auto-enables session display)
- `session::{substring}` (optional) - Filter sessions by ID substring (auto-enables session display)

**Path Parameter - Smart Resolution**:

The `path::` parameter supports both shell-style path resolution and pattern matching:

- **Special paths** (resolved to absolute paths):
  - `path::.` → Current working directory
  - `path::..` → Parent directory
  - `path::~` → Home directory
  - `path::~/subdir` → Home directory + relative path

- **Patterns** (substring matching):
  - `path::assistant` → Match any path containing "assistant"
  - `path::storage` → Match any path containing "storage"

**Examples**:
```bash
# List all projects
.list

# List path-based projects only
.list type::path

# Path resolution (current directory)
cd /home/user/project
.list path::.

# Path resolution (parent directory)
.list path::..

# Path resolution (home directory)
.list path::~

# Pattern matching (backward compatible)
.list path::assistant

# Filter sessions with auto-enable
.list session::commit          # Auto-enables session display
.list agent::1 min_entries::10 # Agent sessions with 10+ entries

# Combine filters
.list path::claude_storage session::default
```

### .show

Display session or project details with **conversation content by default** (REQ-011: Content-First Display).

**Smart Behavior** (adapts to parameters):
- **No parameters** → Shows current directory project (all sessions)
- **session_id only** → Shows that session in current project with conversation content
- **project only** → Shows that project (all sessions)
- **Both parameters** → Shows that session in that project with conversation content

**Parameters**:
- `session_id::{uuid-or-agent-id}` (optional) - Session UUID or agent-{hex}
- `project::{path-or-id}` (optional) - Project path or UUID (default: current directory)
- `verbosity::N` (0-5, default 1) - Output detail level
- `entries::1` (optional) - Show all entries (backward compat with old UUID list format)
- `metadata::1` (optional) - Show metadata only (old behavior, no conversation content)

**Default Behavior** (NEW):
Shows actual conversation content in readable chat-log format. No parameters needed to read messages.

**Examples**:
```bash
# Show current directory project (all sessions)
cd /home/user/project
.show

# Show session with conversation content (default)
.show session_id::abc123

# Show session in different project
.show session_id::abc123 project::/home/user/project

# Metadata only (old behavior)
.show session_id::abc123 metadata::1

# Increase verbosity for metadata footer
.show session_id::abc123 verbosity::2
```

**Content Format**:
```text
Session: 79f86582... (2893 entries)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

[2025-12-02 09:57] User:
last 3 biig tasks solved in this context?

[2025-12-02 09:57] Assistant:
I'll analyze the recent conversation history...

**Recent Major Tasks Completed:**
1. **tree_fmt Standardization**
2. **Path Filter Bug Investigation**
3. **Test Suite Fixes**

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

### .count

Fast counting operations (projects, sessions, entries).

**Parameters**:
- `target::projects|sessions|entries` (required)
- `project::{id}` (for sessions/entries)
- `session::{id}` (for entries)

**Examples**:
```bash
.count target::projects
.count target::sessions project::-home-user-pro
.count target::entries session::abc123
```

### .search

Search session content for query string.

**Parameters**:
- `query::{text}` (required) - Search query (case-insensitive by default)
- `project::{id}` (optional) - Limit search to specific project
- `session::{id}` (optional) - Limit search to specific session
- `case_sensitive::1` (optional) - Enable case-sensitive matching
- `entry_type::user|assistant` (optional) - Filter by entry type
- `verbosity::N` (0-5, default 1) - Detail level

**Examples**:
```bash
.search query::error
.search query::"session management" case_sensitive::1
.search query::implement project::-home-user-pro
```

### .export

Export session to file (markdown, JSON, or text).

**Parameters**:
- `session_id::{id}` (required) - Session ID to export
- `output::{path}` (required) - Output file path
- `format::markdown|json|text` (optional, default: markdown) - Export format
- `project::{id}` (optional) - Project ID if not in current directory

**Formats**:
- **markdown** (.md) - Human-readable with metadata and formatted entries
- **json** (.json) - Machine-readable structured format
- **text** (.txt) - Simple conversation transcript

**Examples**:
```bash
.export session_id::-default_topic output::conversation.md
.export session_id::abc123 format::json output::session.json
.export session_id::xyz789 format::text output::transcript.txt project::-home-user-pro
```

**Note**: Sessions may contain non-conversation metadata entries (queue-operation, summary) which are automatically skipped during export. Only conversation entries (user/assistant messages) are included in the exported output.

### .session

Check if a directory has Claude Code conversation history.

**Parameters**:
- `path::{value}` (optional, default: current directory) - Directory to check

**Examples**:
```bash
# Check current directory
.session

# Check specific directory
.session path::/home/user/project
```

### .sessions

Show active-session summary by default, or list sessions with scope control when any explicit parameter is given (session-first view).

**Scope semantics**:

| Scope | Project qualifies when |
|-------|----------------------|
| `local` | project path == base path |
| `relevant` | base path is under the project path (ancestor) |
| `under` | project path is under the base path (subtree) (default) |
| `global` | all projects regardless of path |

**Parameters**:
- `scope::{local|relevant|under|global}` (optional, default: `under`) - Discovery scope
- `path::{value}` (optional, default: cwd) - Base path for scope resolution
- `session::{substring}` (optional) - Filter by session ID substring
- `agent::{0|1}` (optional) - Filter by type (0=main only, 1=agent only)
- `min_entries::N` (optional) - Minimum entry count threshold
- `verbosity::N` (0-5, default: 1) - Output detail level

**Default output (summary mode)**:
```text
Active session  {8-char-id}  {age}  {N} entries
Project  {rel-path}

Last message:
  {text or first30...last30 if > 50 chars}
```
`No active session found.` when scope has no sessions.

**List output (any explicit parameter given)**:
- verbosity 0: raw session IDs (one per line)
- verbosity 1: family-grouped list with path headers (default); agents shown as `[N agents: N×Type]` per root
- verbosity 2+: full UUIDs, agents tree-indented under their parent session

**Examples**:
```bash
# Active session summary (default — no args)
.sessions

# Sessions for all projects under ~/pro
.sessions scope::under path::~/pro

# All sessions across entire storage
.sessions scope::global

# All agent sessions with 50+ entries
.sessions scope::global agent::1 min_entries::50
```

## scripting integration

**Exit codes**:
- 0: Success
- 1: Error

**Examples**:
```bash
# Get project count
PROJECT_COUNT=$(cargo run --features cli -- .count target::projects | grep -oP '\d+')

# Check if session exists
if cargo run --features cli -- .show session::abc123 &>/dev/null; then
  echo "Session exists"
fi

# Export statistics
cargo run --features cli -- .status verbosity::3 > storage_stats.txt
```

## library api

For programmatic access to Claude Code storage, use `claude_storage_core` directly:

```toml
[dependencies]
claude_storage_core = "1.0.0"
# Or for local development:
# claude_storage_core = { path = "../claude_storage_core" }
```

```rust,no_run
use claude_storage_core::{ Storage, ProjectId };

fn main() -> claude_storage_core::Result< () >
{
  let storage = Storage::new()?;
  for project in storage.list_projects()?
  {
    println!( "Project: {:?}", project.id() );
  }
  Ok( () )
}
```

## architecture

**Dependencies**:
- `claude_storage_core` - Core library for all storage operations
- `unilang` - CLI framework for command parsing
- `phf` - Perfect hash functions for static command registry

**Build system**:
- `build.rs` - Transforms YAML command definitions to static PHF registry
- `unilang.commands.yaml` - Command definitions (9 commands)
- Generated code: Static command map with O(1) lookup

**Command routines** (`src/cli/mod.rs`):
- `status_routine` - Global statistics aggregation
- `list_routine` - Filtered listing
- `show_routine` - Session detail display
- `show_project_routine` - Project detail display
- `count_routine` - Fast counting
- `search_routine` - Content search
- `export_routine` - Session export
- `session_routine` - Directory session check
- `sessions_routine` - Scoped session listing

## documentation

- **Documentation**: `docs/` - Behavioral requirements, CLI reference, feature docs (see `docs/entities.md` for index)
- **Migration guide**: `docs/MIGRATION.md` - Migration from monolithic crate
- **Format docs**: `docs/` - Storage organization, file formats, advanced topics
- **Integration guide**: `docs/integration_guide.md` - Library integration examples

## testing

**Core library tests**: 105 tests in `claude_storage_core` crate
- Entry parsing and validation
- Path encoding/decoding
- JSON parser
- Filtering system
- Content search
- Export functionality (markdown, JSON, text)
- Statistics aggregation
- Bug reproducers with comprehensive documentation

**CLI tests**: 17 integration tests
- Storage operations tests (global stats, project listing)
- Session operations tests (show, stats, entry counts)
- Counting operations tests (projects, sessions, entries)
- Full workflow integration test
- CLI sanity tests (build, features)

## license

MIT