Python · Text Processing

Split a 10,000-Line AI Chat Export into Numbered Markdown Files

TL;DR

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.

Updated 1 min read

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

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

OptionPurpose
INPUT_FILEFull Windows path to the chat export.
SPLIT_PATTERN_ENDText marking a new question (default "# You Asked:").
SPLIT_AT_STARTBoolean – where the separator line lands.

How to Run

Paste the export path into INPUT_FILE
# INPUT_FILE = r"C:\Path\chat_export.md"
Run it
python md_splitter.py

Impact & Benefits

Dramatically lower Notion RAM usage with small pages.
Faster OS search because answers live in individual files.
Easy drag-and-drop of tutorials and snippets into project folders.
The original export is never modified.

Screenshots

1/2 Input file, script and output folders
2/2 Generated numbered Markdown files

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

© 2026 Thuyavan Sivarasa. Script code is MIT licensed.