session-convert
Enables conversion of coding agent sessions between Claude Code, Codex CLI, and OpenCode, including full support for OpenCode's SQLite storage.
README
session-convert
MCP server that converts coding agent sessions between Claude Code, Codex CLI, and OpenCode.
The only tool that supports OpenCode SQLite session conversion — agent-convert and ctxmv handle Claude↔Codex but nothing touches OpenCode's .opencode/opencode.db.
What problem does this solve?
You're using multiple AI coding agents (Claude Code, Codex CLI, OpenCode) and want to migrate a session from one to another — maybe you started in Claude Code but want to continue in OpenCode, or you found a great Codex session that would be useful in Claude.
Each agent stores sessions differently:
- Claude Code — JSONL files in
~/.claude/projects/<hash>/sessions/ - Codex CLI — Rollout JSONL in
~/.codex/sessions/YYYY/MM/DD/ - OpenCode — SQLite database in
<project>/.opencode/opencode.db
This MCP server reads from any of these, normalizes into a unified format, and writes to any other. All 6 conversion directions work (Claude→Codex, Claude→OpenCode, Codex→Claude, Codex→OpenCode, OpenCode→Claude, OpenCode→Codex).
Quick Start
git clone https://github.com/megamen32/session-convert.git
cd session-convert
npm install
npm run build
MCP Configuration
Add to your MCP client config (Claude Desktop, Cursor, Windsurf, etc.):
Claude Desktop (claude_desktop_config.json):
{
"mcpServers": {
"session-convert": {
"command": "node",
"args": ["/absolute/path/to/session-convert/dist/index.js"]
}
}
}
Cursor / Windsurf (.cursor/mcp.json or equivalent):
{
"mcpServers": {
"session-convert": {
"command": "node",
"args": ["/absolute/path/to/session-convert/dist/index.js"]
}
}
}
MCP Tools
list_sessions
List available sessions from a harness. Filter by working directory prefix.
list_sessions({ harness: "claude", cwdPrefix: "~/apps" })
list_sessions({ harness: "codex" })
list_sessions({ harness: "opencode", searchPaths: ["~/projects"] })
convert_session
Convert a session from one harness to another by session ID.
convert_session({ from: "claude", to: "opencode", sessionId: "abc-123" })
convert_session({ from: "codex", to: "claude", sessionId: "xyz-789" })
convert_session({ from: "opencode", to: "codex", sessionId: "oc-session-1", projectPath: "/path/to/project" })
preview_conversion
Dry-run a conversion — shows message breakdown, tool call stats, and compatibility warnings without writing anything.
preview_conversion({ from: "claude", to: "opencode", sessionId: "abc-123" })
convert_by_path
Convert a session file by its direct path. Auto-detects the format (Claude JSONL, Codex rollout JSONL, or OpenCode .db).
convert_by_path({ sourcePath: "/home/user/.claude/projects/.../sessions/abc.jsonl", to: "codex" })
convert_by_path({ sourcePath: "/home/user/myproject/.opencode/opencode.db", to: "claude" })
Conversion Matrix
| From \ To | Claude Code | Codex CLI | OpenCode |
|---|---|---|---|
| Claude Code | — | ✅ | ✅ |
| Codex CLI | ✅ | — | ✅ |
| OpenCode | ✅ | ✅ | — |
What Gets Preserved
| Content type | Claude → Codex | Claude → OpenCode | Codex → Claude | Codex → OpenCode | OpenCode → Claude | OpenCode → Codex |
|---|---|---|---|---|---|---|
| Text messages | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Tool calls (name + args) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Tool results | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Thinking / reasoning | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Images | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Session metadata (CWD, timestamps) | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Model name | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
| Token usage | Approx | Approx | ✅ | Approx | Approx | Approx |
How It Works
Source format → Unified Conversation → Target format
(JSONL/SQLite) (typed Messages) (JSONL/SQLite)
- Read — Parse the source session (Claude JSONL, Codex rollout JSONL, or OpenCode SQLite) into a unified
Conversationobject with typedMessageparts (text,tool_call,tool_result,thinking,image) - Transform — Map content types between format-specific representations (e.g., Claude's
tool_use↔ Codex'sfunction_call↔ OpenCode's double-wrappedtool_callpart) - Write — Serialize to the target harness's native format and store it in the correct location
Format-Specific Details
- Claude Code stores sessions as one JSON object per line in
.jsonlfiles. Tool calls aretool_useblocks, results aretool_resultblocks in the next user message. Thinking blocks are stored asthinkingcontent type. - Codex CLI uses a
session_metaheader line followed byresponse_itementries. Tool calls are separatefunction_callitems with matchingfunction_call_outputitems. Reasoning is a separatereasoningitem type. - OpenCode uses SQLite with a
sessionstable and amessagestable. Parts are stored as JSON in a double-wrapped format:[{ "type": "text", "data": { "text": "..." } }]. This is the trickiest format and the main reason this tool exists.
Testing
# Create the OpenCode SQLite test fixture
npm run test:fixtures
# Run all 34 tests (covers all 6 conversion directions + edge cases)
npm test
# Watch mode
npm run test:watch
Tests use 3 hand-crafted mini-sessions (one per harness) that include text, thinking, tool_call, and tool_result content parts. Each test reads from a fixture, writes to a target format, then reads back to verify roundtrip integrity.
Known Limitations
- Encrypted Codex reasoning (
encrypted_content) cannot be decrypted — only summary text is preserved - Claude sub-agent sessions (Task tool spawning child sessions) are not followed — only the parent conversation converts
- Token usage is approximate when cross-converting (different tokenizers per provider)
- OpenCode must be restarted to discover newly imported sessions
- System messages are dropped for Claude (not stored in JSONL) or converted to user messages for Codex
Comparison with Alternatives
| Feature | session-convert | agent-convert | ctxmv |
|---|---|---|---|
| Claude Code read/write | ✅ | ✅ | ✅ |
| Codex CLI read/write | ✅ | ✅ | ✅ |
| OpenCode read/write | ✅ | ❌ | ❌ |
| MCP interface | ✅ | ❌ | ❌ |
| SQLite support | ✅ | ❌ | ❌ |
| Session preview | ✅ | ❌ | ❌ |
| Path-based conversion | ✅ | ✅ | ❌ |
Keywords
mcp server, claude code session export, codex cli session migration, opencode session convert, ai coding agent session transfer, claude to codex, claude to opencode, codex to claude, opencode to claude, session migration tool, coding agent context switch, mcp tool, model context protocol, session converter, ai agent session backup, claude jsonl, codex rollout jsonl, opencode sqlite, coding session portability
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。