fixing-claude-export-conversations
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFixing Claude Code Export Conversations
修复Claude Code导出的对话文件
Reconstruct broken line wrapping in Claude Code exported files.
.txt重构Claude Code导出的文件中损坏的换行格式。
.txtQuick Start
快速开始
bash
undefinedbash
undefinedFix and show stats
修复并显示统计信息
uv run <skill-path>/scripts/fix-claude-export.py <export.txt> --stats
uv run <skill-path>/scripts/fix-claude-export.py <export.txt> --stats
Custom output
自定义输出
uv run <skill-path>/scripts/fix-claude-export.py <export.txt> -o fixed.txt
uv run <skill-path>/scripts/fix-claude-export.py <export.txt> -o fixed.txt
Validate the result (53 automated checks)
验证结果(包含53项自动检查)
uv run <skill-path>/scripts/validate-claude-export-fix.py <export.txt> fixed.txt
Replace `<skill-path>` with the resolved path to this skill's directory. Find it with:
```bash
find ~/.claude -path "*/fixing-claude-export-conversations/scripts" -type d 2>/dev/nulluv run <skill-path>/scripts/validate-claude-export-fix.py <export.txt> fixed.txt
将`<skill-path>`替换为该skill目录的实际路径。可通过以下命令查找:
```bash
find ~/.claude -path "*/fixing-claude-export-conversations/scripts" -type d 2>/dev/nullWorkflow
工作流程
Copy this checklist and track progress:
- [ ] Step 1: Locate the exported .txt file
- [ ] Step 2: Run fix script with --stats
- [ ] Step 3: Run validation suite
- [ ] Step 4: Spot-check output (tables, CJK paragraphs, tool results)
- [ ] Step 5: Deliver fixed file to userStep 1: Locate the file. Claude Code exports use the naming pattern .
YYYY-MM-DD-HHMMSS-<slug>.txtStep 2: Run the fix script.
bash
uv run <skill-path>/scripts/fix-claude-export.py <input.txt> -o <output.txt> --statsReview the stats output — typical results: 20-25% line reduction, 80+ table borders fixed, 160+ table cells fixed.
Step 3: Run the validation suite.
bash
uv run <skill-path>/scripts/validate-claude-export-fix.py <input.txt> <output.txt>All checks must pass. If any fail, investigate before delivering. Use for full details on passing checks too.
--verboseStep 4: Spot-check. Open the output and verify:
- Tables have intact borders (box-drawing characters on single lines)
- CJK/English mixed text has pangu spacing (, not
Portal 都需要)Portal都需要 - Tool result blocks () have complete content on joined lines
⎿ - Diff output within tool results has each line number on its own line
Step 5: Deliver the fixed file to the user.
复制以下检查清单并跟踪进度:
- [ ] 步骤1:找到导出的.txt文件
- [ ] 步骤2:运行修复脚本并添加--stats参数
- [ ] 步骤3:运行验证套件
- [ ] 步骤4:抽查输出内容(表格、中日韩段落、工具结果)
- [ ] 步骤5:将修复后的文件交付给用户步骤1:找到文件。Claude Code导出文件的命名格式为。
YYYY-MM-DD-HHMMSS-<slug>.txt步骤2:运行修复脚本
bash
uv run <skill-path>/scripts/fix-claude-export.py <input.txt> -o <output.txt> --stats查看统计输出——典型结果:行数减少20-25%,修复80+个表格边框,修复160+个表格单元格。
步骤3:运行验证套件
bash
uv run <skill-path>/scripts/validate-claude-export-fix.py <input.txt> <output.txt>所有检查必须通过。如果有任何检查失败,在交付前需进行调查。使用参数可查看所有通过检查的详细信息。
--verbose步骤4:抽查。打开输出文件并验证:
- 表格边框完整(框线字符在单行显示)
- 中日韩/英文混合文本有Pangu空格(如,而非
Portal 都需要)Portal都需要 - 工具结果块(前缀)的内容已完整合并到单行
⎿ - 工具结果中的Diff输出每行的行号单独显示
步骤5:交付修复后的文件给用户。
What Gets Fixed
修复内容
The script handles 10 content types using a state-machine with next-line look-ahead:
- User prompts (prefix, dw=76 padding) — paragraph joins with pangu spacing
❯ - Claude responses (prefix) — narrative, bullet, and numbered list joins
● - Claude paragraphs (2-space indent) — next-line look-ahead via
_is_continuation_fragment - Tables — border reconstruction, cell re-padding with pipe-count tracking
- Tool calls (etc.) — path and argument reconstruction
● Bash( - Tool results (prefix) — continuation joins including deeper-indented fragments
⎿ - Plan text (5-space indent) — next-line look-ahead via
_is_plan_continuation_fragment - Agent tree (/
├─) — preserved structure└─ - Separators (,
────) — never joined--- - Tree connectors (standalone ) — preserved
│
该脚本使用带下一行前瞻的状态机处理10种内容类型:
- 用户提示(前缀,dw=76填充)——段落合并并添加Pangu空格
❯ - Claude回复(前缀)——叙述内容、项目符号和编号列表合并
● - Claude段落(2空格缩进)——通过进行下一行前瞻
_is_continuation_fragment - 表格——边框重构,通过管道计数跟踪重新填充单元格
- 工具调用(等)——路径和参数重构
● Bash( - 工具结果(前缀)——合并连续内容,包括更深缩进的片段
⎿ - 计划文本(5空格缩进)——通过进行下一行前瞻
_is_plan_continuation_fragment - Agent树(/
├─)——保留结构└─ - 分隔符(,
────)——从不合并--- - 树连接器(独立的)——保留结构
│
Key Design Decisions
关键设计决策
Next-line look-ahead (not dw thresholds): Instead of asking "was this line wrapped?" (fragile threshold), the script asks "does the next line look like a continuation?" by examining its content patterns — lowercase start, CJK ideograph start, opening bracket, hyphen/slash/underscore continuation.
Pangu spacing: Inserts spaces between ASCII alphanumeric characters and CJK ideographs at join boundaries. Also triggers for , , , adjacent to CJK.
%#+:Mid-token detection: Joins without space when boundaries indicate identifiers ( + ), paths ( + ), or hyphenated names ( + ). Exception: prefix gets a space ( + ).
BASE_URLdocuments/05-teamready-together--run--headed下一行前瞻(而非dw阈值):不是判断“这行是否被换行?”(脆弱的阈值),而是通过检查内容模式判断“下一行看起来是否是延续内容?”——比如以小写字母开头、中日韩汉字开头、左括号开头、连字符/斜杠/下划线延续等。
Pangu空格:在ASCII字母数字字符和中日韩汉字的合并边界插入空格。当、、、与中日韩汉字相邻时也会触发。
%#+:中间标记检测:当边界表示标识符(如 + )、路径(如 + )或连字符名称(如 + )时,无空格合并。例外:前缀前添加空格(如 + )。
BASE_URLdocuments/05-teamready-together--run--headedSafety
安全性
- Never modifies the original file
- Marker counts verified: ,
❯,●,✻,⎿must match input/output… - Runaway join detection: warns if any line exceeds 500 display-width
- Strict UTF-8 encoding — no silent fallbacks
- 从不修改原始文件
- 验证标记计数:、
❯、●、✻、⎿在输入和输出中必须一致… - 失控合并检测:如果任何行超过500显示宽度则发出警告
- 严格UTF-8编码——无静默回退
Dependencies
依赖项
Python 3.10+ via — zero external packages (stdlib only: , , , , ).
uv rununicodedataargparserepathlibdataclasses通过运行Python 3.10+——零外部包(仅使用标准库:、、、、)。
uv rununicodedataargparserepathlibdataclasses