Design and Implementation of a Terminal-Based AI Conversation History Export Tool
This article details the design and implementation of a terminal-based tool for exporting AI conversation histories to local Markdown files. Addressing challenges like data sovereignty, search efficiency, and content reuse, the tool leverages Go and a Terminal User Interface (TUI) to fetch, select, and format cloud-based AI conversations. Key features include credential-based real-time fetching, lazy loading, interactive selection via Bubbletea, local deduplication, and cross-platform distribution.
1. Background and Motivation
As large language model (LLM) chat platforms become a standard in daily workflows, valuable Q&A, reasoning processes, and code snippets accumulate in cloud session records. These records face several practical challenges:
- Data Sovereignty Risks: Conversation data is entirely hosted on the provider’s side. If an account experiences issues or the service changes, historical records may become irretrievable.
- Low Search Efficiency: Built-in search capabilities are limited and difficult to integrate with personal knowledge bases.
- Reuse Difficulties: Organizing these conversations into notes, blogs, or documentation requires manual copy-pasting, which is highly inefficient.
A natural solution is to build a local tool that batch-fetches conversation history, converts it into structured Markdown files, and hands them off to local note-taking software (such as a Markdown-based knowledge base with bidirectional links) for organization. This article breaks down the design and implementation of such an export tool based on Go and a Terminal User Interface (TUI).
2. Overall Architecture Design
The core pipeline of the tool can be abstracted into four stages:
Credential Acquisition -> Conversation List Fetching -> Interactive Selection -> Formatted Export and Deduplication
1. Credential Acquisition
Older solutions typically rely on the platform’s official “export all data” feature, where users download a ZIP archive, extract it, and feed the JSON file to a script—a cumbersome and lagging process. The refactored approach fetches session credentials (Token) directly from the browser. Users press F12 in the logged-in web client to open Developer Tools, switch to the Network tab, and copy the authentication field’s value from any API request header. Once the tool receives the Token, it can directly call the conversation list and message detail APIs, achieving real-time fetching and eliminating the dependency on manual export files.
2. Conversation List Fetching
There may be hundreds or thousands of historical conversations. Fetching all at once is slow and memory-intensive. Therefore, a pagination + lazy loading strategy is adopted: only the first page is loaded initially, and a request for the next page is triggered when the user scrolls to the bottom of the list. This pattern provides a particularly smooth experience in a TUI environment. The corresponding pseudocode is as follows:
func (m *model) LoadMore() {if m.loading || !m.hasMore {return}m.loading = truego func() {batch, next := api.FetchConversations(m.token, m.cursor)m.mu.Lock()m.items = append(m.items, batch...)m.cursor = nextm.hasMore = next != ""m.loading = falsem.mu.Unlock()}()}
3. Interactive Selection
The TUI is implemented based on Bubbletea’s message-driven model, where keyboard events drive the state machine. The core interaction conventions are:
Up/Downorj/kto move the cursor;Spaceto toggle the current item;Enterto confirm selection and enter the export process;ato select all on the current page,qto quit.
Three export modes are provided: Recent Export (fetches only new conversations since the last export), Full Export, and Manual Selection Export, covering both incremental backup and on-demand organizing scenarios.
4. Formatted Export
The structured messages returned by the API are converted to Markdown. Filenames follow a “Date + Conversation Title” naming convention, such as 2026-05-12_Tech Discussion on Concurrency.md, ensuring natural chronological sorting in file managers. Monthly subdirectories (e.g., conversations_export/2026-05/) are also created to prevent an excessive number of files in a single directory.
3. Key Technical Details
3.1 Local Deduplication Mechanism
Repeated exporting is the biggest resource waste—costing user time and generating numerous redundant requests. Before exporting, the tool scans the target directory and builds a “set of existing filenames.” During export, it compares items one by one: if a file with the same name already exists, it is automatically skipped and marked as “exported” in the UI. This step reduces the cost of a full export to approximately that of an incremental one, which is key to the tool’s practicality.
3.2 Restoration of Deep Thinking Processes
LLM conversations typically contain two types of content: the visible reply body and the “deep thinking/reasoning chain” process. The export process handles these differently:
- Reasoning processes are rendered as collapsible quote blocks or independent sections, combined with heading levels and separators to preserve the original “think first, conclude later” reading rhythm.
- Language tags for code blocks in the body are preserved, and structures like tables and lists are restored as-is.
- Special characters (
/ \ : * ?, etc.) in titles are sanitized to avoid illegal cross-platform filenames.
3.3 Cross-Platform and Distribution
Using Go’s cross-compilation capabilities, a single command can produce binaries for Windows, macOS, and Linux (amd64/arm64):
GOOS=linux GOARCH=arm64 go build -o ai2md-linux-arm64
A single executable file with zero dependencies is the best practice for terminal tool distribution. For users without a Go environment installed, an equivalent Python script version can be provided as a supplement.
4. Workflow Summary
- Log into the chat platform in the browser and obtain the request credentials via Developer Tools.
- Launch the tool, paste the credentials, and the tool loads the conversation list.
- Choose an export mode (Recent/Full/Manual), use Space to select, and Enter to confirm.
- The tool automatically deduplicates, formats, and writes files to local directories organized by month.
- Open the export directory in your note-taking software to search, link, and archive.
5. Conclusion
The value of such a tool goes beyond simple “backup.” It transforms scattered cloud-based conversation assets into local, searchable, version-controllable, and reusable Markdown text, truly realizing data sovereignty over personal AI usage records. Its design concepts—lazy loading, interactive selection, local deduplication, and structured formatting—are equally applicable to any scenario requiring the batch export of structured data, making it a valuable reference for developers to adapt and extend.
