Markdown AI-chat splitter
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
Source & download: Split a 10,000-Line AI Chat Export into Numbered Markdown Files
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) |
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
AI and LLM experiments
Experiments with LLM APIs: a Flask chat over several providers, speech-to-text and model tests, and a React and shadcn debugging sandbox.
PythonFastAPI / FlaskLLM integrationReact+1ThuOneCopy: desktop code consolidator for LLM prompts
A PyQt5 desktop app that picks files from a project and copies them as one block for LLM prompts, with a layered layout and auto-update.
PythonDesktop GUI (Tk / Qt)LLM integrationVisaAgent: AI and RPA visa-form automation platform
My own product: AI document extraction plus Playwright automation that fills government visa forms, as desktop app, web and WhatsApp bot.
PlaywrightLLM integrationPythonFastAPI / Flask+6Want to discuss this project?
Happy to walk through the architecture, trade-offs or the code.