ln-004-agent-config-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePaths: File paths (,shared/,references/) are relative to skills repo root. If not found at CWD, locate this SKILL.md directory and go up one level for repo root.../ln-*
路径说明: 文件路径(、shared/、references/)均相对于skills仓库根目录。如果在当前工作目录(CWD)中未找到,请定位到本SKILL.md所在目录,再向上一级即为仓库根目录。../ln-*
Agent Sync (Standalone Utility)
Agent 同步工具(独立实用程序)
Type: Standalone Utility
Category: 0XX Shared
Synchronizes skills and MCP server configurations from Claude Code (source of truth) to Gemini CLI and Codex CLI. Creates symlinks for skills, copies/converts MCP settings.
类型: 独立实用程序
分类: 0XX 共享工具
将Claude Code(可信数据源)中的skills和MCP服务器配置同步到Gemini CLI和Codex CLI。为skills创建符号链接,复制/转换MCP设置。
When to Use This Skill
何时使用该工具
- After adding/removing MCP servers in Claude Code settings
- After installing new plugins in Claude Code
- First-time setup of Gemini CLI or Codex CLI alongside Claude Code
- Periodic sync to keep all agents aligned
- 在Claude Code设置中添加/移除MCP服务器后
- 在Claude Code中安装新插件后
- 首次搭配Claude Code配置Gemini CLI或Codex CLI时
- 定期同步以保持所有Agent配置一致
Input Parameters
输入参数
| Parameter | Required | Default | Description |
|---|---|---|---|
| targets | No | both | |
| mode | No | full | |
| dry_run | No | false | Show planned actions without executing |
| 参数 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|
| targets | 否 | both | 可选值: |
| mode | 否 | full | 可选值: |
| dry_run | 否 | false | 显示计划执行的操作但不实际执行 |
Workflow
工作流程
Detect OS → Discover Configs → Sync Skills → Sync MCP → Report检测操作系统 → 发现配置信息 → 同步Skills → 同步MCP设置 → 生成报告Phase 0: OS Detection
阶段0:操作系统检测
| Check | Result | Impact |
|---|---|---|
| win32 / darwin / linux | Junction vs symlink |
| Home directory | | Config paths |
Paths by OS:
| Agent | Windows | macOS / Linux |
|---|---|---|
| Claude | | |
| Gemini | | |
| Codex | | |
| 检查项 | 结果 | 影响 |
|---|---|---|
| win32 / darwin / linux | 决定使用快捷方式还是符号链接 |
| 主目录 | | 配置文件路径 |
各系统对应的路径:
| Agent | Windows | macOS / Linux |
|---|---|---|
| Claude | | |
| Gemini | | |
| Codex | | |
Phase 1: Discover Current State
阶段1:发现当前状态
-
Read Claude settings:
- Parse → extract
~/.claude/settings.jsonblockmcpServers - If no → WARN "No MCP servers configured in Claude", skip MCP sync
mcpServers
- Parse
-
Read target configs (if exist):
- Gemini: Parse → extract existing
~/.gemini/settings.jsonmcpServers - Codex: Parse → extract existing
~/.codex/config.toml[mcp_servers.*]
- Gemini: Parse
-
Detect installed plugins:
- Glob → list plugin directories
~/.claude/plugins/*/plugin.json - Also check if skills repo itself is a plugin source
- Glob
-
Check existing symlinks:
- → exists? points where?
~/.gemini/skills - → exists? points where?
~/.codex/skills
-
Show current state:
Current State: | Agent | Skills | MCP Servers | Config Exists | |-------|--------|-------------|---------------| | Claude (source) | 5 plugins | 4 servers | yes | | Gemini | no link | 2 servers | yes | | Codex | → ~/.claude/plugins | 4 servers | yes |
-
读取Claude设置:
- 解析→ 提取
~/.claude/settings.json模块mcpServers - 如果未找到→ 警告"Claude中未配置MCP服务器",跳过MCP同步步骤
mcpServers
- 解析
-
读取目标配置(如果存在):
- Gemini:解析→ 提取已有的
~/.gemini/settings.jsonmcpServers - Codex:解析→ 提取已有的
~/.codex/config.toml[mcp_servers.*]
- Gemini:解析
-
检测已安装的插件:
- 遍历→ 列出插件目录
~/.claude/plugins/*/plugin.json - 同时检查skills仓库本身是否为插件源
- 遍历
-
检查已有的符号链接:
- → 是否存在?指向何处?
~/.gemini/skills - → 是否存在?指向何处?
~/.codex/skills
-
显示当前状态:
当前状态: | Agent | Skills | MCP 服务器 | 配置是否存在 | |-------|--------|-------------|---------------| | Claude(数据源) | 5个插件 | 4台服务器 | 是 | | Gemini | 无链接 | 2台服务器 | 是 | | Codex | → ~/.claude/plugins | 4台服务器 | 是 |
Phase 2: Sync Skills (symlinks/junctions)
阶段2:同步Skills(符号链接/快捷方式)
FOR EACH target IN (gemini, codex) WHERE target in targets:
-
Determine link path:
- Gemini:
~/.gemini/skills - Codex:
~/.codex/skills
- Gemini:
-
Check if already linked correctly:
- IF link exists AND points to correct source → SKIP (already synced)
- IF link exists AND points to wrong source → WARN, ask user before replacing
- IF regular directory (not link) exists → WARN "Target is a real directory, not a link. Skip to avoid data loss."
-
Determine source:
- IF single plugin: link directly to plugin dir
- IF multiple plugins: ask user which plugin to share
-
Create link:
OS Command Windows cmd /c mklink /J "{target_path}" "{source_path}"macOS / Linux ln -s "{source_path}" "{target_path}" -
Verify: Check link exists and resolves correctly
针对每个在targets列表中的目标(gemini、codex)执行以下操作:
-
确定链接路径:
- Gemini:
~/.gemini/skills - Codex:
~/.codex/skills
- Gemini:
-
检查是否已正确链接:
- 如果链接已存在且指向正确的源 → 跳过(已同步)
- 如果链接已存在但指向错误的源 → 发出警告,询问用户后再替换
- 如果存在的是普通目录(而非链接) → 警告"目标为真实目录,而非链接。为避免数据损失,将跳过该操作。"
-
确定源路径:
- 如果是单个插件:直接链接到该插件目录
- 如果是多个插件:询问用户要共享哪个插件
-
创建链接:
操作系统 命令 Windows cmd /c mklink /J "{target_path}" "{source_path}"macOS / Linux ln -s "{source_path}" "{target_path}" -
验证: 检查链接是否存在且指向正确
Phase 3: Sync MCP Settings
阶段3:同步MCP设置
Source: → block
~/.claude/settings.jsonmcpServers数据源: 中的 模块
~/.claude/settings.jsonmcpServers3a: Claude → Gemini (JSON → JSON)
3a:Claude → Gemini(JSON → JSON)
- Read Claude as JSON object
mcpServers - Read Gemini (or create
settings.jsonif missing){} - Merge strategy: Claude servers override Gemini servers by key name. Gemini-only servers preserved.
- Write updated
settings.json
Conversion: None needed — identical format.
- 读取Claude的JSON对象
mcpServers - 读取Gemini的(如果不存在则创建空对象
settings.json){} - 合并策略: Claude中的服务器将覆盖Gemini中同名的服务器配置。仅存在于Gemini中的服务器配置将被保留。
- 写入更新后的
settings.json
格式转换: 无需转换——两者格式完全一致。
3b: Claude → Codex (JSON → TOML)
3b:Claude → Codex(JSON → TOML)
-
Read Claudeas JSON object
mcpServers -
Read Codex(or create empty if missing)
config.toml -
Convert each server:
Claude JSON field Codex TOML field Notes commandcommandSame argsargsJSON array → TOML array env[mcp_servers.{name}.env]Nested table +type: "http"urlurlHTTP transport +type: "sse"urlurlSSE transport Example conversion:json"context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"] }toml[mcp_servers.context7] command = "npx" args = ["-y", "@upstash/context7-mcp"] -
Merge strategy: Claude servers override. Codex-only servers preserved.
-
Write updated
config.toml
Unsupported conversions (preserve as-is in Codex):
- — no Claude equivalent
bearer_token_env_var - /
enabled_tools— no Claude equivalentdisabled_tools
-
读取Claude的JSON对象
mcpServers -
读取Codex的(如果不存在则创建空文件)
config.toml -
转换每个服务器配置:
Claude JSON 字段 Codex TOML 字段 说明 commandcommand保持不变 argsargsJSON数组 → TOML数组 env[mcp_servers.{name}.env]嵌套表 +type: "http"urlurlHTTP传输协议 +type: "sse"urlurlSSE传输协议 转换示例:json"context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"] }toml[mcp_servers.context7] command = "npx" args = ["-y", "@upstash/context7-mcp"] -
合并策略: Claude中的服务器将覆盖Codex中同名的服务器配置。仅存在于Codex中的服务器配置将被保留。
-
写入更新后的
config.toml
不支持的转换(将在Codex中保持原样):
- —— Claude中无对应字段
bearer_token_env_var - /
enabled_tools—— Claude中无对应字段disabled_tools
Phase 4: Report
阶段4:生成报告
Sync Complete:
| Action | Target | Status |
|--------|--------|--------|
| Skills symlink | Gemini | Created → ~/.claude/plugins/... |
| Skills symlink | Codex | Already linked |
| MCP sync | Gemini | 4 servers synced (2 new, 2 updated) |
| MCP sync | Codex | 4 servers synced (1 new, 3 updated) |同步完成:
| 操作 | 目标 | 状态 |
|--------|--------|--------|
| Skills符号链接 | Gemini | 已创建 → ~/.claude/plugins/... |
| Skills符号链接 | Codex | 已链接 |
| MCP同步 | Gemini | 4台服务器已同步(2台新增,2台更新) |
| MCP同步 | Codex | 4台服务器已同步(1台新增,3台更新) |Critical Rules
核心规则
- Claude = source of truth. Never write TO Claude settings. Read-only source.
- Non-destructive merge. Target-only servers/settings preserved. Only Claude servers added/updated.
- No data loss. If target is a real directory (not symlink) — warn and skip, never delete.
- Backup before write. Before modifying any config file, create copy.
.bak - Dry run first. If , show all planned actions without executing.
dry_run=true - Ask on conflict. If symlink points to different source — ask user, don't auto-replace.
- Claude 是可信数据源。 绝不向Claude的设置中写入数据。仅作为只读数据源。
- 非破坏性合并。 仅存在于目标Agent中的服务器/配置将被保留。仅添加/更新来自Claude的服务器配置。
- 无数据损失。 如果目标路径是真实目录(而非符号链接)——发出警告并跳过操作,绝不删除任何内容。
- 写入前备份。 在修改任何配置文件前,创建备份文件。
.bak - 先执行试运行。 如果,仅显示所有计划执行的操作但不实际执行。
dry_run=true - 冲突时询问用户。 如果符号链接指向错误的源——询问用户,不自动替换。
Anti-Patterns
反模式
- Writing TO Claude settings from Gemini/Codex (reverse sync)
- Deleting target-only MCP servers during sync
- Creating symlinks inside symlinks (circular)
- Modifying config files without backup
- 从Gemini/Codex向Claude写入设置(反向同步)
- 同步时删除仅存在于目标Agent中的MCP服务器
- 在符号链接内部创建符号链接(循环引用)
- 不备份就修改配置文件
Definition of Done
完成标准
| # | Criterion |
|---|---|
| 1 | Claude settings read successfully |
| 2 | Skills symlinks created/verified for each target |
| 3 | MCP settings synced with format conversion (JSON→TOML for Codex) |
| 4 | Backup files created before any config modification |
| 5 | Report shown with all actions and warnings |
Version: 1.0.0
Last Updated: 2026-02-15
| 序号 | 判定标准 |
|---|---|
| 1 | 成功读取Claude的设置 |
| 2 | 为每个目标Agent创建/验证Skills符号链接 |
| 3 | 完成MCP设置同步及格式转换(Codex需JSON→TOML转换) |
| 4 | 修改任何配置文件前已创建备份文件 |
| 5 | 生成包含所有操作和警告的报告 |
版本: 1.0.0
最后更新时间: 2026-02-15