cd /news/developer-tools/opencode-commands-safe-git-commit-an… · home topics developer-tools article
[ARTICLE · art-28031] src=gist.github.com ↗ pub= topic=developer-tools verified=true sentiment=· neutral

OpenCode commands: /safe-git-commit and /clear-safe-git — safe git commits with automatic backup snapshots

OpenCode introduced two new commands, /safe-git-commit and /clear-safe-git, that enable developers to safely commit changes with automatic backup snapshots. The /safe-git-commit command creates a backup ref before staging and committing, allowing recovery if anything goes wrong. The /clear-safe-git command cleans up backup refs when no longer needed.

read1 min publishedJun 15, 2026

| description | Safely commit changes with automatic backup snapshot | | agent | build |

!`BRANCH=$(git rev-parse --abbrev-ref HEAD) && BASE=$(git rev-parse HEAD) && REF_NAME="$BRANCH-$(date +%s)-$$" && ORIG_INDEX=$(git write-tree) && git add -A && STASH=$(git stash create -u) && git read-tree $ORIG_INDEX && if [ -n "$STASH" ]; then git update-ref "refs/safe-git/$REF_NAME" $STASH && printf 'BACKUP CREATED\nBase: %s\nStash: %s\nRef: refs/safe-git/%s\nRecovery: "git reset --hard %s && git stash apply --index refs/safe-git/%s && git update-ref -d refs/safe-git/%s"\nCleanup: "git update-ref -d refs/safe-git/%s"\n' "$BASE" "$STASH" "$REF_NAME" "$BASE" "$REF_NAME" "$REF_NAME" "$REF_NAME"; else echo 'NO CHANGES — working tree is clean. Nothing to snapshot.'; fi`

If the output above says NO CHANGES, tell the user "Nothing to snapshot — working tree is clean" and stop. Do nothing else.

If the output says BACKUP CREATED, follow this procedure:

Echo the recovery and cleanup commands to the user BEFORE making any changes. Copy the exact Recovery and Cleanup lines from the output above and show them to the user. This ensures they can recover or clean up manually if needed.

Process the current changes and split them into logical, well-described commits. Stage hunks, make individual commits with meaningful messages.

If anything goes wrong — a bad commit, incorrect staging, validation failure, or any error — run the recovery commands shown above to automatically restore the working directory and staging area (to the state before any changes were made). Then stop and report what happened.

Do NOT clean up the backup ref automatically after committing. Leave the backup ref in place. Only delete it if the user explicitly asks with a command like "clean up the backup" or by running the Cleanup command themselves.

── more in #developer-tools 4 stories · sorted by recency
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/opencode-commands-sa…] indexed:0 read:1min 2026-06-15 ·