Skip to main contentgitclaw
Back up the OpenClaw agent workspace to a GitHub repo and keep it synced via a cron-driven commit/push script.
الانتقال إلى التثبيت التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
يتجاوز الأمر المباشر Prompt المخصّص للمراجعة. افحص المصدر قبل تشغيله.
npx skills add https://github.com/duclm1x1/Dive-Ai --skill gitclawيبقى الأمر في سطر واحد. مرّر أفقيًا لمراجعته كاملًا قبل النسخ.
تفضّل نسخة محلية؟ نزّل الملفات المتاحة حاليًا لدى SkillsMP.
المزيد من هذا المستودع
Persistent memory system for AI agents following Model Context Protocol (MCP). Use for storing long-term memories across sessions, semantic search of past knowledge, building knowledge graphs, auto-injecting context, deduplicating memories, syncing to cloud storage. Essential for agents that need to remember decisions, solutions, preferences, and learned patterns over time.
Persistent memory system for AI agents following Model Context Protocol (MCP). Use for storing long-term memories across sessions, semantic search of past knowledge, building knowledge graphs, auto-injecting context, deduplicating memories, syncing to cloud storage. Essential for agents that need to remember decisions, solutions, preferences, and learned patterns over time.
Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.
| name | gitclaw |
| description | Back up the OpenClaw agent workspace to a GitHub repo and keep it synced via a cron-driven commit/push script. |
| homepage | https://gitclaw.ai |
| metadata | {"openclaw":{"emoji":"🐙","homepage":"https://gitclaw.ai"}} |
GitClaw: Agent self-backup to GitHub
When to use
Use this skill automatically when it's installed or reference, and also when the user asks to:
- back up / sync / mirror the OpenClaw workspace
- set up periodic commits and pushes
- install/configure GitHub backup automation for the agent
Behavioral rule (important)
- Do everything automatically and quietly.
- Only message the user when:
- you need inputs (repo name, visibility, optional frequency), or
- Git/GH/Cron install fails, or
- GitHub auth requires the user to complete the browser/device step, or
- Git operations fail (conflicts, permissions, etc).
Inputs to ask the user for
Ask the user for:
- Repository name (e.g.,
openclaw-backup)
- Visibility:
public or private
- (Optional) Backup frequency in minutes (default: 60)
Do NOT ask for a Personal Access Token. We use auth.
gh
Step 1: Ensure prerequisites (auto-install)
1A) Ensure git is installed (auto-install; do not stop)
If missing, install using the best available method:
- If
brew exists:
- Else if
apt-get exists:
sudo apt-get update && sudo apt-get install -y git
- Else if
dnf exists:
- Else if
yum exists:
- Else if
pacman exists:
sudo pacman -S --noconfirm git
- Else if
zypper exists:
sudo zypper install -y git
- Else if
apk exists:
- Else if macOS and
xcode-select exists:
xcode-select --install (this may prompt the user)
- Else:
- Tell the user you couldn’t auto-install git on this OS and show the failing detection output.
Only notify the user if install failed.
1B) Ensure cron/crontab is available (best-effort auto-install)
If missing, attempt install:
- If
apt-get exists:
sudo apt-get update && sudo apt-get install -y cron
sudo systemctl enable --now cron || sudo service cron start || true
- Else if
dnf exists:
sudo dnf install -y cronie
sudo systemctl enable --now crond || true
- Else if
yum exists:
sudo yum install -y cronie
sudo systemctl enable --now crond || true
- Else if
pacman exists:
sudo pacman -S --noconfirm cronie
sudo systemctl enable --now cronie || true
- Else if
apk exists:
sudo apk add dcron
sudo rc-update add dcron default || true
sudo rc-service dcron start || true
- Else:
- If you can’t install, tell the user cron is required for scheduling.
Step 2: Ensure GitHub CLI (gh) is installed (auto-install)
Only notify the user if install failed.
Step 3: Ensure the user is authenticated in gh (agent runs the flow)
gh auth status --hostname github.com
-
Run:
gh auth login --hostname github.com --git-protocol https
-
The terminal flow will show a one-time code and ask the user to authorize.
-
After login:
-
Verify again:
gh auth status --hostname github.com
If auth fails, stop and report the exact terminal output.
Step 4: Initialize git in the OpenClaw workspace and connect/create the repo
Workspace dir (where you store SOUL.md, AGENTS.md, etc.):
- Example (path might be different on your environment):
WORKSPACE_DIR="$HOME/.openclaw/workspace"
-
Ensure the workspace exists:
mkdir -p "$WORKSPACE_DIR"
cd "$WORKSPACE_DIR"
-
Initialize repo if needed:
- If
.git does not exist: git init
git branch -M main
-
Configure a deterministic commit identity (local-only):
git config user.name "gitclaw.ai"
git config user.email "gitclaw-bot@users.noreply.github.com"
-
Determine the authenticated GitHub username (owner):
OWNER="$(gh api user --jq .login)"
- (Do not print unless debugging is needed)
-
Repo name and visibility:
REPO="<repo name from user>"
- Visibility:
public => --public
private => --private
-
Ensure there is at least one commit (required for first push/cron):
- Create a tiny marker file if needed:
test -f .gitclaw.keep || printf "gitclaw initialized: %s\n" "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" > .gitclaw.keep
git add -A
git commit -m "gitclaw: initial backup" || true
-
Create or reuse the target repo:
- If it exists:
gh repo view "$OWNER/$REPO" >/dev/null 2>&1
- Set remote:
REMOTE_URL="https://github.com/$OWNER/$REPO.git"
- If origin exists:
git remote set-url origin "$REMOTE_URL"
- Else:
git remote add origin "$REMOTE_URL"
- Try to fast-forward sync (avoid overwriting remote history):
git fetch origin main || true
git merge --ff-only origin/main || true
- If it does NOT exist:
- Create it non-interactively and connect it:
- Public:
gh repo create "$REPO" --public --confirm
- Private:
gh repo create "$REPO" --private --confirm
- Set remote:
REMOTE_URL="https://github.com/$OWNER/$REPO.git"
git remote add origin "$REMOTE_URL" || git remote set-url origin "$REMOTE_URL"
-
Initial push:
If push fails due to conflicts or non-fast-forward:
- Do NOT force-push automatically.
- Report the exact error and stop (user decision required).
Step 5: Install deterministic backup script (NO AI / NO heartbeat)
Create a folder outside the workspace:
mkdir -p "$HOME/.openclaw/gitclaw"
Create this script EXACTLY:
$HOME/.openclaw/gitclaw/auto_backup.sh
#!/usr/bin/env bash
set -euo pipefail
export PATH="/usr/local/bin:/opt/homebrew/bin:/usr/bin:/bin:$PATH"
WORKSPACE_DIR="${HOME}/.openclaw/workspace"
STATE_DIR="${HOME}/.openclaw/gitclaw"
LOG_FILE="${STATE_DIR}/backup.log"
LOCK_DIR="${STATE_DIR}/lock"
mkdir -p "${STATE_DIR}"
timestamp() { date -u '+%Y-%m-%dT%H:%M:%SZ'; }
if ! mkdir "${LOCK_DIR}" 2>/dev/null; then
echo "$(timestamp) Skip: already running." >> "${LOG_FILE}"
exit 0
fi
trap 'rmdir "${LOCK_DIR}" >/dev/null 2>&1 || true' EXIT
if ! command -v git >/dev/null 2>&1; then
echo "$(timestamp) ERROR: git not found on PATH. Install git first." >> "${LOG_FILE}"
exit 2
fi
if [ ! -d "${WORKSPACE_DIR}/.git" ]; then
echo "$(timestamp) ERROR: ${WORKSPACE_DIR} is not a git repo. Run GitClaw setup first." >> "${LOG_FILE}"
exit 3
fi
cd "${WORKSPACE_DIR}"
git add -A
if git diff --cached --quiet; then
echo "$(timestamp) No changes." >> "${LOG_FILE}"
exit 0
fi
git commit -m "gitclaw backup: $(timestamp)" >> "${LOG_FILE}" 2>&1
git push origin main >> "${LOG_FILE}" 2>&1
echo "$(timestamp) Backup OK." >> "${LOG_FILE}"
$HOME/.openclaw/gitclaw/auto_backup.sh
chmod +x "$HOME/.openclaw/gitclaw/auto_backup.sh"
Step 6: Configure crontab (idempotent)
Default schedule: hourly (0 * * * *). If user provided a different frequency, convert it to a cron expression.
CRON_CMD="$HOME/.openclaw/gitclaw/auto_backup.sh"
CRON_LINE="0 * * * * $CRON_CMD"
- Install without duplicates:
crontab -l 2>/dev/null | grep -F "$CRON_CMD" >/dev/null
- If not found, append:
(crontab -l 2>/dev/null; echo "$CRON_LINE") | crontab -
crontab -l | grep -F "$CRON_CMD"
Step 7: Final validation
$HOME/.openclaw/gitclaw/auto_backup.sh
tail -n 50 "$HOME/.openclaw/gitclaw/backup.log" || true
- Repo:
https://github.com/$OWNER/$REPO
- Schedule: hourly (or the chosen cadence)
- Script path:
~/.openclaw/gitclaw/auto_backup.sh
المهن ذات الصلةSOC
استنادا إلى تصنيف SOC المهني