session-search

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Session Search

会话搜索

Search Claude Code session transcripts by combining keyword pre-filtering with semantic evaluation. Finds previous sessions about specific topics, debugging conversations, research tasks, or any past work.
通过结合关键词预过滤与语义评估来搜索Claude Code会话记录。查找与特定主题、调试对话、研究任务或任何过往工作相关的历史会话。

Workflow

工作流程

Step 1: Run the search script

步骤1:运行搜索脚本

Execute
scripts/search.py
with the user's query:
bash
python3 scripts/search.py "<query>" [max_results] [max_age_days]
  • query
    (required): Natural language search query
  • max_results
    (optional, default 10): Maximum results to return
  • max_age_days
    (optional, default 90): How far back to search
The script performs keyword pre-filtering across all sessions, then extracts meaningful excerpts from top candidates. Output contains a
SESSIONS_DATA
JSON block.
使用用户查询执行
scripts/search.py
bash
python3 scripts/search.py "<query>" [max_results] [max_age_days]
  • query
    (必填):自然语言搜索查询
  • max_results
    (可选,默认值10):返回的最大结果数
  • max_age_days
    (可选,默认值90):搜索的时间范围(回溯天数)
该脚本会对所有会话进行关键词预过滤,然后从候选结果中提取有意义的片段。输出包含一个
SESSIONS_DATA
JSON块。

Step 2: Evaluate results semantically

步骤2:语义评估结果

After receiving the script output, evaluate each session's relevance to the query. Consider:
  • Synonym matching: "bug" matches "error", "issue", "problem", "fix"
  • Related concepts: "debugging" matches sessions with test failures or error messages
  • Tool patterns: "refactoring" matches Edit-heavy sessions
  • Domain context: "obsidian" matches vault-related work
Assign a relevance score (0-10) to each session based on excerpt content and query intent.
收到脚本输出后,评估每个会话与查询的相关性,需考虑:
  • 同义词匹配:“bug”匹配“error”、“issue”、“problem”、“fix”
  • 相关概念:“debugging”匹配包含测试失败或错误消息的会话
  • 工具模式:“refactoring”匹配以编辑操作为主的会话
  • 领域上下文:“obsidian”匹配与vault相关的工作
根据片段内容和查询意图,为每个会话分配0-10的相关性评分。

Step 3: Present results

步骤3:展示结果

Display the top results (up to
max_results
) sorted by relevance, formatted as:
undefined
按相关性排序显示排名靠前的结果(最多
max_results
个),格式如下:
undefined

[Relevance: N/10] Project — Date

[相关性:N/10] 项目 — 日期

Summary of what the session was about (1-2 sentences based on excerpts)
claude --resume <session-id>

If no relevant results are found, report that and suggest alternative queries.
会话内容摘要(基于片段的1-2句话)
claude --resume <session-id>

如果未找到相关结果,需告知用户并建议替代查询。

Session Storage

会话存储

Sessions are stored as JSONL files in
~/.claude/projects/
. Each file contains events with user/assistant messages and tool calls. The search script handles file discovery and text extraction automatically.
会话以JSONL文件形式存储在
~/.claude/projects/
目录下。每个文件包含用户/助手消息及工具调用事件。搜索脚本会自动处理文件发现和文本提取。

Customization

自定义设置

To search older sessions or get more results:
/session-search "query" 20 180
(20 results, 180 days lookback)
如需搜索更早的会话或获取更多结果:
/session-search "query" 20 180
(返回20条结果,回溯180天)