Python · Text Processing
Split a 10,000-Line AI Chat Export into Numbered Markdown Files
Point md_splitter.py at your chat export and it creates a timestamped folder with one numbered Markdown file per conversation, leaving the original untouched.
PythonCompiled RegexUTF-8 / BOM
Abstract
The problem
AI tools export entire chat history as one huge .md file. Importing it into Notion causes lag and makes it impossible to file answers into different projects.
The solution
A regex-based script that splits the export on the "--- # You Asked:" delimiter into individual, zero-padded files inside a timestamped workspace.
The result
A clean, segmented library of conversations that imports individually into Notion or any knowledge system.
Input & Output
Input
- One large Markdown chat export (path set in INPUT_FILE)
Output
- Timestamped folder YYYY-MM-DD_HH-MM-SS_<Filename> with 001.md, 002.md …
Optional output
- Terminal summary: files created and folder location
System Diagram
Chat export .md
10,000+ lines
Load & decode
UTF-8 → UTF-8-SIG fallback
Compiled regex
MULTILINE split pattern
Numbered files
001, 002, 010 …
Timestamped workspace
Original untouched
How It Works
High-performance regex
re.compile with MULTILINE finds the delimiter pattern near-instantly.
Dual-mode split
SPLIT_AT_START decides whether the separator stays with the previous or next file.
Workspace per run
Timestamped folders prevent overwrites between exports.
Robust file handling
Windows path normalisation, encoding fallback and zero-padded names.
Configuration
| Option | Purpose |
|---|---|
INPUT_FILE | Full Windows path to the chat export. |
SPLIT_PATTERN_END | Text marking a new question (default "# You Asked:"). |
SPLIT_AT_START | Boolean – where the separator line lands. |
How to Run
# INPUT_FILE = r"C:\Path\chat_export.md"python md_splitter.pyImpact & Benefits
Screenshots
Frequently Asked Questions
Why is my large Markdown file slow in Notion?
Single files with tens of thousands of lines use a lot of memory. Splitting into small pages keeps Notion responsive.
How does the script decide where to split?
A compiled multiline regex matches the delimiter (default "--- # You Asked:"). SPLIT_AT_START controls which file keeps the separator.
Does it change my original export?
No. Output goes to a new YYYY-MM-DD_HH-MM-SS folder.
Related
Merge Selected Project Files into One AI-Ready Text Block
Select files from a local project and merge them into one sanitised, AI-ready text block.
Read documentation