Developer tools & scriptsOwnerDec 2025

Markdown AI-chat splitter

TL;DR

AI chat exports are single huge Markdown files. This script splits them on a regex delimiter into zero-padded files in a timestamped folder and leaves the original untouched.

Period
Dec 2025
Technologies
2
Diagrams
1
Reading time
1 min

PythonLLM integration

Problem (owner's spec)

Exported chats from ChatGPT, Gemini, Perplexity and similar tools are single huge Markdown files. Importing one into Notion as a single page uses a lot of RAM and becomes hard to view. The owner wanted each question + answer as its own numbered file so they can be imported one by one.

Behaviour

Step Function Detail
Config constants at the top INPUT_FILE (Windows path), split marker, SPLIT_AT_START flag; no CLI arguments, by design
Path normalize_path accepts pasted Windows paths (quotes, backslashes)
Output dir create_output_folder <YYYY-MM-DD_HH-MM-SS>__<file name> next to the input, so reruns never overwrite
Find find_split_positions re.compile(r'^---\s*\n+# You Asked:', re.MULTILINE): exact, case-sensitive marker at line start
Split split_content at the start of the marker (before ---) or after # You Asked:, by flag; warns if no marker is found
Write numbered files numbered in order, names made safe by sanitize_name (strips Windows-illegal characters)
Behaviour
Diagram as text
flowchart LR
 IN[chat export.md] --> RE["regex: ^--- … # You Asked:"] --> POS[split offsets] --> CH[chunks]
 CH --> N[numbered, sanitised file names] --> OUT[(timestamped folder → Notion import)]

The file is read once and matched with one compiled regex, so a 10,000-line export splits in a single pass.

Relationship

Part of the owner’s LLM-workflow tools with S06 (HAR → API docs, doc 030), S04 (tree export, doc 037) and S01 / P22 (code → prompt).

Related projects

Want to discuss this project?

Happy to walk through the architecture, trade-offs or the code.

Email me about it

© 2026 Thuyavan Sivarasa. Script code is MIT licensed.