Overview

In a team, agent-generated code that reaches main without review is a shared risk. The protocol is strict because the consequences are shared. Every rule here exists because the cost of getting it wrong falls on more than one person.

Not sure which guide is right for you? See all three profiles.

The branch rule - not optional

Never let the agent modify main directly. Every agent session starts on a branch:

git checkout -b agent/feature-name

The naming convention matters. agent/ as a prefix makes it immediately clear in the commit history and PR list what came from an agent session versus human work. Your team can filter, review, and track it.

Before the session

Commit your current state before the agent starts working. This gives you a clean rollback point and a clear before/after boundary in the history:

git add -A
git commit -m "checkpoint: before agent session"

Reviewing the diff

After the agent works, review before staging anything:

git diff
What to look for - not just errors
Files that should not have been touched
Deleted code that the agent removed without being asked
New imports or added dependencies
Changes to configuration, environment, or build files
Scope creep - the agent doing more than it was asked to do

Committing and pushing

Commit by logical unit, not by session. One PR should tell one coherent story:

git add src/lib/components/NewComponent.svelte
git commit -m "add NewComponent"

git add src/lib/components/index.ts
git commit -m "export NewComponent from barrel"

git push origin agent/feature-name
# open PR from here

The team protocol

Branch per session Always. Name it with the agent/ prefix so it is visible in history.
Review the diff Before staging anything. Every changed file, not just the ones you expected.
PR before merge Agent-generated code follows the same review process as human-generated code. No exceptions.
Push manually Never let the agent push. Always push yourself after reviewing the full diff.
Never force push No exceptions. Not the agent, not you. Force push rewrites shared history.
Never amend published commits Once a commit is pushed, it belongs to the shared history. Leave it.

Recovery patterns

Undo last local commit, keep changes
git reset --soft HEAD~1
Undo last local commit, discard changes
git reset --hard HEAD~1
Restore one specific file
git checkout HEAD~1 -- path/to/file.ts
Stash and come back later
git stash
git stash pop    # restore
git stash drop   # discard