Skip to content
Agentmart
Submit a tool

add-git-sync

Add git-as-state hooks to an agent — auto-commits on Stop, rebases on SessionStart, snapshots on PreCompact.

Skill by Ability.ai

IndexedApache-2.0
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/abilityai-add-git-sync

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Add git-as-state hooks to an agent — auto-commits on Stop, rebases on SessionStart, snapshots on PreCompact. Gives agents durable cross-session memory through their own repo.

Use cases: agent-building

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Shell scripts

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/add-git-sync

Tools it pre-approves 7

From allowed-tools in SKILL.md: the agent may use these without asking you each time.

  • Read,
  • Write,
  • Edit,
  • Bash,
  • Glob,
  • Grep,
  • AskUserQuestion

What's inside

Skill name
add-git-sync
Description
Add git-as-state hooks to an agent — auto-commits on Stop, rebases on SessionStart, snapshots on PreCompact. Gives agents durable cross-session memory through their own repo.
License
Apache-2.0
Allowed tools
Read,, Write,, Edit,, Bash,, Glob,, Grep,, AskUserQuestion
Metadata
author: Ability.ai · mirror: abilities@06679ae plugins/agent-dev/skills/add-git-sync · created: 2026-04-21 · version: 1.4
Instructions
269 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts
  • Pre-approves some shell commands

Files (5)

  • SKILL.md
  • git-pre-compact.sh · templates/
  • git-session-start.sh · templates/
  • git-sync-local.sh · templates/
  • git-sync.sh · templates/

SKILL.md (first lines)

# Add Git Sync

> ℹ️ **First, set expectations:** before anything else, print one short line with this skill's version and its most recent change — the top entry of `metadata.changelog` above — e.g. `add-git-sync vX.Y — recent: <summary>`. Then proceed.

Installs three hooks that turn the agent's own repo into its durable state layer:

| Hook | Event | Job |
|---|---|---|
| `git-session-start.sh` | `SessionStart` (startup/resume) | Stash local drift → fetch → rebase onto remote branch → restore drift. Every session begins consistent with origin. |
| `git-pre-compact.sh` | `PreCompact` | Fast local commit so in-flight work survives context compaction. No push. |
| `git-sync.sh` | `Stop` (async) | `git add -A` → commit → push with rebase-on-reject retry. Drops `.git/SYNC_FAILED` if it can't reconcile; SessionStart surfaces the note next run. |

**Who this is for:** any agent whose directory is its own git repo and is worked on in **local** Claude Code sessions that should leave the repo committed and pushed — authoring an agent before it is deployed, long-running local research agents. Not appropriate for agents nested inside a larger monorepo.

**Where it fits with Trinity:** Trinity deploys an agent by **cloning its GitHub repo**, so the deployed agent starts from whatever the branch tip holds. Locally, these hooks keep that tip honest — work is committed and pushed at session end instead of lingering uncommitted, so the deployed copy's own pull (or `/trinity:sync`) carries it forward. **Inside a deployed agent the hooks stand down:** the platform heartbeat owns commit-and-push there (one writer, visible in sync health — trinity-enterprise#708), and the hooks exit as soon as they see the platform (`/opt/trinity/hooks`). Committing them to the repo is harmless; they simply stay silent on Trinity.

**Escape hatches baked in:**
- `touch .git/NO_AUTOSYNC` — disables all three hooks
- `echo "..." > .git/SELF_SELECT_MSG` — subagents write structured commit messages that survive the generic Stop-hook commit
- `.git/SYNC_FAILED` — propagates push failures forward to the next session

---

## Process

### Step 1: Preflight

Run from inside the target agent directory (or ask the user for the path). Verify:

```bash
# 1. CWD has CLAUDE.md (i.e. is an agent root)
[ -f CLAUDE.md ] || ask_user_for_agent_path

# 2. CWD is a git repo root (not nested). Resolve both sides with `pwd -P`
#    so macOS /tmp vs /private/tmp symlinks don't cause a false positive.
REPO_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
if [ -z "$REPO_ROOT" ]; then
  # Not a git repo — ask whether to init
  :
elif [ "$(cd "$REPO_ROOT" && pwd -P)" != "$(pwd -P)" ]; then
  # Nested inside a larger repo — refuse or offer local-only
  echo "ERROR: Agent dir is nested inside $REPO_ROOT. Hooks would push the wrong scope."
  exit 1
fi

# 3. Does .claude/settings.json exist? (create if missing)
# 4. Do any of the target hooks already exist? (if yes, diff and ask)
```

If no `.git/`: ask "Initialize git repo here?" If yes, `git init`.

### Step 2: Ask configuration questions

Use AskUserQuestion with these three questions (in order):

**Q1 — Sync mode**
- `remote-push` (default) — Stop hook commits and pushes
- `local-only` — Stop hook commits but does not push (use when there's no remote or the agent is air-gapped)

**Q2 — Remote and branch** (only if Q1 = remote-push)
- Default: `origin` / `main`
- If `git remote get-url origin` fails, ask for the remote URL and set it up before continuing

**Q3 — Commit co-author line**
- Default: `Co-Authored-By: Claude <noreply@anthropic.com>`
- Or blank (no co-author)

### Step 3: Install hook scripts

Templates live in this skill's `templates/` directory. Copy to the agent's `.claude/hooks/` with placeholder substitution:

```bash
SKILL_DIR="$(dirname "${0}")"  # resolved at runtime
TEMPLATES="$SKILL_DIR/templates"
HOOKS_DIR="$AGENT_DIR/.claude/hooks"
mkdir -p "$HOOKS_DIR"

substitute() {
  local src="${1}" dst="${2}"
  sed -e "s|__BRANCH__|$BRANCH|g" \
      -e "s|__REMOTE__|$REMOTE|g" \
      -e "s|__COAUTHOR__|$COAUTHOR|g" \
      "$src" > "$dst"
  chmod +x "$dst"
}

if [ "$MODE" = "remote-push" ]; then
  substitute "$TEMPLATES/git-session-start.sh" "$HOOKS_DIR/git-session-start.sh"
  substitute "$TEMPLATES/git-pre-compact.sh"   "$HOOKS_DIR/git-pre-compact.sh"
  substitute "$TEMPLATES/git-sync.sh"          "$HOOKS_DIR/git-sync.sh"
else
  # local-only: no SessionStart (no remote to rebase from)
  substitute "$TEMPLATES/git-pre-compact.sh"   "$HOOKS_DIR/git-pre-compact.sh"
  substitute "$TEMPLATES/git-sync-local.sh"    "$HOOKS_DIR/git-sync.sh"
fi
```

**Idempotency:** before overwriting any existing hook file, diff content. If identical, skip silently. If different, show the diff and ask the user whether to overwrite.

### Step 4: Merge into `.claude/settings.json`

Load existing settings (create `{}` if missing), merge the `hooks` block, write back. Use `jq` to keep the JSON canonical:

```bash
SETTINGS="$AGENT_DIR/.claude/settings.json"
[ -f "$SETTINGS" ] || echo '{}' > "$SETTINGS"

# Build the hooks JSON we want to ensure is present
NEW_HOOKS=$(jq -n --arg mode "$MODE" '{
  SessionStart: (if $mode == "remote-push" then [{
    matcher: "startup|resume",
    hooks: [{
      type: "command",
      command: "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/git-session-start.sh",
      timeout: 20,
      statusMessage: "Syncing from git..."
    }]
  }] else null end),
  PreCompact: [{

From Abilityai/trinity-skills, Apache-2.0.

More from Abilityai/trinity-skills

Signals

Stars
0
Forks
1
Open issues
1
Last commit (this folder)
Oct 20, 2026 (7 days ago)
Last release
Oct 21, 2026 (6 days ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.4
License
Apache-2.0
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from Ability.ai

Cite this page

add-git-sync skill. Agent Mart. https://agentmart.dev/skills/abilityai-add-git-sync (last updated 2026-10-24)