From b27d93727d9251d65a6f46bbff8145252e741210 Mon Sep 17 00:00:00 2001 From: Kaan Barmore-Genc Date: Sun, 7 Jun 2026 14:22:00 -0500 Subject: [PATCH] Add cc-query-chat skill for searching past sessions Companion to cc-compact: resolves a session by id or name, then searches across user prompts, agent replies, commands, file ops, tool calls, and tool output via regexp, glob, or ranked keyword matching. Bounded output (centred snippets, --limit/--truncate tuned to ~2k tokens). cc-compact now points to it for closing concrete gaps the compact report leaves open. --- claude/skills/cc-compact/SKILL.md | 15 + claude/skills/cc-query-chat/SKILL.md | 81 ++++ claude/skills/cc-query-chat/query_session.py | 443 +++++++++++++++++++ 3 files changed, 539 insertions(+) create mode 100644 claude/skills/cc-query-chat/SKILL.md create mode 100755 claude/skills/cc-query-chat/query_session.py diff --git a/claude/skills/cc-compact/SKILL.md b/claude/skills/cc-compact/SKILL.md index 9cd2872..4a29fe4 100644 --- a/claude/skills/cc-compact/SKILL.md +++ b/claude/skills/cc-compact/SKILL.md @@ -62,3 +62,18 @@ diving in, decide whether you actually know how to proceed: before acting. Surface the few plausible next steps you inferred and let them pick or correct you. If there is any doubt, opt to ask the user first. +## If the compact report left something unclear + +Compaction is lossy. If — and **only if absolutely necessary** — a specific +detail you need to proceed is missing or ambiguous (an exact command that ran, +a file path, what a tool returned, the precise wording of an earlier request), +search the full session with the companion **cc-query-chat** skill instead of +reading the raw log: + +```sh +python3 ~/.claude/skills/cc-query-chat/query_session.py --chat '' --keyword 'the detail you need' +``` + +The compact report is meant to stand on its own — reach for this only to close a +concrete gap, never to re-read the session. + diff --git a/claude/skills/cc-query-chat/SKILL.md b/claude/skills/cc-query-chat/SKILL.md new file mode 100644 index 0000000..641c2b1 --- /dev/null +++ b/claude/skills/cc-query-chat/SKILL.md @@ -0,0 +1,81 @@ +--- +name: cc-query-chat +description: Search a past Claude Code session by id or name — across prompts, replies, commands, files, and tool output — via regexp, glob, or ranked keyword. +--- + +You are searching a previous Claude Code session for specific information, +without reading its whole history. The bundled helper script resolves the +session, walks it once, and prints only the matching items. + +**Hard rule: you may NOT read the session `.jsonl` file by any means** — no +`cat`, `head`, `tail`, `jq`, `grep`, `Read`, nothing. Run the helper script and +work solely from its output. That is the only thing allowed to touch the file. + +The helper lives at `~/.claude/skills/cc-query-chat/query_session.py`. + +## Step 1: Resolve the session + +The session is identified by id or name, passed via `--chat`: + +It auto-detects whether the parameter is a UUID or title. +Titles are case insensitive matched. +If you already know it's a title vs an id, `--title`/`--id`/`--file` also work. + +## Step 2: Choose a matching scheme + +Exactly one of these is required: + +- **`--regexp PATTERN`** — Python regex, searched anywhere in each item. + Exact filter: an item either matches or it doesn't. + ```sh + ... --chat '' --regexp 'ab.*c' + ``` +- **`--glob PATTERN`** — shell glob (`*`, `?`, `[..]`), searched anywhere in + each item. Exact filter. + ```sh + ... --chat '' --glob 'ab*c' + ``` +- **`--keyword "WORDS"`** — space-separated keywords with partial (substring) + matches. Results are **ranked**: the more distinct keywords an item matches + the higher it scores (ties broken by total hit count), best first. + ```sh + ... --chat '' --keyword 'data pipeline error delivery' + ``` + +regexp and glob are case-insensitive by default (pass `--case-sensitive` to +change that); keyword is always case-insensitive. + +## Step 3: Narrow and shape the results + +- **`--type LIST`** — restrict to item types (comma-separated). Types: + - `user` — the human's prompts + - `agent` — the assistant's text replies + - `command` — Bash commands (command + description) + - `file` — file operations (Read/Write/Edit/NotebookEdit): path + content + - `tool` — other tool calls (name + input) + - `output` — tool results: command output, file contents read back, etc. + + e.g. `--type command,output` to search only what was run and what it printed. + +- **`--limit N`** — max results (default 5). +- **`--truncate N`** — max chars of matched text per result; the shown snippet + is centred on the match. + +The defaults are tuned so that output is short enough to note pollute context. +Do not raise them without good reason. If raising `truncate`, you might want to lower `limit` and vice versa. + +## Step 4: Read the output + +It prints an XML-tagged report: a header with how many items were searched and +matched, then one `` per hit with its `type`, `turn` number, timestamp, +keyword score (for keyword mode), a `