cogpit-memory 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  CLI tool that gives any AI assistant memory of past [Claude Code](https://docs.anthropic.com/en/docs/claude-code) sessions. Retrieve conversation history, tool usage, thinking blocks, sub-agent activity, and full-text search across all sessions.
4
4
 
5
+ All output is JSON to stdout — designed for programmatic consumption by AI agents.
6
+
5
7
  ## Install
6
8
 
7
9
  ```bash
@@ -35,17 +37,10 @@ cogpit-memory search "authentication"
35
37
  ### `sessions` — Discover sessions
36
38
 
37
39
  ```bash
38
- # Recent sessions (last 7 days)
39
- cogpit-memory sessions
40
-
41
- # Filter by project directory
42
- cogpit-memory sessions --cwd /path/to/project
43
-
44
- # Get most recent session for a directory
45
- cogpit-memory sessions --current --cwd /path/to/project
46
-
47
- # Custom time window and limit
48
- cogpit-memory sessions --max-age 30d --limit 50
40
+ cogpit-memory sessions # Recent sessions (last 7 days)
41
+ cogpit-memory sessions --cwd /path/to/project # Filter by project
42
+ cogpit-memory sessions --current --cwd /path/to/project # Most recent for a project
43
+ cogpit-memory sessions --max-age 30d --limit 50 # Custom window
49
44
  ```
50
45
 
51
46
  | Flag | Default | Description |
@@ -55,50 +50,28 @@ cogpit-memory sessions --max-age 30d --limit 50
55
50
  | `--max-age` | `7d` | Time window (`7d`, `12h`, `30d`) |
56
51
  | `--current` | — | Most recent session for `--cwd` |
57
52
 
58
- ### `context` — Browse session content (layered)
53
+ ### `context` — Layered session drill-down
59
54
 
60
- Three layers of detail start at L1, drill down as needed.
61
-
62
- **Layer 1 — Session overview** (always start here):
63
-
64
- ```bash
65
- cogpit-memory context <sessionId>
66
- ```
55
+ Three layers of detail. Start at L1, drill down only as needed.
67
56
 
68
- Returns every turn with user prompt, assistant reply, tool usage summary, and sub-agent list.
69
-
70
- **Layer 2 Turn detail:**
71
-
72
- ```bash
73
- cogpit-memory context <sessionId> --turn 3
74
- ```
75
-
76
- Returns thinking blocks, full tool call inputs/outputs, and sub-agent summaries in chronological order.
77
-
78
- **Layer 3 — Sub-agent detail:**
79
-
80
- ```bash
81
- # Sub-agent overview (same shape as L1)
82
- cogpit-memory context <sessionId> --agent <agentId>
57
+ | Layer | Command | What you get |
58
+ |-------|---------|-------------|
59
+ | **L1**Overview | `cogpit-memory context <sessionId>` | Every turn: user prompt, assistant reply, tool summary, sub-agent list |
60
+ | **L2** — Turn detail | `cogpit-memory context <sessionId> --turn 3` | Thinking blocks, full tool call I/O, sub-agent summaries (chronological) |
61
+ | **L3** — Sub-agent | `cogpit-memory context <sessionId> --agent <agentId>` | Full sub-agent conversation (same shape as L1) |
62
+ | **L3** — Sub-agent turn | `cogpit-memory context <sessionId> --agent <agentId> --turn 0` | Sub-agent turn detail (same shape as L2) |
83
63
 
84
- # Sub-agent turn detail (same shape as L2)
85
- cogpit-memory context <sessionId> --agent <agentId> --turn 0
86
- ```
64
+ **Discovery flow:** L1 gives you `turnIndex` and `agentId` values → use those to drill into L2/L3.
87
65
 
88
66
  ### `search` — Full-text search with FTS5
89
67
 
90
- ```bash
91
- # Search across all recent sessions
92
- cogpit-memory search "authentication"
93
-
94
- # Scope to a single session
95
- cogpit-memory search "auth" --session <sessionId>
96
-
97
- # Custom time window
98
- cogpit-memory search "bug" --max-age 30d --limit 50
68
+ Searches everything: user messages, assistant responses, thinking blocks, tool call inputs/outputs, sub-agent content, and compaction summaries.
99
69
 
100
- # Case-sensitive
101
- cogpit-memory search "AuthProvider" --case-sensitive
70
+ ```bash
71
+ cogpit-memory search "authentication" # Cross-session search
72
+ cogpit-memory search "auth" --session <sessionId> # Single session
73
+ cogpit-memory search "bug" --max-age 30d --limit 50 # Custom window
74
+ cogpit-memory search "AuthProvider" --case-sensitive # Case-sensitive
102
75
  ```
103
76
 
104
77
  | Flag | Default | Description |
@@ -108,31 +81,51 @@ cogpit-memory search "AuthProvider" --case-sensitive
108
81
  | `--limit` | `20` | Max returned hits |
109
82
  | `--case-sensitive` | `false` | Case sensitivity |
110
83
 
111
- Searches everything: user messages, assistant responses, thinking blocks, tool call inputs/outputs, sub-agent content, and compaction summaries.
84
+ Each hit includes a `location` string (e.g. `turn/3/assistantMessage`, `agent/a7f3bc2/toolCall/tc1/result`) that maps directly to L2/L3 drill-down commands.
112
85
 
113
86
  ### `index` — Manage the FTS5 search index
114
87
 
115
88
  ```bash
116
- cogpit-memory index stats # Show index stats
89
+ cogpit-memory index stats # Show index stats (session count, DB size, staleness)
117
90
  cogpit-memory index rebuild # Rebuild from scratch
118
91
  ```
119
92
 
120
- ## Output
93
+ ## Performance
94
+
95
+ Benchmarked against a real Claude Code history: **765 sessions, 1,745 sub-agents, 210K indexed rows, 1.4 GB index**.
96
+
97
+ | Operation | Time | Notes |
98
+ |-----------|------|-------|
99
+ | `sessions --limit 20` | **38ms** | File-system scan, no DB needed |
100
+ | `context <sessionId>` (L1) | **34ms** | Single JSONL file parse |
101
+ | `context <sessionId> --turn N` (L2) | **35ms** | Same file, filtered to one turn |
102
+ | `search "keyword"` (cross-session) | **56–200ms** | FTS5 trigram across 210K rows |
103
+ | `search "keyword" --session <id>` | **30ms** | Scoped to single session |
104
+ | `index stats` | **50ms** | Single DB query |
121
105
 
122
- All output is JSON to stdout, designed for programmatic consumption by AI agents.
106
+ ### Scaling characteristics
107
+
108
+ | History size | Sessions | Indexed rows | DB size | Cross-session search |
109
+ |-------------|----------|-------------|---------|---------------------|
110
+ | Light (3 months) | ~200 | ~50K | ~350 MB | <50ms |
111
+ | Moderate (6 months) | ~800 | ~210K | ~1.4 GB | 50–200ms |
112
+ | Heavy (1 year) | ~2,000 | ~500K | ~3.5 GB | 100–400ms |
113
+ | Power user (2+ years) | ~5,000 | ~1.2M | ~8 GB | 200–800ms |
114
+
115
+ FTS5 trigram search is sublinear — doubling the index size does not double query time. The index uses SQLite WAL mode for concurrent reads and is incrementally updated.
123
116
 
124
117
  ## How It Works
125
118
 
126
- cogpit-memory reads Claude Code's JSONL session files from `~/.claude/projects/`. It parses the conversation structure and provides a layered drill-down interface.
119
+ cogpit-memory reads Claude Code's JSONL session files from `~/.claude/projects/`. It parses the conversation structure (turns, tool calls, thinking blocks, sub-agents) and provides a layered drill-down interface.
127
120
 
128
- For search, it maintains an FTS5 trigram index at `~/.claude/cogpit-memory/search-index.db` for fast full-text search across all sessions.
121
+ For search, it maintains an FTS5 trigram index at `~/.claude/cogpit-memory/search-index.db`. The trigram tokenizer enables substring matching (not just whole-word) searching for `"auth"` matches `"authentication"`, `"OAuth"`, and `"AuthProvider"`.
129
122
 
130
123
  ## Development
131
124
 
132
- Requires [Bun](https://bun.sh) for development (source uses `bun:sqlite`). The npm build uses `better-sqlite3` for Node.js compatibility.
125
+ Requires [Bun](https://bun.sh) for development (source uses `bun:sqlite`). The npm build uses `better-sqlite3` for Node.js compatibility via an esbuild alias.
133
126
 
134
127
  ```bash
135
- # Run tests
128
+ # Run tests (82 tests)
136
129
  bun test
137
130
 
138
131
  # Build compiled binary (Bun, uses bun:sqlite)
@@ -142,6 +135,20 @@ bun run build
142
135
  bun run build:npm
143
136
  ```
144
137
 
138
+ ## Claude Code Skill
139
+
140
+ cogpit-memory ships with a [Claude Code skill](https://docs.anthropic.com/en/docs/claude-code/skills) that teaches Claude how to use it automatically — layered drill-down, search workflows, and all command options.
141
+
142
+ ```bash
143
+ # Install the skill into the current project
144
+ npx cogpit-memory install-skill
145
+
146
+ # Or specify a project directory
147
+ npx cogpit-memory install-skill --cwd /path/to/project
148
+ ```
149
+
150
+ This creates `.claude/skills/cogpit-memory/SKILL.md` in your project. Once installed, Claude Code will automatically use `cogpit-memory` when it needs to recall past session context or search conversation history.
151
+
145
152
  ## License
146
153
 
147
154
  MIT
package/dist/cli.js CHANGED
@@ -2064,6 +2064,43 @@ async function indexRebuild(dbPath) {
2064
2064
  return { status: "rebuilt", stats };
2065
2065
  }
2066
2066
 
2067
+ // src/commands/install-skill.ts
2068
+ var import_node_fs4 = require("node:fs");
2069
+ var import_node_path8 = require("node:path");
2070
+ var import_node_url = require("node:url");
2071
+ var import_meta = {};
2072
+ function findSkillContent() {
2073
+ const candidates = [];
2074
+ if (typeof __dirname !== "undefined") {
2075
+ candidates.push((0, import_node_path8.join)(__dirname, "..", "skill", "SKILL.md"));
2076
+ candidates.push((0, import_node_path8.join)(__dirname, "..", "..", "skill", "SKILL.md"));
2077
+ }
2078
+ try {
2079
+ const thisDir = (0, import_node_path8.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
2080
+ candidates.push((0, import_node_path8.join)(thisDir, "..", "skill", "SKILL.md"));
2081
+ candidates.push((0, import_node_path8.join)(thisDir, "..", "..", "skill", "SKILL.md"));
2082
+ } catch {
2083
+ }
2084
+ for (const candidate of candidates) {
2085
+ try {
2086
+ if ((0, import_node_fs4.existsSync)(candidate)) {
2087
+ return (0, import_node_fs4.readFileSync)(candidate, "utf-8");
2088
+ }
2089
+ } catch {
2090
+ }
2091
+ }
2092
+ throw new Error("Could not find SKILL.md \u2014 try reinstalling cogpit-memory");
2093
+ }
2094
+ function installSkill(cwd) {
2095
+ const root = cwd ?? process.cwd();
2096
+ const skillDir = (0, import_node_path8.join)(root, ".claude", "skills", "cogpit-memory");
2097
+ (0, import_node_fs4.mkdirSync)(skillDir, { recursive: true });
2098
+ const content = findSkillContent();
2099
+ const dest = (0, import_node_path8.join)(skillDir, "SKILL.md");
2100
+ (0, import_node_fs4.writeFileSync)(dest, content);
2101
+ return { installed: true, path: skillDir };
2102
+ }
2103
+
2067
2104
  // src/cli.ts
2068
2105
  function parseArgs(argv) {
2069
2106
  const command = argv[0];
@@ -2126,6 +2163,16 @@ function parseArgs(argv) {
2126
2163
  args.subcommand = argv[1] ?? "stats";
2127
2164
  break;
2128
2165
  }
2166
+ case "install-skill": {
2167
+ for (let i = 1; i < argv.length; i++) {
2168
+ switch (argv[i]) {
2169
+ case "--cwd":
2170
+ args.cwd = argv[++i];
2171
+ break;
2172
+ }
2173
+ }
2174
+ break;
2175
+ }
2129
2176
  }
2130
2177
  return { command, args };
2131
2178
  }
@@ -2183,6 +2230,9 @@ async function main() {
2183
2230
  result = await indexStats();
2184
2231
  }
2185
2232
  break;
2233
+ case "install-skill":
2234
+ result = installSkill(cmd.args.cwd);
2235
+ break;
2186
2236
  default:
2187
2237
  console.error(JSON.stringify({ error: `Unknown command: ${cmd.command}` }));
2188
2238
  printUsage();
@@ -2212,11 +2262,14 @@ Commands:
2212
2262
 
2213
2263
  index stats Show index stats
2214
2264
  index rebuild Rebuild full index
2265
+
2266
+ install-skill [--cwd path] Install Claude Code skill to .claude/skills/
2215
2267
  `);
2216
2268
  }
2217
2269
  var isBunCompiled = false;
2218
- var isScript = process.argv[1]?.endsWith("/cli.ts") || process.argv[1]?.endsWith("/cli.js") || process.argv[1]?.endsWith("/cli.cjs");
2219
- if (isBunCompiled || isScript) {
2270
+ var isNodeScript = process.argv[1]?.endsWith("/cli.ts") || process.argv[1]?.endsWith("/cli.js");
2271
+ var isCjsMain = typeof require !== "undefined" && typeof module !== "undefined" && require.main === module;
2272
+ if (isBunCompiled || isNodeScript || isCjsMain) {
2220
2273
  main().catch((err) => {
2221
2274
  console.error(JSON.stringify({ error: String(err) }));
2222
2275
  process.exit(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cogpit-memory",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "CLI tool for Claude Code session introspection — search, browse, and drill into past sessions",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./src/index.ts",
@@ -8,7 +8,8 @@
8
8
  "cogpit-memory": "./dist/cli.js"
9
9
  },
10
10
  "files": [
11
- "dist/"
11
+ "dist/",
12
+ "skill/"
12
13
  ],
13
14
  "scripts": {
14
15
  "test": "bun test",
package/skill/SKILL.md ADDED
@@ -0,0 +1,342 @@
1
+ ---
2
+ name: cogpit-memory
3
+ description: CLI tool for Claude Code session introspection -- retrieves conversation history, tool calls, thinking, sub-agent/team activity, full-text search, and session discovery. All output is JSON to stdout.
4
+ ---
5
+
6
+ # Cogpit Memory -- Session Context CLI
7
+
8
+ CLI tool that gives any AI assistant memory of past Claude Code sessions. Retrieve conversation history, tool usage, thinking, and sub-agent activity via a layered command structure. **Also supports full-text search across all sessions** and session discovery/listing.
9
+
10
+ Always start with session discovery or the overview (Layer 1), and drill into specific turns or sub-agents only as needed. Use search when you need to **find** content rather than browse known sessions.
11
+
12
+ **Prerequisite:** Bun must be installed (uses bun:sqlite for FTS5 search).
13
+
14
+ ## Step 1 -- Verify the tool works
15
+
16
+ ```bash
17
+ bunx cogpit-memory --help
18
+ ```
19
+
20
+ If this prints usage info, proceed to Step 2. If `bunx` is not available, install the package globally:
21
+
22
+ ```bash
23
+ npm install -g cogpit-memory
24
+ ```
25
+
26
+ Then use `cogpit-memory` directly instead of `bunx cogpit-memory`.
27
+
28
+ ## Step 2 -- Find sessions
29
+
30
+ ### List recent sessions
31
+
32
+ ```bash
33
+ # List recent sessions (default: last 7 days, up to 20 results)
34
+ bunx cogpit-memory sessions
35
+
36
+ # Filter by working directory
37
+ bunx cogpit-memory sessions --cwd /path/to/project
38
+
39
+ # Customize limit and time window
40
+ bunx cogpit-memory sessions --limit 50 --max-age 30d
41
+ ```
42
+
43
+ Options:
44
+
45
+ | Flag | Default | Description |
46
+ |------|---------|-------------|
47
+ | `--limit` | `20` | Max results |
48
+ | `--max-age` | `7d` | Time window: `7d`, `12h`, `30d` |
49
+ | `--cwd` | all | Filter by working directory |
50
+
51
+ Response: array of session summaries with `sessionId`, `cwd`, `model`, `firstMessage`, `lastMessage`, `turnCount`, `status`, `mtime`.
52
+
53
+ ### Get current session for a directory
54
+
55
+ ```bash
56
+ bunx cogpit-memory sessions --current --cwd /path/to/project
57
+ ```
58
+
59
+ Returns the most recently active session for the given working directory. The `--cwd` flag is required when using `--current` (defaults to the current working directory if omitted).
60
+
61
+ ## Step 3 -- Layer 1: Get session overview (ALWAYS call this first)
62
+
63
+ This gives you every user prompt and AI reply, plus a tool usage summary per turn. **You must call this before Layer 2 or Layer 3** -- it provides the `turnIndex` and `agentId` values you need for drill-downs.
64
+
65
+ ```bash
66
+ bunx cogpit-memory context <SESSION_ID>
67
+ ```
68
+
69
+ Response shape:
70
+ ```json
71
+ {
72
+ "sessionId": "abc-123",
73
+ "cwd": "/path/to/project",
74
+ "model": "claude-opus-4-6",
75
+ "branchedFrom": null,
76
+ "compacted": false,
77
+ "turns": [
78
+ {
79
+ "turnIndex": 0,
80
+ "userMessage": "Fix the auth bug",
81
+ "assistantMessage": "I found the issue...",
82
+ "toolSummary": { "Edit": 2, "Read": 3 },
83
+ "subAgents": [
84
+ {
85
+ "agentId": "a7f3bc2",
86
+ "name": "researcher",
87
+ "type": "Explore",
88
+ "status": "success",
89
+ "durationMs": 12300,
90
+ "toolUseCount": 8,
91
+ "isBackground": false
92
+ }
93
+ ],
94
+ "hasThinking": true,
95
+ "isError": false,
96
+ "compactionSummary": null
97
+ }
98
+ ],
99
+ "stats": {
100
+ "totalTurns": 5,
101
+ "totalToolCalls": 23,
102
+ "totalTokens": { "input": 45000, "output": 12000 }
103
+ }
104
+ }
105
+ ```
106
+
107
+ Key fields:
108
+ - `userMessage` -- the human's full prompt text (`null` for synthetic turns, images shown as `[image attached]`)
109
+ - `assistantMessage` -- the AI's full text response (`null` if only tools ran)
110
+ - `toolSummary` -- tool name to count (e.g., `{"Read": 5, "Edit": 2}`)
111
+ - `subAgents` -- summary of sub-agents that ran in this turn. Fields `status`, `durationMs`, `toolUseCount` may be `null` for older sessions
112
+ - `hasThinking` -- whether thinking blocks exist (boolean only; full text is in Layer 2)
113
+ - `compacted` -- `true` if the session was compacted (early context compressed)
114
+
115
+ ## Step 4 -- Layer 2: Get turn detail (one turn at a time)
116
+
117
+ Use this to drill into a specific turn. Get thinking, full tool call inputs/outputs, and sub-agent summaries in chronological order.
118
+
119
+ ```bash
120
+ bunx cogpit-memory context <SESSION_ID> --turn <TURN_INDEX>
121
+ ```
122
+
123
+ Response shape:
124
+ ```json
125
+ {
126
+ "sessionId": "abc-123",
127
+ "turnIndex": 0,
128
+ "userMessage": "Fix the auth bug",
129
+ "contentBlocks": [
130
+ { "kind": "thinking", "text": "Let me analyze...", "timestamp": "..." },
131
+ { "kind": "text", "text": "I found the issue.", "timestamp": "..." },
132
+ {
133
+ "kind": "tool_calls",
134
+ "toolCalls": [
135
+ { "id": "tc1", "name": "Edit", "input": { "file_path": "/a.ts" }, "result": "done", "resultTruncated": false, "isError": false }
136
+ ],
137
+ "timestamp": "..."
138
+ },
139
+ {
140
+ "kind": "sub_agent",
141
+ "agents": [
142
+ { "agentId": "a7f3bc2", "name": "researcher", "type": "Explore", "prompt": "Find auth files", "resultText": "Found 3 files...", "status": "success", "durationMs": 12300, "toolUseCount": 8, "isBackground": false }
143
+ ],
144
+ "timestamp": "..."
145
+ }
146
+ ],
147
+ "tokenUsage": { "input": 8000, "output": 2500 },
148
+ "model": "claude-opus-4-6",
149
+ "durationMs": 15000
150
+ }
151
+ ```
152
+
153
+ Key details:
154
+ - `contentBlocks` kinds: `thinking`, `text`, `tool_calls`, `sub_agent`, `background_agent`
155
+ - Tool call `result` is truncated at 10,000 chars -- check `resultTruncated: true`
156
+ - Tool call `result` may be `null` if the tool hasn't returned yet
157
+ - Sub-agent blocks show prompt + result text. For full sub-agent conversation, use Layer 3
158
+
159
+ **Make separate requests per turn** -- do not try to batch multiple turns in one call.
160
+
161
+ ## Step 5 -- Layer 3: Get sub-agent / team member detail
162
+
163
+ Drill into a specific sub-agent's full conversation. Returns the same shape as Layer 1 (an overview of the sub-agent's own turns).
164
+
165
+ ```bash
166
+ bunx cogpit-memory context <SESSION_ID> --agent <AGENT_ID>
167
+ ```
168
+
169
+ Get the `AGENT_ID` from Layer 1's `subAgents[].agentId` field.
170
+
171
+ Response shape:
172
+ ```json
173
+ {
174
+ "sessionId": "abc-123",
175
+ "agentId": "a7f3bc2",
176
+ "name": "researcher",
177
+ "type": "Explore",
178
+ "parentToolCallId": "tc5",
179
+ "isBackground": false,
180
+ "teamContext": null,
181
+ "overview": {
182
+ "turns": [ "..." ],
183
+ "stats": { "..." }
184
+ }
185
+ }
186
+ ```
187
+
188
+ The `overview` field has the exact same shape as Layer 1. You can then drill into specific sub-agent turns:
189
+
190
+ ```bash
191
+ bunx cogpit-memory context <SESSION_ID> --agent <AGENT_ID> --turn <TURN_INDEX>
192
+ ```
193
+
194
+ This returns the same shape as Layer 2.
195
+
196
+ ### Team context
197
+
198
+ If the sub-agent is a team member, `teamContext` will be populated:
199
+ ```json
200
+ {
201
+ "teamContext": {
202
+ "teamName": "admin-ui-redesign",
203
+ "role": "layout-dev",
204
+ "currentTask": { "id": "3", "subject": "Redesign layout.tsx", "status": "in_progress" }
205
+ }
206
+ }
207
+ ```
208
+
209
+ **Note:** Team members using `tmux` backend are not accessible via this command (they run as separate sessions).
210
+
211
+ ## Discovery chain
212
+
213
+ The typical workflow for drilling into sub-agent activity:
214
+
215
+ 1. Call Layer 1 to get the session overview
216
+ 2. Look at `turns[].subAgents[]` to find agent IDs
217
+ 3. Call Layer 3 with the `--agent` flag to get that sub-agent's overview
218
+ 4. Call Layer 3 + `--turn` to drill into a specific sub-agent turn
219
+ 5. If the sub-agent itself had sub-agents, repeat from step 2 using the sub-agent's overview
220
+
221
+ ## Session Search -- Find keywords across sessions
222
+
223
+ Search for keywords across all sessions or within a specific session. Searches **everything**: user messages, assistant responses, thinking blocks, tool call inputs/results, sub-agent messages, sub-agent tool calls, and compaction summaries.
224
+
225
+ **When to use search vs Layer 1:**
226
+ - You know the session -> Use Layer 1 overview, then drill with Layer 2/3
227
+ - You need to **find** which session discussed something -> Use search first, then drill into hits
228
+
229
+ ### Basic usage
230
+
231
+ ```bash
232
+ # Search across all recent sessions (last 5 days)
233
+ bunx cogpit-memory search "authentication"
234
+
235
+ # Search within a specific session
236
+ bunx cogpit-memory search "authentication" --session <SESSION_ID>
237
+
238
+ # Search with custom time window and more results
239
+ bunx cogpit-memory search "authentication" --max-age 30d --limit 50
240
+
241
+ # Case-sensitive search
242
+ bunx cogpit-memory search "AuthProvider" --case-sensitive
243
+ ```
244
+
245
+ ### Options
246
+
247
+ | Flag | Default | Description |
248
+ |------|---------|-------------|
249
+ | `--session` | all sessions | Scope to single session |
250
+ | `--max-age` | `5d` | Time window: `5d`, `12h`, `30d` |
251
+ | `--limit` | `20` | Max returned hits |
252
+ | `--case-sensitive` | `false` | Case sensitivity |
253
+
254
+ ### Response shape
255
+
256
+ ```json
257
+ {
258
+ "query": "authentication",
259
+ "totalHits": 47,
260
+ "returnedHits": 20,
261
+ "sessionsSearched": 8,
262
+ "results": [
263
+ {
264
+ "sessionId": "abc-123",
265
+ "hits": [
266
+ {
267
+ "location": "turn/3/userMessage",
268
+ "snippet": "...need to fix the authentication flow before...",
269
+ "matchCount": 2
270
+ },
271
+ {
272
+ "location": "turn/5/toolCall/tc_abc/result",
273
+ "toolName": "Read",
274
+ "snippet": "...export function authentication(req, res)...",
275
+ "matchCount": 1
276
+ },
277
+ {
278
+ "location": "agent/a7f3bc2/turn/1/assistantMessage",
279
+ "agentName": "researcher",
280
+ "snippet": "...found 3 authentication-related files in...",
281
+ "matchCount": 1
282
+ }
283
+ ]
284
+ }
285
+ ]
286
+ }
287
+ ```
288
+
289
+ ### Location format
290
+
291
+ Locations map directly to Layer 2/3 drill-down commands -- use them to fetch full context:
292
+ - `turn/{i}/userMessage` -- user prompt -> drill with `--turn {i}`
293
+ - `turn/{i}/assistantMessage` -- AI response -> drill with `--turn {i}`
294
+ - `turn/{i}/thinking` -- thinking blocks -> drill with `--turn {i}`
295
+ - `turn/{i}/toolCall/{id}/input` -- tool call input -> drill with `--turn {i}`
296
+ - `turn/{i}/toolCall/{id}/result` -- tool call result -> drill with `--turn {i}`
297
+ - `turn/{i}/compactionSummary` -- compaction summary -> drill with `--turn {i}`
298
+ - `agent/{agentId}/...` -- sub-agent content -> drill with `--agent {agentId}` then `--agent {agentId} --turn {i}`
299
+
300
+ ### Typical workflow
301
+
302
+ 1. Search for keyword: `bunx cogpit-memory search "auth"`
303
+ 2. Pick a hit from results (e.g., `sessionId: "abc-123"`, `location: "turn/3/assistantMessage"`)
304
+ 3. Get full turn context: `bunx cogpit-memory context abc-123 --turn 3`
305
+ 4. If hit is in a sub-agent, get agent overview first: `bunx cogpit-memory context abc-123 --agent a7f3bc2`
306
+
307
+ ### Performance notes
308
+
309
+ - Cross-session search uses a raw-text pre-filter -- files that can't match are skipped before expensive parsing
310
+ - Default 5-day window keeps search fast; increase `--max-age` only if needed
311
+ - Single-session search (`--session` flag) is much faster than cross-session
312
+ - Typical cross-session search: ~150 sessions in ~1-2 seconds
313
+
314
+ ## Index management
315
+
316
+ The search index is an FTS5 trigram database at `~/.claude/cogpit-memory/search-index.db`. Most commands work without the index (falling back to raw file scanning), but indexed search is significantly faster.
317
+
318
+ ```bash
319
+ # Show index stats (session count, staleness, DB size)
320
+ bunx cogpit-memory index stats
321
+
322
+ # Rebuild the full index from scratch
323
+ bunx cogpit-memory index rebuild
324
+ ```
325
+
326
+ ## Quick reference
327
+
328
+ | Goal | Command |
329
+ |------|---------|
330
+ | List recent sessions | `bunx cogpit-memory sessions` |
331
+ | Sessions for a directory | `bunx cogpit-memory sessions --cwd <path>` |
332
+ | Current session for a directory | `bunx cogpit-memory sessions --current --cwd <path>` |
333
+ | Session overview (always first) | `bunx cogpit-memory context <sessionId>` |
334
+ | Turn detail | `bunx cogpit-memory context <sessionId> --turn <N>` |
335
+ | Sub-agent overview | `bunx cogpit-memory context <sessionId> --agent <agentId>` |
336
+ | Sub-agent turn detail | `bunx cogpit-memory context <sessionId> --agent <agentId> --turn <N>` |
337
+ | **Search across sessions** | `bunx cogpit-memory search "<query>"` |
338
+ | **Search single session** | `bunx cogpit-memory search "<query>" --session <sessionId>` |
339
+ | Index stats | `bunx cogpit-memory index stats` |
340
+ | Index rebuild | `bunx cogpit-memory index rebuild` |
341
+
342
+ **Default to Layer 1 only. Drill into Layer 2/3 only when you have a specific reason.**