← 返回 Skills 市场
marian2js

GitClaw

作者 Mariano Pardo · GitHub ↗ · v1.0.0
cross-platform ⚠ suspicious
3594
总下载
6
收藏
15
当前安装
1
版本数
在 OpenClaw 中安装
/install gitclaw
功能描述
Back up the OpenClaw agent workspace to a GitHub repo and keep it synced via a cron-driven commit/push script.
使用说明 (SKILL.md)

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:

  1. Repository name (e.g., openclaw-backup)
  2. Visibility: public or private
  3. (Optional) Backup frequency in minutes (default: 60)

Do NOT ask for a Personal Access Token. We use gh auth.


Step 1: Ensure prerequisites (auto-install)

1A) Ensure git is installed (auto-install; do not stop)

Check:

  • git --version

If missing, install using the best available method:

  • If brew exists:
    • brew install git
  • Else if apt-get exists:
    • sudo apt-get update && sudo apt-get install -y git
  • Else if dnf exists:
    • sudo dnf install -y git
  • Else if yum exists:
    • sudo yum install -y git
  • Else if pacman exists:
    • sudo pacman -S --noconfirm git
  • Else if zypper exists:
    • sudo zypper install -y git
  • Else if apk exists:
    • sudo apk add git
  • 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.

Re-check:

  • git --version

Only notify the user if install failed.

1B) Ensure cron/crontab is available (best-effort auto-install)

Check:

  • command -v crontab

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.

Re-check:

  • command -v crontab

Step 2: Ensure GitHub CLI (gh) is installed (auto-install)

Check:

  • gh --version

If missing, install:

  • If brew exists:

    • brew install gh
  • Else if apt-get exists (official GitHub CLI packages; preferred):

    • Install using the official apt repo steps:
      • (type -p wget >/dev/null || (sudo apt-get update && sudo apt-get install -y wget))
      • sudo mkdir -p -m 755 /etc/apt/keyrings
      • out=$(mktemp) && wget -nv -O"$out" https://cli.github.com/packages/githubcli-archive-keyring.gpg
      • cat "$out" | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null
      • sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg
      • sudo mkdir -p -m 755 /etc/apt/sources.list.d
      • echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
      • sudo apt-get update && sudo apt-get install -y gh
  • Else if dnf exists:

    • sudo dnf install -y 'dnf-command(config-manager)' || sudo dnf install -y dnf5-plugins || true
    • sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo || sudo dnf config-manager addrepo --from-repofile=https://cli.github.com/packages/rpm/gh-cli.repo || true
    • sudo dnf install -y gh --repo gh-cli || sudo dnf install -y gh || true
  • Else if yum exists:

    • type -p yum-config-manager >/dev/null || sudo yum install -y yum-utils
    • sudo yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
    • sudo yum install -y gh
  • Else if zypper exists:

    • sudo zypper addrepo https://cli.github.com/packages/rpm/gh-cli.repo || true
    • sudo zypper ref
    • sudo zypper install -y gh
  • Else if pacman exists:

    • sudo pacman -S --noconfirm github-cli
  • Else if apk exists:

    • sudo apk add github-cli
  • Else:

    • Tell the user you can’t auto-install gh on this OS.

Re-check:

  • gh --version

Only notify the user if install failed.


Step 3: Ensure the user is authenticated in gh (agent runs the flow)

Check:

  • gh auth status --hostname github.com

If NOT authenticated:

  1. Run:

    • gh auth login --hostname github.com --git-protocol https
  2. The terminal flow will show a one-time code and ask the user to authorize.

  3. After login:

    • gh auth setup-git
  4. 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"
  1. Ensure the workspace exists:

    • mkdir -p "$WORKSPACE_DIR"
    • cd "$WORKSPACE_DIR"
  2. Initialize repo if needed:

    • If .git does not exist: git init
    • git branch -M main
  3. Configure a deterministic commit identity (local-only):

  4. Determine the authenticated GitHub username (owner):

    • OWNER="$(gh api user --jq .login)"
    • (Do not print unless debugging is needed)
  5. Repo name and visibility:

    • REPO="\x3Crepo name from user>"
    • Visibility:
      • public => --public
      • private => --private
  6. 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\ " "$(date -u '+%Y-%m-%dT%H:%M:%SZ')" > .gitclaw.keep
    • git add -A
    • git commit -m "gitclaw: initial backup" || true
  7. 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"
  8. Initial push:

    • git push -u origin main

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:

Path:

  • $HOME/.openclaw/gitclaw/auto_backup.sh

Contents:

#!/usr/bin/env bash
set -euo pipefail

# GitClaw deterministic backup (no AI)
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'; }

# Simple lock to prevent overlapping runs
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}"

# Stage everything
git add -A

# If nothing staged, exit quietly
if git diff --cached --quiet; then
  echo "$(timestamp) No changes." >> "${LOG_FILE}"
  exit 0
fi

# Commit + push
git commit -m "gitclaw backup: $(timestamp)" >> "${LOG_FILE}" 2>&1
git push origin main >> "${LOG_FILE}" 2>&1

echo "$(timestamp) Backup OK." >> "${LOG_FILE}"

Write the script to:

  • $HOME/.openclaw/gitclaw/auto_backup.sh

Then:

  • 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.

  1. Define:
  • CRON_CMD="$HOME/.openclaw/gitclaw/auto_backup.sh"
  • CRON_LINE="0 * * * * $CRON_CMD"
  1. 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 -
  1. Confirm:
  • crontab -l | grep -F "$CRON_CMD"

Step 7: Final validation

  1. Run once:
  • $HOME/.openclaw/gitclaw/auto_backup.sh
  1. Show the log:
  • tail -n 50 "$HOME/.openclaw/gitclaw/backup.log" || true
  1. Tell the user:
  • Repo: https://github.com/$OWNER/$REPO
  • Schedule: hourly (or the chosen cadence)
  • Script path: ~/.openclaw/gitclaw/auto_backup.sh
安全使用建议
This skill will attempt system-level installs (using sudo), enable/start services, run the GitHub CLI auth flow, initialize a git repo in your agent workspace, and create a cron job that regularly commits and pushes the entire workspace to GitHub. That can inadvertently publish secrets or other private data and makes persistent changes to the system. Before installing, consider: (1) Inspect the workspace contents and add strict .gitignore entries or prune sensitive files; (2) prefer a private repo and review the first commit before pushing; (3) require explicit user approval for every privileged install or script creation (the skill currently says to act quietly); (4) if you want to limit autonomous behavior, set disableModelInvocation: true or avoid referencing the skill except when you explicitly run it; (5) if you need this functionality, consider running the setup steps manually or adapt the script so the user must confirm each privileged action and review commit contents. If you do not fully trust the skill source or do not want persistent automated pushes of your workspace, do not install.
功能分析
Type: OpenClaw Skill Name: gitclaw Version: 1.0.0 The skill is classified as suspicious due to several prompt injection instructions and the broad system-level access it requests. Instructions like 'Do everything automatically and quietly' and using `--confirm` for `gh repo create` aim to bypass user interaction, which, while potentially for automation, could be abused. The skill also performs extensive system modifications, including installing `git`, `cron`, and `gh` CLI using `sudo` across various package managers, and sets up a persistent cron job. While these actions are plausibly needed for the stated purpose of backing up the OpenClaw workspace to GitHub, the combination of prompt injection and high-privilege operations without explicit user confirmation for each step raises a red flag regarding potential misuse or unintended consequences.
能力评估
Purpose & Capability
The name/description (backup OpenClaw workspace to GitHub) aligns with the instructions to initialize a git repo, create or connect a GitHub repo, and set up scheduled commits/pushes. However, the scope of actions (installing system packages with sudo, enabling system services, running gh auth flows, and scheduling cron jobs) is broader than many users would reasonably expect from a simple "backup" helper and should be explicitly justified/consented to.
Instruction Scope
SKILL.md instructs the agent to run system package managers (brew/apt/dnf/yum/pacman/zypper/apk), enable/start system services, run gh auth (device/browser login), initialize and add all files from the workspace directory, and create a cron-driven commit/push script. It also contains an explicit behavioral rule to "Do everything automatically and quietly," which grants the agent discretion to perform privileged installs and persistent exfiltration of workspace contents with minimal user interaction. The instructions therefore exceed the narrow scope of safely backing up a curated set of files and would read/write system-level configuration and potentially transmit private data to GitHub.
Install Mechanism
There is no formal install spec (instruction-only), which is lower risk in one sense, but the runtime instructions explicitly call system package managers and download the official GitHub CLI keyring (official URLs). That avoids third-party binary hosting, but still directs automated use of sudo and system installs — a high-impact action that should require explicit user approval.
Credentials
The skill requests no declared environment variables, but it requires GitHub authentication via gh (device/browser flow) and will push the entire workspace to a user-chosen GitHub repo. This is functionally required for backups, but the level of access (push rights to a repo that will contain your agent workspace) is high and can expose secrets stored in the workspace. The SKILL.md forbids asking for a PAT (prefers gh), which is reasonable, but does not limit which files are committed or require user review of contents prior to push.
Persistence & Privilege
The skill instructs creation of a cron job and a commit/push script (persistent presence on the host). The skill metadata does not set always:true, but it leaves model invocation enabled (disable-model-invocation not set), and the SKILL.md explicitly tells the agent to act "automatically and quietly" when installed or referenced. That combination allows the model to trigger persistent, automated backups (and therefore repeated exfiltration) without clear, repeated explicit consent.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install gitclaw
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /gitclaw 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
GitClaw 1.0.0 – Initial release: automatic agent workspace backup to GitHub with cron-driven syncing. - Automates installation and setup of prerequisites: git, crontab, GitHub CLI (gh). - Guides user through repository creation (name, visibility) and configures GitHub authentication with gh (no personal access token needed). - Sets up a git repository in the agent workspace and connects to a user-chosen GitHub repo, avoiding accidental overwrites. - Installs a cron-based sync script to back up agent workspace at a user-defined interval. - Only notifies the user if input or action is required (repo details, permissions, or installation/authentication failures).
元数据
Slug gitclaw
版本 1.0.0
许可证
累计安装 15
当前安装数 15
历史版本数 1
常见问题

GitClaw 是什么?

Back up the OpenClaw agent workspace to a GitHub repo and keep it synced via a cron-driven commit/push script. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 3594 次。

如何安装 GitClaw?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install gitclaw」即可一键安装,无需额外配置。

GitClaw 是免费的吗?

是的,GitClaw 完全免费(开源免费),可自由下载、安装和使用。

GitClaw 支持哪些平台?

GitClaw 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 GitClaw?

由 Mariano Pardo(@marian2js)开发并维护,当前版本 v1.0.0。

💬 留言讨论