How to Extract All AI Chat History from Cursor, Claude, and Windsurf
If you've been actively writing code with AI assistants over the past year or two, gigabytes of hidden context have accumulated on your disk. This includes hundreds of conversations, debugging sessions, generated diffs, edits, and context snippets. The problem is that each tool hides this data in its own corners. Cursor stores history in SQLite databases, Claude Code writes separate JSONL session files, and Continue and Gemini CLI keep everything in deep system folders.
The ai-data-extraction repository by developer 0xSero solves a simple problem: it finds all local assistant databases, parses them, and exports a clean dataset in a unified JSONL format.
Why extract this data
The main reason is fine-tuning your own models. When developers tune open models like Qwen2.5-Coder or DeepSeek-Coder for their stack, synthetic datasets often fall short. Your real conversations with an assistant contain unique data: how exactly you formulate tasks, which errors you fix, which files you pass into context, and which edit options you actually accept.
The second reason is more practical: simple backup and local search. Finding a session from three months ago within the Cursor or Trae interface can be difficult, especially if the project is closed or migrated.
What the script collection can do
The project is a collection of small Python scripts. A nice detail: there are no external dependencies. You only need standard Python 3.6+, and the scripts use built-in modules sqlite3, json, pathlib, and os.
The set supports eight popular tools:
- Cursor (including older chat versions, Composer v1 and v2 with tables
cursorDiskKV) - Claude Code and Claude Desktop
- Windsurf
- Trae
- Continue
- OpenCode (the desktop Tauri version and CLI)
- Google Gemini CLI
- Codex
The scripts automatically detect the operating system (macOS, Linux, or Windows), locate the editors' working directories, and extract structured history.
How the export format works
Each line in the resulting JSONL file is a separate complete session. The scripts don't extract raw text but a full context snapshot:
{
"messages": [
{
"role": "user",
"content": "Как исправить эту ошибку типизации в TypeScript?",
"code_context": [
{
"file": "/Users/user/project/src/index.ts",
"code": "const x: string = 123;",
"range": {
"selectionStartLineNumber": 10,
"positionLineNumber": 10
}
}
],
"timestamp": "2025-01-16T14:30:22.123Z"
},
{
"role": "assistant",
"content": "Ошибка возникает из-за присвоения числа переменной строкового типа...",
"suggested_diffs": [],
"model": "claude-sonnet-4-5",
"timestamp": "2025-01-16T14:30:25.456Z"
}
],
"source": "cursor-composer",
"name": "TypeScript Type Error Fix",
"created_at": 1705414222000
}
It includes tool system calls, command execution results, applied diffs, and model-specific metadata.
Quick start
Clone the repository and run the desired script:
git clone https://github.com/0xSero/ai-data-extraction.git
cd ai-data-extraction
# Выгрузить только Cursor
python3 extract_cursor.py
# Или вытащить данные сразу со всех установленных инструментов
./extract_all.sh
All results will land in the extracted_data/ folder as separate timestamped files.
You can merge everything into a single file with one system command:
cat extracted_data/*.jsonl > all_conversations.jsonl
Preparing for training via Unsloth
After export, the dataset can easily be fed to fine-tuning libraries. For example, the combination of datasets from Hugging Face and Unsloth picks up this JSONL directly:
from datasets import load_dataset
from unsloth import FastLanguageModel
# Загружаем собранные сессии
dataset = load_dataset('json', data_files='extracted_data/*.jsonl', split='train')
# Оставляем только сессии с ответами ассистента
dataset = dataset.filter(lambda x: any(m['role'] == 'assistant' for m in x['messages']))
model, tokenizer = FastLanguageModel.from_pretrained(
"unsloth/qwen2.5-coder-7b-instruct",
max_seq_length=4096,
load_in_4bit=True,
)
def format_chat(example):
return {
'text': tokenizer.apply_chat_template(
example['messages'],
tokenize=False
)
}
dataset = dataset.map(format_chat)
Security and considerations
Before sending the resulting dataset to the cloud or an external server, check its contents. Your conversation history will inevitably contain private code fragments, home directory paths, and sometimes forgotten API keys.
The project author recommends running files through a secret detector:
pip install detect-secrets
detect-secrets scan extracted_data/*.jsonl
If the editor's database is locked during export (a common situation with SQLite when Cursor is open), simply close the editor before running the script.
Who will find this repository useful
The project is useful for ML engineers collecting data for local code models and developers who want to preserve an archive of their AI work in case they switch editors. The script code is simple and open, making it easy to extend for any rare plugin or custom VS Code fork.
Related projects