introspect

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Introspect

自省分析

Extract actionable intelligence from Claude Code session logs. Analyze tool usage, reasoning patterns, errors, and conversation flow to improve workflows and debug issues.
从Claude Code会话日志中提取可落地的洞察信息。分析工具使用情况、推理模式、错误及对话流程,以优化工作流并排查问题。

Log File Structure

日志文件结构

~/.claude/
├── history.jsonl                              # Global: all user inputs across projects
├── projects/
│   └── {project-path}/                        # e.g., X--Dev-claude-mods/
│       ├── sessions-index.json                # Session metadata index
│       ├── {session-uuid}.jsonl               # Full session transcript
│       └── agent-{short-id}.jsonl             # Subagent transcripts
~/.claude/
├── history.jsonl                              # 全局:跨项目的所有用户输入
├── projects/
│   └── {project-path}/                        # 示例:X--Dev-claude-mods/
│       ├── sessions-index.json                # 会话元数据索引
│       ├── {session-uuid}.jsonl               # 完整会话记录
│       └── agent-{short-id}.jsonl             # 子Agent会话记录

Project Path Encoding

项目路径编码

Project paths use double-dash encoding:
X:\Dev\claude-mods
X--Dev-claude-mods
bash
undefined
项目路径使用双短横线编码:
X:\Dev\claude-mods
X--Dev-claude-mods
bash
undefined

Find project directory for current path

查找当前路径对应的项目目录

project_dir=$(pwd | sed 's/[:\/]/-/g' | sed 's/--/-/g') ls ~/.claude/projects/ | grep -i "${project_dir##-}"
undefined
project_dir=$(pwd | sed 's/[:\/]/-/g' | sed 's/--/-/g') ls ~/.claude/projects/ | grep -i "${project_dir##-}"
undefined

Entry Types in Session Files

会话文件中的条目类型

TypeContainsKey Fields
user
User messages
message.content
,
uuid
,
timestamp
assistant
Claude responses
message.content[]
,
cwd
,
gitBranch
thinking
Reasoning blocks
thinking
,
signature
(in content array)
tool_use
Tool invocations
name
,
input
,
id
(in content array)
tool_result
Tool outputs
tool_use_id
,
content
summary
Conversation summaries
summary
,
leafUuid
file-history-snapshot
File state checkpointsFile contents at point in time
system
System contextInitial context, rules
类型包含内容关键字段
user
用户消息
message.content
,
uuid
,
timestamp
assistant
Claude回复
message.content[]
,
cwd
,
gitBranch
thinking
推理思考块
thinking
,
signature
(在content数组中)
tool_use
工具调用记录
name
,
input
,
id
(在content数组中)
tool_result
工具输出结果
tool_use_id
,
content
summary
对话摘要
summary
,
leafUuid
file-history-snapshot
文件状态检查点对应时间点的文件内容
system
系统上下文初始上下文、规则

Core Analysis Patterns

核心分析模式

List Sessions for Current Project

列出当前项目的会话

bash
undefined
bash
undefined

Get sessions index

获取会话索引

cat ~/.claude/projects/X--Dev-claude-mods/sessions-index.json | jq '.'
cat ~/.claude/projects/X--Dev-claude-mods/sessions-index.json | jq '.'

List session files with sizes and dates

列出会话文件及其大小和日期

ls -lah ~/.claude/projects/X--Dev-claude-mods/*.jsonl | grep -v agent
undefined
ls -lah ~/.claude/projects/X--Dev-claude-mods/*.jsonl | grep -v agent
undefined

Session Overview

会话概览

bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"
bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"

Entry type distribution

条目类型分布

jq -r '.type' ~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c
jq -r '.type' ~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c

Session duration (first to last timestamp)

会话时长(从第一条到最后一条的时间戳)

jq -s '[.[].timestamp // .[].message.timestamp | select(.)] | [min, max] | map(. / 1000 | strftime("%Y-%m-%d %H:%M"))'
~/.claude/projects/$PROJECT/$SESSION.jsonl
jq -s '[.[].timestamp // .[].message.timestamp | select(.)] | [min, max] | map(. / 1000 | strftime("%Y-%m-%d %H:%M"))'
~/.claude/projects/$PROJECT/$SESSION.jsonl

Conversation summaries (quick overview)

对话摘要(快速概览)

jq -r 'select(.type == "summary") | .summary' ~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined
jq -r 'select(.type == "summary") | .summary' ~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined

Tool Usage Statistics

工具使用统计

bash
PROJECT="X--Dev-claude-mods"
bash
PROJECT="X--Dev-claude-mods"

Tool frequency across all sessions

所有会话的工具使用频率

cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' |
sort | uniq -c | sort -rn
cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' |
sort | uniq -c | sort -rn

Tool frequency for specific session

特定会话的工具使用频率

jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn

Tools with their inputs (sampled)

带输入参数的工具示例

jq -c 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | {tool: .name, input: .input}'
~/.claude/projects/$PROJECT/$SESSION.jsonl | head -20
undefined
jq -c 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | {tool: .name, input: .input}'
~/.claude/projects/$PROJECT/$SESSION.jsonl | head -20
undefined

Extract Thinking Blocks

提取思考块

bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"
bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"

All thinking blocks (reasoning trace)

所有思考块(推理轨迹)

jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "thinking") | .thinking'
~/.claude/projects/$PROJECT/$SESSION.jsonl
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "thinking") | .thinking'
~/.claude/projects/$PROJECT/$SESSION.jsonl

Thinking blocks with context (which turn)

带上下文的思考块(对应对话轮次)

jq -r 'select(.type == "assistant") | .message.content as $content | ($content | map(select(.type == "thinking")) | .[0].thinking) as $thinking | ($content | map(select(.type == "text")) | .[0].text | .[0:100]) as $response | select($thinking) | "---\nThinking: ($thinking[0:500])...\nResponse: ($response)..."'
~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined
jq -r 'select(.type == "assistant") | .message.content as $content | ($content | map(select(.type == "thinking")) | .[0].thinking) as $thinking | ($content | map(select(.type == "text")) | .[0].text | .[0:100]) as $response | select($thinking) | "---\n思考内容: ($thinking[0:500])...\n回复内容: ($response)..."'
~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined

Error Analysis

错误分析

bash
PROJECT="X--Dev-claude-mods"
bash
PROJECT="X--Dev-claude-mods"

Find tool errors across sessions

跨会话查找工具错误

cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | select(.content | test("error|Error|ERROR|failed|Failed|FAILED"; "i")) | {tool_id: .tool_use_id, error: .content[0:200]}' 2>/dev/null | head -50
cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | select(.content | test("error|Error|ERROR|failed|Failed|FAILED"; "i")) | {tool_id: .tool_use_id, error: .content[0:200]}' 2>/dev/null | head -50

Count errors by pattern

按错误模式统计数量

cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | .content' 2>/dev/null |
grep -i "error|failed|exception" |
sed 's/[0-9]+//g' | sort | uniq -c | sort -rn | head -20
undefined
cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | .content' 2>/dev/null |
grep -i "error|failed|exception" |
sed 's/[0-9]+//g' | sort | uniq -c | sort -rn | head -20
undefined

Search Across Sessions

跨会话搜索

bash
PROJECT="X--Dev-claude-mods"
bash
PROJECT="X--Dev-claude-mods"

Search user messages

搜索用户消息

cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "text") | .text' |
grep -i "pattern"
cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "user") | .message.content[]? | select(.type == "text") | .text' |
grep -i "pattern"

Search assistant responses

搜索Claude回复

cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "text") | .text' |
grep -i "pattern"
cat ~/.claude/projects/$PROJECT/*.jsonl |
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "text") | .text' |
grep -i "pattern"

Find sessions mentioning a file

查找提及特定文件的会话

for f in ~/.claude/projects/$PROJECT/*.jsonl; do if grep -q "specific-file.ts" "$f"; then echo "Found in: $(basename $f)" fi done
undefined
for f in ~/.claude/projects/$PROJECT/*.jsonl; do if grep -q "specific-file.ts" "$f"; then echo "在以下文件中找到: $(basename $f)" fi done
undefined

Conversation Flow Reconstruction

对话流重构

bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"
bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"

Reconstruct conversation (user/assistant turns)

重构对话(用户/Claude轮次)

jq -r ' if .type == "user" then .message.content[]? | select(.type == "text") | "USER: (.text[0:200])" elif .type == "assistant" then .message.content[]? | select(.type == "text") | "CLAUDE: (.text[0:200])" else empty end ' ~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined
jq -r ' if .type == "user" then .message.content[]? | select(.type == "text") | "用户: (.text[0:200])" elif .type == "assistant" then .message.content[]? | select(.type == "text") | "CLAUDE: (.text[0:200])" else empty end ' ~/.claude/projects/$PROJECT/$SESSION.jsonl
undefined

Subagent Analysis

子Agent分析

bash
PROJECT="X--Dev-claude-mods"
bash
PROJECT="X--Dev-claude-mods"

List subagent sessions

列出子Agent会话

ls ~/.claude/projects/$PROJECT/agent-*.jsonl 2>/dev/null
ls ~/.claude/projects/$PROJECT/agent-*.jsonl 2>/dev/null

Subagent tool usage

子Agent工具使用情况

for f in ~/.claude/projects/$PROJECT/agent-*.jsonl; do echo "=== $(basename $f) ===" jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' "$f" |
sort | uniq -c | sort -rn | head -5 done
undefined
for f in ~/.claude/projects/$PROJECT/agent-*.jsonl; do echo "=== $(basename $f) ===" jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' "$f" |
sort | uniq -c | sort -rn | head -5 done
undefined

Advanced Analysis

高级分析

Token/Cost Estimation

Token/成本估算

bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"
bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"

Rough character count (tokens ≈ chars/4)

粗略字符数统计(Token数≈字符数/4)

jq -r '[ (select(.type == "user") | .message.content[]? | select(.type == "text") | .text | length), (select(.type == "assistant") | .message.content[]? | select(.type == "text") | .text | length) ] | add' ~/.claude/projects/$PROJECT/$SESSION.jsonl |
awk '{sum+=$1} END {print "Total chars:", sum, "Est tokens:", int(sum/4)}'
undefined
jq -r '[ (select(.type == "user") | .message.content[]? | select(.type == "text") | .text | length), (select(.type == "assistant") | .message.content[]? | select(.type == "text") | .text | length) ] | add' ~/.claude/projects/$PROJECT/$SESSION.jsonl |
awk '{sum+=$1} END {print "总字符数:", sum, "估算Token数:", int(sum/4)}'
undefined

File Modification Tracking

文件修改跟踪

bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"
bash
SESSION="417ce03a-6fc7-4906-b767-6428338f34c3"
PROJECT="X--Dev-claude-mods"

Files edited (Edit tool usage)

编辑过的文件(Edit工具使用记录)

jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "Edit") | .input.file_path'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "Edit") | .input.file_path'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn

Files written

写入的文件

jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "Write") | .input.file_path'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq
undefined
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use" and .name == "Write") | .input.file_path'
~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq
undefined

Session Comparison

会话对比

bash
PROJECT="X--Dev-claude-mods"
SESSION1="session-id-1"
SESSION2="session-id-2"
bash
PROJECT="X--Dev-claude-mods"
SESSION1="session-id-1"
SESSION2="session-id-2"

Compare tool usage between sessions

对比两个会话的工具使用情况

echo "=== Session 1 ===" &&
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION1.jsonl | sort | uniq -c | sort -rn
echo "=== Session 2 ===" &&
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION2.jsonl | sort | uniq -c | sort -rn
undefined
echo "=== 会话1 ===" &&
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION1.jsonl | sort | uniq -c | sort -rn
echo "=== 会话2 ===" &&
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name'
~/.claude/projects/$PROJECT/$SESSION2.jsonl | sort | uniq -c | sort -rn
undefined

Quick Reference Commands

快速参考命令

TaskCommand Pattern
List sessions
ls -lah ~/.claude/projects/$PROJECT/*.jsonl | grep -v agent
Entry types
jq -r '.type' $SESSION.jsonl | sort | uniq -c
Tool stats
jq -r '... | select(.type == "tool_use") | .name' | sort | uniq -c
Extract thinking
jq -r '... | select(.type == "thinking") | .thinking'
Find errors
grep -i "error|failed" $SESSION.jsonl
Session summaries
jq -r 'select(.type == "summary") | .summary'
User messages
jq -r 'select(.type == "user") | .message.content[]?.text'
任务命令模板
列出会话
ls -lah ~/.claude/projects/$PROJECT/*.jsonl | grep -v agent
条目类型统计
jq -r '.type' $SESSION.jsonl | sort | uniq -c
工具使用统计
jq -r '... | select(.type == "tool_use") | .name' | sort | uniq -c
提取思考内容
jq -r '... | select(.type == "thinking") | .thinking'
查找错误
grep -i "error|failed" $SESSION.jsonl
会话摘要
jq -r 'select(.type == "summary") | .summary'
用户消息
jq -r 'select(.type == "user") | .message.content[]?.text'

Usage Examples

使用示例

"What tools did I use most in yesterday's session?"

"我昨天的会话中使用最多的工具是什么?"

bash
undefined
bash
undefined

Find yesterday's sessions by modification time

按修改时间查找昨天的会话

find ~/.claude/projects/X--Dev-claude-mods -name ".jsonl" -mtime -1 ! -name "agent-" |
xargs -I{} jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' {} |
sort | uniq -c | sort -rn
undefined
find ~/.claude/projects/X--Dev-claude-mods -name ".jsonl" -mtime -1 ! -name "agent-" |
xargs -I{} jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' {} |
sort | uniq -c | sort -rn
undefined

"Show me my reasoning when debugging the auth issue"

"展示我调试认证问题时的思考过程"

bash
undefined
bash
undefined

Search for sessions mentioning auth, then extract thinking

搜索提及认证的会话,然后提取思考内容

for f in ~/.claude/projects/$PROJECT/*.jsonl; do if grep -qi "auth" "$f"; then echo "=== $(basename $f) ===" jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "thinking") | .thinking' "$f" |
grep -i -A5 -B5 "auth" fi done
undefined
for f in ~/.claude/projects/$PROJECT/*.jsonl; do if grep -qi "auth" "$f"; then echo "=== $(basename $f) ===" jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "thinking") | .thinking' "$f" |
grep -i -A5 -B5 "auth" fi done
undefined

"What errors occurred most frequently this week?"

"这周最频繁出现的错误是什么?"

bash
find ~/.claude/projects/ -name "*.jsonl" -mtime -7 | \
  xargs cat 2>/dev/null | \
  jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | .content' 2>/dev/null | \
  grep -i "error\|failed" | \
  sed 's/[0-9]\+//g' | sed 's/\/[^ ]*//g' | \
  sort | uniq -c | sort -rn | head -10
bash
find ~/.claude/projects/ -name "*.jsonl" -mtime -7 | \
  xargs cat 2>/dev/null | \
  jq -r 'select(.type == "user") | .message.content[]? | select(.type == "tool_result") | .content' 2>/dev/null | \
  grep -i "error\|failed" | \
  sed 's/[0-9]\+//g' | sed 's/\/[^ ]*//g' | \
  sort | uniq -c | sort -rn | head -10

Privacy Considerations

隐私注意事项

Session logs contain:
  • Full conversation history including any sensitive data discussed
  • File contents that were read or written
  • Thinking/reasoning (internal deliberation)
  • Tool inputs/outputs
Before sharing session exports:
  1. Review for credentials, API keys, personal data
  2. Consider redacting file paths if they reveal project structure
  3. Thinking blocks may contain candid assessments
会话日志包含:
  • 完整对话历史,包括讨论过的敏感数据
  • 读取或写入的文件内容
  • 思考/推理过程(内部 deliberation)
  • 工具输入/输出
在分享会话导出内容前:
  1. 检查是否包含凭证、API密钥、个人数据
  2. 考虑编辑文件路径以避免泄露项目结构
  3. 思考块可能包含未公开的评估内容

Export Formats

导出格式

Markdown Report

Markdown报告

bash
SESSION="session-id"
PROJECT="X--Dev-claude-mods"

echo "# Session Report: $SESSION"
echo ""
echo "## Summary"
jq -r 'select(.type == "summary") | "- \(.summary)"' ~/.claude/projects/$PROJECT/$SESSION.jsonl
echo ""
echo "## Tool Usage"
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' \
  ~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn | \
  awk '{print "| " $2 " | " $1 " |"}'
bash
SESSION="session-id"
PROJECT="X--Dev-claude-mods"

echo "# 会话报告: $SESSION"
echo ""
echo "## 摘要"
jq -r 'select(.type == "summary") | "- \(.summary)"' ~/.claude/projects/$PROJECT/$SESSION.jsonl
echo ""
echo "## 工具使用情况"
jq -r 'select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name' \
  ~/.claude/projects/$PROJECT/$SESSION.jsonl | sort | uniq -c | sort -rn | \
  awk '{print "| " $2 " | " $1 " |"}'

JSON Export (for further processing)

JSON导出(用于进一步处理)

bash
jq -s '{
  session_id: "'$SESSION'",
  entries: length,
  tools: [.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name] | group_by(.) | map({tool: .[0], count: length}),
  summaries: [.[] | select(.type == "summary") | .summary]
}' ~/.claude/projects/$PROJECT/$SESSION.jsonl
bash
jq -s '{
  session_id: "'$SESSION'",
  entries: length,
  tools: [.[] | select(.type == "assistant") | .message.content[]? | select(.type == "tool_use") | .name] | group_by(.) | map({tool: .[0], count: length}),
  summaries: [.[] | select(.type == "summary") | .summary]
}' ~/.claude/projects/$PROJECT/$SESSION.jsonl