作者:互联网 时间: 2026-07-24 17:11:55
通过 GitHub 实现 Codex 跨平台对话同步(使用第三方API)。在一台设备上 push,另一台设备上 pull — Windows 与 macOS 之间的项目路径自动转换。 如果安装有问题可以问问LLM。

Windows macOS ┌──────────┐ ┌──────────┐ │ ~/.codex │ ── push ──> GitHub <── pull ── │ ~/.codex │ │ sessions │ │ sessions │ │ rules/ │ │ rules/ │ │ skills/ │ │ skills/ │ │ ... │ │ ... │ └──────────┘ └──────────┘
同步 .gitignore 未排除的所有内容(sessions、rules、skills、plugins 等)。敏感文件(auth.json、config.toml)和大文件(*.sqlite)永远不会被同步。
路径转换:通过 pathmap.conf,会话文件中的项目路径在 Windows(D:working)和 macOS(/Users/.../working)之间自动转换。
pip install pathspec(如使用后台监控还需 pip install watchdog)codex-sync)# 将本仓库克隆到 ~/.codex/ cd ~/.codex git clone https://github.com/YOUR_USERNAME/codex-sync-tools.git tools # 或直接复制以下文件: # sync.py, codex-watch.py, pathmap.conf.example, home.gitignore # 复制并配置 gitignore,修改为你需要的屏蔽的文件或文件夹 .gitignore # 配置路径映射 cp pathmap.conf.example pathmap.conf # 编辑 pathmap.conf,填入你的项目路径 # 编辑 sync.py:将 SYNC_REPO 改为你的私有同步仓库地址
关闭 Codex,然后:
python ~/.codex/sync.py push
脚本会自动初始化同步仓库并推送你的会话数据。
python ~/.codex/sync.py pull
| 命令 | 作用 |
|---|---|
| push | 将会话和文件复制到 GitHub(自动路径转换) |
| pull | 从 GitHub 拉取到本地 ~/.codex/ |
| status | 查看本地与远程会话数量对比 |
codex-watch.py 在后台运行,自动完成:
pip install watchdog python ~/.codex/codex-watch.py
Windows:将 codex-watch.vbs(先修改内部路径)放入 shell:startup。
macOS:通过 launchd 运行。
| 文件 | 用途 |
|---|---|
| sync.py | 主同步脚本(push/pull/status) |
| codex-watch.py | 后台自动同步监控(可选) |
| codex-watch.vbs | Windows 静默启动器 |
| pathmap.conf.example | 跨平台路径映射模板 |
| home.gitignore | ~/.codex/ 的 .gitignore 模板 |
pathmap.conf 定义 Windows 与 macOS 之间的项目路径对应关系:
# name = WindowsPath | macOSPath working = D:working | /Users/name/working learning = C:learning | /Users/name/learning
只有在此列出的项目才会进行路径转换,项目无关的对话不受影响。