Eddie0521/agentsync

★ 4Forks 0TypeScriptGitHub ↗Compare

README

English | 简体中文

AgentSync

A cross-AI-coding-agent session sync tool. AgentSync migrates conversation history across OpenCode, Claude Code, and Codex while preserving the full conversation context.

License Platform

Features

  • Cross-agent sync - Migrate sessions among OpenCode, Claude Code, and Codex.
  • Full context preservation - Keep messages, tool calls, timestamps, and other conversation context intact.
  • Search and filter - Search session titles by keyword.
  • Batch export - Export sessions to JSON files.
  • Dry-run preview - Preview sync results before making changes.
  • Interactive interface - Friendly TUI with multi-select workflows.
  • Skill support - Includes SKILL.md so compatible agents can invoke AgentSync directly.

Installation

One-line install

On macOS / Linux, install with:

curl -fsSL https://raw.githubusercontent.com/Edmund-a7/agentsync/main/scripts/install.sh | bash

The installer will:

  • Detect macOS / Linux and arm64 / x64 automatically.
  • Download the latest GitHub Release binary to ~/.local/bin/agentsync.
  • Ask whether ~/.local/bin should be added to your PATH.

Optional arguments:

# Install a specific version
curl -fsSL https://raw.githubusercontent.com/Edmund-a7/agentsync/main/scripts/install.sh | bash -s -- --version v0.1.0

# Use a custom install directory
curl -fsSL https://raw.githubusercontent.com/Edmund-a7/agentsync/main/scripts/install.sh | bash -s -- --install-dir /usr/local/bin

On Windows, run:

irm https://raw.githubusercontent.com/Edmund-a7/agentsync/main/scripts/install.ps1 | iex

Manual download

You can also download the binary for your platform from Releases, rename it to agentsync (agentsync.exe on Windows), and place it in a directory on your PATH.

Build from source

# Clone the repository
git clone https://github.com/Edmund-a7/agentsync.git
cd agentsync

# Install dependencies
bun install

# Build
bun run build

# The compiled binary is generated in dist/

Quick Start

Interactive mode

Run agentsync to open the interactive interface:

agentsync

Workflow:

  1. Choose the source agent.
  2. Choose one or more target agents with Space, or press a to select all.
  3. Choose the sessions to sync.
  4. Review the result after sync completes.

CLI mode

List sessions

# List all sessions
agentsync list claude-code

# Output JSON
agentsync list opencode --json

View session details

agentsync view claude-code <session-id>

# JSON output
agentsync view codex <session-id> --json

Search sessions

# Search by keyword
agentsync search claude-code "html"

# Limit result count
agentsync search opencode "project" --limit 5

Export sessions

agentsync export claude-code <session-id> -o /path/to/output.json

Sync sessions

# Sync one session
agentsync sync -s claude-code -t opencode -i <session-id>

# Sync to multiple targets
agentsync sync -s claude-code -t "opencode,codex" -i <session-id>

# Sync multiple sessions, up to 10
agentsync sync -s claude-code -t opencode -i "id1,id2,id3"

# Dry-run preview
agentsync sync -s claude-code -t opencode -i <session-id> --dry-run

# JSON result
agentsync sync -s claude-code -t opencode -i <session-id> --json

Update and uninstall

# Update to the latest version
agentsync update

# Preview the release asset that would be downloaded
agentsync update --dry-run

# Install a specific version
agentsync update --version v0.1.0

# Uninstall
agentsync uninstall

# Non-interactive uninstall
agentsync uninstall --yes

Common Use Cases

Case 1: Migrate from Claude Code to OpenCode

# 1. List Claude Code sessions
agentsync list claude-code

# 2. Find the session ID and sync it
agentsync sync -s claude-code -t opencode -i abc-123-def

# Or preview first with dry-run
agentsync sync -s claude-code -t opencode -i abc-123-def --dry-run

Case 2: Batch migrate multiple sessions

# Get all session IDs
agentsync list claude-code --json | jq -r '.[].id'

# Sync the first 5 sessions
agentsync sync -s claude-code -t opencode -i "id1,id2,id3,id4,id5"

Case 3: Back up sessions to files

# Export one session
agentsync export claude-code <session-id> -o backup.json

# Batch export with a shell script
for id in $(agentsync list claude-code --json | jq -r '.[].id'); do
  agentsync export claude-code $id -o "backups/$id.json"
done

How It Works

AgentSync reads each agent's local database or files, converts sessions into a unified internal format, and writes them into the target agent.

Supported Agents

Agent Read Source Write Target
OpenCode SQLite database (~/.local/share/opencode/opencode.db) opencode import command
Claude Code JSONL files (~/.claude/projects/) JSONL files
Codex SQLite + JSONL (~/.codex/) JSONL + database

Data Filtering

AgentSync automatically filters system-injected messages during sync:

  • <environment_context>
  • # AGENTS.md instructions
  • <skill>, <subagent_notification>

This ensures the target agent shows real user messages instead of system metadata.

Idempotency and Resync

  • AgentSync normalizes session content before checking whether it has already been imported. Re-syncing the same session will not silently create duplicate copies.
  • If you migrated from an earlier version and already have broken imported data with malformed titles, system-message pollution, or unstable restore behavior, delete the bad data and sync again.
  • Pre-release verification is based on clean fixtures and local smoke tests. It does not guarantee that historically corrupted data can be repaired in place.

Skill Integration

This project includes SKILL.md, which can be invoked directly by agents that support MCP (Model Context Protocol).

Trigger examples:

  • "Migrate Claude Code sessions to OpenCode"
  • "Export the current session to another agent"
  • "Sync conversation history"
  • "Back up sessions"

Place SKILL.md in the agent's skills directory to use it.

Command Reference

Command Description Example
agentsync Start the interactive interface agentsync
agentsync list <agent> List sessions agentsync list claude-code
agentsync view <agent> <id> View session details agentsync view opencode abc-123
agentsync search <agent> <keyword> Search sessions agentsync search codex "project"
agentsync export <agent> <id> Export a session agentsync export claude-code abc-123 -o out.json
agentsync sync Sync sessions agentsync sync -s claude-code -t opencode -i abc-123
agentsync update Update an installed binary agentsync update
agentsync uninstall Uninstall an installed binary agentsync uninstall --yes

Global Options

  • --json - Output JSON.
  • -h, --help - Show help.

sync Options

  • -s, --source <agent> - Source agent.
  • -t, --target <agents> - Target agents, separated by commas.
  • -i, --ids <ids> - Session IDs, separated by commas. Supports up to 10 sessions.
  • --dry-run - Preview mode.

update / uninstall Notes

  • agentsync update only supports installed standalone binaries. It does not support bun run src/index.ts.
  • agentsync uninstall asks for confirmation by default. Use --yes in CI or scripts.
  • The default Unix install directory is ~/.local/bin. You can override it with AGENTSYNC_INSTALL_DIR or an installer argument.

Tech Stack

  • TypeScript - Type safety.
  • Bun - Runtime and build tooling.
  • Commander - CLI framework.
  • Clack - Interactive prompts.
  • bun:sqlite - SQLite database access.

Development

# Install dependencies
bun install

# Development mode
bun run dev

# Build a binary
bun run build

# Typecheck
bun run typecheck

# Test
bun test

# Pre-release check: typecheck + test + build
bun run release-check

bun run build also generates dist/SHA256SUMS, which helps verify release artifacts.

FAQ

Q: Why does the target agent show garbled session titles after sync? A: The source agent session may contain system-injected messages. Use the latest version, which filters these messages automatically.

Q: Can I sync an active session? A: Yes, but it is better to finish the current conversation first so all context is captured.

Q: Does sync delete sessions from the source agent? A: No. Sync is read-only for source data.

Q: Can AgentSync sync to other tools? A: AgentSync currently supports OpenCode, Claude Code, and Codex. PRs for additional agents are welcome.

Contributing

Issues and PRs are welcome.

License

MIT License. See LICENSE for details.

Acknowledgements

Thanks to these open source projects:

Contributors

Eddie0521

Issues