/install nini-code-sync
Code Sync
Batch sync all git repos under a base directory — push (end-of-day) or pull (start-of-day).
Default base directory: ~/code. Configurable via ~/.config/nini-skill/code-sync/config.md.
Prerequisites
| Tool | Type | Required | Install |
|---|---|---|---|
| git | cli | Yes | brew install git or git-scm.com |
| git-workflow | skill | Yes | Included in npx skills add niracler/skill — must be invoked via Skill tool for all commits |
Do NOT proactively verify these tools on skill load. If a command fails due to a missing tool, directly guide the user through installation and configuration step by step.
First-Time Setup
On first use, check for config at ~/.config/nini-skill/code-sync/config.md.
If not found, ask the user:
- "Where do you keep your git repos?" (default:
~/code) - "What's the directory structure?" — explain the expected pattern:
\x3Cbase-dir>/*/for top-level repos and\x3Cbase-dir>/*/repos/*/for monorepo sub-repos - Save to
~/.config/nini-skill/code-sync/config.md:
base_dir: ~/code
Mode Selection
| User says | Mode |
|---|---|
| 「下班同步」or "push" | Push |
| 「上班更新」or "pull" | Pull |
| 「同步代码」「code-sync」 | Ask user |
Workflow (shared by both modes)
- Scan → 2. Categorize → 3. Batch action (auto, no confirmation) → 4. Handle exceptions (interactive) → 5. Summary
If all repos are up-to-date, report that and stop.
Scan
bash scripts/scan.sh # Push: local data only (default ~/code)
bash scripts/scan.sh --fetch # Pull: fetch remote first (10s timeout/repo)
bash scripts/scan.sh --base-dir /path/to/dir # Custom base directory
Output: JSON array with fields path, name, branch, remote, remote_url, dirty_count, has_upstream, ahead, behind, and fetch_error (only on --fetch failure).
Categorize
Push mode:
| Category | Condition | Action |
|---|---|---|
| up-to-date | dirty_count == 0 && ahead == 0 |
Report |
| needs-push | dirty_count == 0 && ahead > 0 |
Auto git push |
| dirty | dirty_count > 0 |
Interactive |
| no-upstream | has_upstream == false |
Ask user |
Pull mode:
| Category | Condition | Action |
|---|---|---|
| up-to-date | dirty_count == 0 && behind == 0 |
Report |
| needs-pull | dirty_count == 0 && behind > 0 |
Auto git pull --ff-only |
| dirty+behind | dirty_count > 0 && behind > 0 |
Interactive |
| fetch-error | fetch_error == true |
Report, skip |
Exception Handling
| Situation | Steps |
|---|---|
| Dirty repo (push) | git diff --stat + git status → describe to user → ask: commit, stash, or skip. If commit, MUST invoke git-workflow skill via Skill tool — never run git commit directly. |
| No upstream (push) | Report → ask: set upstream and push (git push -u origin \x3Cbranch>), or skip |
| ff-only fails (pull) | git log --oneline HEAD..@{u} + @{u}..HEAD → explain divergence → suggest: rebase, merge, or skip |
| Dirty + behind (pull) | Report both issues → ask: stash and pull (stash, pull --ff-only, pop), or skip |
Summary
Group repos by outcome after all operations complete:
## {Push|Pull} Summary
{Pushed|Updated} (N):
- repo-name (branch, N commits)
Already up-to-date (N):
- repo-a, repo-b, ...
Resolved (N):
- repo-c: action taken
Skipped (N):
- repo-d: reason
Common Issues
| Issue | Fix |
|---|---|
scan.sh finds 0 repos |
Check ~/code/*/ has git repos |
fetch_error |
Check network, SSH keys |
| ff-only fails | Rebase or merge manually |
| Push rejected | Pull first, then push |
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install nini-code-sync - 安装完成后,直接呼叫该 Skill 的名称或使用
/nini-code-sync触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
Code Sync 是什么?
Use this skill to batch-sync all git repos across machines — pushing uncommitted changes at end of day or pulling latest at start of day. Invoke when the use... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 425 次。
如何安装 Code Sync?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install nini-code-sync」即可一键安装,无需额外配置。
Code Sync 是免费的吗?
是的,Code Sync 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Code Sync 支持哪些平台?
Code Sync 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Code Sync?
由 Niracler(@niracler)开发并维护,当前版本 v0.3.0。