Use case · Protect

# My agent pushed straight to main. *Now it stops and offers a branch.*

With the Balanced preset, Protect stops pushes to main, master, production and release/*, and every force push. Your agent offers to push a branch and open a pull request instead.

[Get started free](https://console.context-mode.com/login) [Read the docs](https://context-mode.com/docs/protect#pack-production)

Your agent runs

git push origin main git push --force Push a branch Your protected branches

You say: push straight to main so CI can publish.

Blocked · never reaches your shell **Push to protected branches**

main, master, production and release/*. Blocked in Balanced and Locked down.

```
⛔ context-mode Protect blocked this command, so it was NOT executed:
Blocked by your team’s policy: Push to protected branches. Protected branches change through reviewed pull requests.
```

The push never reaches your shell. The agent says so and offers a branch.

The agent force pushes over a shared branch.

Blocked · never reaches your shell **Rewrite shared history**

git push --force, -f and +ref, on any branch.

```
⛔ context-mode Protect blocked this command, so it was NOT executed:
Blocked by your team’s policy: Rewrite shared history. Force pushes overwrite other people’s work.
```

A separate rule from the main block, in the same pack.

You ask for a branch. The agent pushes release-prep for review.

Runs **No rule matches**

release-prep is not a protected branch.

```
$ git push origin release-prep
```

The agent then prints a gh pr create command for you. From the live run in the Protect docs.

You choose which branches count.

Branch *main* *master* *production* *release/** *feature/x*

Protected by default: main, master, production, release/*. A push to feature/x runs. Match by exact name or by the start of the name. Removing one asks for a reason.

The problem

## You asked for a release. *It went to main.*

**It skips review**

You say "push straight to main so CI can publish". The agent does it, with no pull request.

**It forces its way**

In one long session, an agent can run `git push --force`. Force pushes overwrite other people's work.

**Git lets it**

Git by itself takes the same `git push origin main`. Nothing asks you first.

How it works

## Checked before it runs. *Branches still ship.*

1. 01 **Turn on Protect** In the console, open Protect, turn it on, and pick the Balanced or Locked down preset. Both block the two push rules.
2. 02 **The agent asks to push** Protect reads the git push and its target before your client runs it. A push to a protected branch, or with force, never reaches your shell.
3. 03 **The model reads why** The refusal names the rule and tells the agent not to retry another way. The agent then offers to push a branch and open a pull request.

**Your agent**Asks to run `git push origin main`.

→

**Context Mode · Protect**Checks the call before your client runs it.

- Push to protected branches: blocked
- Rewrite shared history: blocked
- Push to release-prep: runs

→

**The model**Reads the refusal as the tool result, and offers a branch instead.

Your agent asks to push. Protect, in blue, decides before the shell runs anything. Main does not move.

Proof

## A real release chore. *Main did not move.*

**Main did not move** in every live run, with Claude Opus 5.5 and Claude Haiku 4.5. The push was blocked, and the branch landed when you asked for it.

**2 rules** one for protected branches, one for force pushes, both on in Balanced and Locked down

| The agent runs | With Protect (Balanced) | Rule |
| --- | --- | --- |
| `git push origin main` | Blocked | Push to protected branches |
| git push to master, production or release/* | Blocked | Push to protected branches |
| `git push --force` , `-f` or `+ref` | Blocked | Rewrite shared history |
| `git push origin feature/x` | Runs | No rule matches |

The live runs are in the Protect docs, with the setup and prompts so you can repeat them in 5 minutes. Check it yourself: the remote main matches the hash you saved before the agent started. [Method and sources →](https://context-mode.com/docs/protect#try-it) The API checks: [how we tested Protect](https://context-mode.com/blog/protect-rules-for-coding-agents).

Products used

## What this *uses.*

**[Protect](https://context-mode.com/protect)**

Checks every tool call before your terminal runs it. In every plan, off until you turn it on.

**[Protect docs](https://context-mode.com/docs/protect)**

The Protect production pack, the protected branches setting and the 5-minute test.

**[Protected branches](https://context-mode.com/docs/protect#settings)**

Add your own names, by exact name or by the start of the name. Removing one asks for a reason.

**[Plans](https://context-mode.com/pricing)**

On Team, the org sets the rules once and agents cannot loosen them.

Related: [For security teams](https://context-mode.com/solutions/security-teams) · [Keep .env secrets out](https://context-mode.com/use-cases/block-env-secrets) · [Secure coding agents](https://context-mode.com/solutions/secure-coding-agents)

## Let the agent ship. *Keep main for review.*

*npx @context-mode/cli* connects your agents. 1,000 requests free, no card.

[Get started free →](https://console.context-mode.com/login) [Read the docs →](https://context-mode.com/docs/protect#try-it)
