# Skills Backup

> Use when the user asks to backup or sync their skills. This skill automatically detects the OS (Windows/Mac) and syncs the entire skills directory to the configured Git repository, handling cross-platform conflicts like line endings and paths.

- Skill: `wsxwj123/skills-backup` (Agent Skill, multi-file: 6 files)
- Install (CLI): `npx skillmds@latest add wsxwj123/skills-backup`
- Raw SKILL.md: https://api.skillmd.com/api/skills/wsxwj123/skills-backup/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: wsxwj123 (https://skillmd.com/u/wsxwj123)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/wsxwj123/skills-backup

---


# Skills Backup & Sync (Cross-Platform)

这个 Skill 用于在 Windows 和 macOS 之间自动同步 OpenCode Skills。
它解决了跨平台路径问题（`/Users/...` vs `C:\Users\...`）和换行符冲突。

## 功能
- **自动识别系统**：在 Windows 和 Mac 上都能直接运行。
- **智能同步**：先拉取（Pull）远程更新，再推送（Push）本地修改，最大程度避免冲突。
- **冲突预防**：自动创建 `.gitattributes` 处理换行符（CRLF/LF）问题。
- **特定同步**：支持只同步指定的 Skill。

## 前置要求
1. 确保 `skills` 目录是一个 Git 仓库：
   ```bash
   cd ~/.config/opencode/skills
   git init
   git remote add origin <你的GitHub仓库地址>
   ```
2. 确保已安装 Python 3。

## 使用方法
在 OpenCode 中直接告诉 AI：
- "备份 skills" (同步所有)
- "同步 skills" (同步所有)
- "备份 xlsx 技能" (仅同步 xlsx)
- "同步 writing-plans 和 theme-factory" (同步指定的两个技能)

## 自动备份 (Auto Backup)
你可以设置每小时自动备份，确保技能永不丢失。

**安装方法：**
在 OpenCode 中运行：
```python
python3 /Users/wsxwj/.config/opencode/skills/skills-backup/setup_auto_backup.py
```
或者让 AI 帮你运行："设置自动备份"。

**自动备份特性：**
- **频率**：每小时运行一次。
- **日志**：记录在 `skills-backup/logs/history.md`。
- **静默**：后台运行，不打扰工作。

## 运行原理
该 Skill 会执行 `scripts/sync_skills.py` 脚本：
1. 检测当前操作系统。
2. 检查 Git 状态。
3. 执行 `git stash` (保存未提交修改)。
4. 执行 `git pull --rebase` (拉取最新代码)。
5. 执行 `git stash pop` (恢复本地修改)。
6. 根据指令执行 `git add .` (全部) 或 `git add <skill_name>` (特定)。
7. 执行 `git commit` (提交信息包含系统名称)。
8. 执行 `git push`。

