首页 / 全部技能 / 基础工具与工作流 / fixing-claude-export-conversations
基础工具与工作流 · daymade/claude-code-skills

fixing-claude-export-conversations

Fixes broken line wrapping in Claude Code exported conversation files (.txt), reconstructing tables, paragraphs, paths, and tool calls that were hard-wrapped at fixed column widths. Includes an automated validation suite (generic, file-agnostic checks). Triggers when the user has a Claude Code export file with broken formatting, mentions "fix export", "fix conversation", "exported conversation", "make export readable", references a file matching YYYY-MM-DD-HHMMSS-*.txt, or has a .txt file with broken tables, split paths, or mangled tool output from Claude Code.

L4 高权限 · 分级授权与审计V1 已固定执行命令读写文件Dual-pass Audit
Author daymadeGitHub daymade/claude-code-skills ↗Stars 1385License MIT(仓库根 LICENSE:Copyright (c) 2025 daymade;GitHub API spdx MIT)Commit d5c4678cb5
管控等级描述 skill 的能力与建议配套的管控措施,不代表质量或安全认证,也不表示可用或不可用。是否使用由用户和管理者决定。不同 agent 宿主对权限的约束各不相同,请勿假定宿主一定会提供安全兜底。第三方 skill 版权归原作者,使用风险由使用者自行承担。

1实现原理 · 为什么它能做到

核心不是按固定折行宽度判断,而是状态机 + 下一行 look-ahead:每遇到疑似被硬折的行,问『下一行长得像不像续行』(小写开头 / CJK 开头 / 开括号 / 连字符-斜杠-下划线续写),以此决定拼接而不是宽度阈值。

daymade-claude-code/claude-export-txt-better/SKILL.md
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.
对应 fix-claude-export.py 的 _is_continuation_fragment / _is_plan_continuation_fragment 等谓词:它们是‘拼不拼’的决策核心。

对 10 类内容分别处理(用户提示、Claude 回复、段落、表格、工具调用、工具结果、plan 文本、agent 树、分隔线、树连接符),表格另有边框重建与按列宽重排。

daymade-claude-code/claude-export-txt-better/SKILL.md
The script handles 10 content types using a state-machine with next-line look-ahead
脚本 process() 约 470 行状态机;表格处理占大头(_merge_multirow_table_cells / _realign_table_borders / _repad_table_row_to_widths 等)。

拼接时做 CJK 感知的空格处理(pangu spacing)与 mid-token 检测:ASCII 与 CJK 交界插空格;标识符/路径/连字符中间被折的则不加空格直接接回。

daymade-claude-code/claude-export-txt-better/SKILL.md
**Pangu spacing**: Inserts spaces between ASCII alphanumeric characters and CJK ideographs at join boundaries.
smart_join/boundary_aware_join 实现 CJK↔ASCII 空格与 BASE_+URL 这类 mid-token 直连规则。

输出经过多道保真安全闸:绝不允许覆盖原文件、标记符号(❯ ● ✻ ⎿ …)输入输出计数必须一致、超宽行(>500 display width)报警、严格 UTF-8 无静默回退。

daymade-claude-code/claude-export-txt-better/SKILL.md
- Never modifies the original file - Marker counts verified: `❯`, `●`, `✻`, `⎿`, `…` must match input/output
main() 里先 resolve 输入输出路径并拒绝 output==input,再跑 marker-count 与 runaway-join 两道检查后才写盘。

配套一个通用(与文件无关)的自动验证套件 validate-claude-export-fix.py,作为每次修复后的质量门。

daymade-claude-code/claude-export-txt-better/scripts/validate-claude-export-fix.py
Runs a comprehensive suite of checks against a fixed file and its original, reporting PASS/FAIL for each with evidence.
SKILL 工作流 Step 3 要求全部 checks 通过才交付;SKILL.md 称其为 '53 automated checks'(脚本内按 category 分组逐项断言)。

纯本地、零第三方依赖:以 uv run 启动,只用 Python 标准库。

daymade-claude-code/claude-export-txt-better/SKILL.md
Python 3.10+ via `uv run` — zero external packages (stdlib only: `unicodedata`, `argparse`, `re`, `pathlib`, `dataclasses`).
脚本无网络/子进程调用;uv 仅作运行时启动器(若本机缺 Python 3.10+ 会按需获取运行时)。

2核心能力

01修复 Claude Code .txt 导出的硬折行断行(段落/表格/路径/工具调用/工具结果)
0210 类内容分别走状态机 + look-ahead 拼接,保留 agent 树与分隔线结构
03表格边框重建 + 按列宽重新填充(pipe 计数追踪)
04CJK/ASCII 交界 pangu 空格与 mid-token 无空格直连
05保真安全闸:不改原文件、marker 计数一致、超宽行报警、严格 UTF-8
06通用自动化验证套件(53 项断言)+ --stats/--dry-run 输出

3外部依赖

KindDependency / Endpoint
cliuv
clipython3 (>=3.10)

4管控建议与判定依据

建议配套管控措施
面向 Agent
分级或逐次授权,建议在沙箱运行
面向管理者
审批流程、可回滚、全程审计
判定依据(文件路径与关键语句摘要)
  • scripts/: 执行本地脚本或命令: scripts/fix-claude-export.py
  • 本地工作目录: 文件读写与工件输出: 输出 *-fixed.txt(默认 <input-stem>-fixed.txt,可 -o 指定;main() 强制 output 不能等于 inpu
审计说明: 。自带脚本纯本地文本整形:读入用户给出的 export .txt,写出 *-fixed.txt,强制 output≠input、marker 计数一致、超宽行报警、严格 UTF-8;无网络外发、无凭证读取、不读取 settings/密钥文件。唯一间接接触面是 SKILL 用 uv run 启动(若本机缺 Python 3.10+ 会按需从官方源获取运行时,属常规工具链动作)。

5第二遍独立确认

  • [ok] 无网络外发(脚本层) — 全目录无 urllib/requests/http 调用,grep https?:// 零命中(连文档链接都没有)
  • [ok] 无凭证读取 — 无 os.environ/getenv/API_KEY/settings.json 读取;脚本只读用户显式传入的 export 路径
  • [ok] 不改原文件声明属实 — main() 先比较 resolve 后的 input/output 路径,相等即报错退出
  • [ok] marker 计数保真声明属实 — _count_markers 统计 ❯/●/✻/⎿/…,输出不一致打印 WARNING
  • [ok] '10 content types' 与 '53 automated checks' 能力声明 — SKILL.md What Gets Fixed 列出 10 类;validate 脚本为分 category 的断言套件,'53' 为 SKILL 侧声明数
  • [ok] 零第三方依赖声明 — 脚本 import 仅标准库;uv 只作为启动器出现于 SKILL.md 命令

6结论

  • 修复决策基于内容模式(look-ahead)而非脆弱的宽度阈值,能处理表格/CJK/长路径等真实破损形态
  • 把不破坏原文件的承诺做进代码强制(output 必须不同于 input)而非提示词
  • 自带通用验证套件与评测文件,交付有机械质量门
  • 零依赖纯本地,CJK/ASCII 混排体验精细(pangu 空格 + mid-token 直连)
  • 适合: 适合任何手里有 Claude Code 导出的 .txt(表格断裂、路径被折、工具输出错位、中英混排缺空格)需要恢复可读性的用户;修复由脚本机械完成 + 校验套件把关,人工只做抽查,对普通开发者与需要批量处理多个导出文件的场景都适用。
    不适合: 不适合需要修复非 .txt 格式(JSON/markdown 源文件)或语义性重写对话内容的任务;不适合期望把内容上传/交给外部服务的场景(本技能纯本地);也不适合把行数减少当 KPI 的用法。
    Install Agent-Ready
    ① Verified Mirror 2026-09-09
    Option A · Direct DownloadDownload fixing-claude-export-conversations.tar.gz
    sha256: d5562a9e134ff1b7…
    Option B · Copy Guide for Agent
    install.json
    agent 读 JSON 指南后会自动从本站下载安装,无需更多说明。
    ② Upstream GitHub
    GitHub Repo ↗
    Pinned to commit d5c4678cb5.