Skip to content

Block push --delete and refspec delete syntax in agent mode#3

Closed
crcatala wants to merge 1 commit intomattzcarey:mainfrom
crcatala:block-push-delete
Closed

Block push --delete and refspec delete syntax in agent mode#3
crcatala wants to merge 1 commit intomattzcarey:mainfrom
crcatala:block-push-delete

Conversation

@crcatala
Copy link

@crcatala crcatala commented Jan 3, 2026

Problem

Agents can accidentally delete remote branches using git push --delete or the equivalent refspec syntax git push origin :<branch>. Unlike other destructive commands, there's no "safe mode" or dry-run flag for remote branch deletion - the only safe alternative is to ask the user to do it manually.

Solution

Block both deletion patterns when ZAGI_AGENT is set:

git push origin --delete feature  # blocked
git push origin :feature          # blocked (refspec syntax)

This aligns with existing guardrails for push --force, stash drop, and stash clear.

Changes

  • AGENTS.md: Added both patterns to blocked commands table
  • src/guardrails.zig:
    • New cmd_with_arg_prefix pattern type for refspec detection
    • Blocking rules for --delete, -d, and :<branch> syntax
    • 4 unit tests

Testing

zig build test  # all pass

# Manual verification:
$ ZAGI_AGENT=1 zagi push origin --delete branch
error: destructive command blocked (ZAGI_AGENT is set)
reason: deletes remote branch

$ ZAGI_AGENT=1 zagi push origin :branch  
error: destructive command blocked (ZAGI_AGENT is set)
reason: deletes remote branch (refspec syntax)

# Normal refspec still works:
$ ZAGI_AGENT=1 zagi push origin feature:feature  # allowed

Add guardrails to prevent agents from accidentally deleting remote branches.

Changes:
- AGENTS.md: Document blocked patterns
- src/guardrails.zig: Add cmd_with_arg_prefix pattern, blocking rules, and tests

Co-authored-by: Christian Catalan <crcatala@gmail.com>
mattzcarey pushed a commit that referenced this pull request Feb 18, 2026
Cherry-pick changes from PR #3 to block `git push --delete` and
`git push origin :<branch>` refspec delete syntax in agent mode.
Also reverts the task edit hint back to recommending 'tasks append'.

https://claude.ai/code/session_01B6U9cKiYt9Dr1BrK8Bg9Hk
@mattzcarey
Copy link
Owner

closed in favour of #15

Thanks for this!!!

@mattzcarey mattzcarey closed this Feb 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants