# 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.

URL: https://thuyavan.netlify.app/projects/markdown-chat-splitter
Updated: 2026-10-12

- Period: 2025-12
- Technologies: Python, LLM 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)

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).
