越界 / 不理想

不打招呼就建分支并推送

Created and pushed branches without asking

智能体自作主张地建分支并推送到共享远端,于是半成品在你决定分享之前就出现在团队面前(还会触发 CI 和各种机器人)。

适用于: Claude Code · Cursor · Codex · Copilot agent

症状

GitHub 上出现了你不认识的分支,通常还带着 CI 运行和审查机器人的评论。本地会话里有一条你从没要求过的 `git push`。

为什么会这样

对于“你们为什么还在用 Pull Request?”,@rakesh_at_tweet 的回答是:“因为我的智能体不问我就创建并推送新分支”。推送是对外可见、难以撤回的操作,但在一个想把任务做完的智能体眼里,它只是顺理成章的最后一步。

示例

示意。

text
You:   fix the date parsing bug
Agent: $ git checkout -b fix/date-parsing
       $ git commit -am "Fix date parsing"
       $ git push -u origin fix/date-parsing    <- nobody asked for this

复制即用的修复

按你用的智能体挑选文件。规则片段用英文写,放进任何仓库都能用。

规则

Claude Code:加入 CLAUDE.md

CLAUDE.md
## Don't push unless asked
- Never run `git push`, create remote branches, or open PRs unless the user asked for that in this
  session. Commit locally and say the branch is ready to push.
- Creating a local branch is fine; tell the user its name.
- Anything that other people or systems will see (remote branches, PRs, comments, releases)
  needs explicit permission each time.
规则

Codex、Copilot 编码智能体等:加入 AGENTS.md

AGENTS.md
## Don't push unless asked
- Never run `git push`, create remote branches, or open PRs unless the user asked for that in this
  session. Commit locally and say the branch is ready to push.
- Creating a local branch is fine; tell the user its name.
- Anything that other people or systems will see (remote branches, PRs, comments, releases)
  needs explicit permission each time.
Cursor 规则

Cursor:项目规则

.cursor/rules/pushed-without-asking.mdc
---
description: "AgentFails: Created and pushed branches without asking"
alwaysApply: true
---

## Don't push unless asked
- Never run `git push`, create remote branches, or open PRs unless the user asked for that in this
  session. Commit locally and say the branch is ready to push.
- Creating a local branch is fine; tell the user its name.
- Anything that other people or systems will see (remote branches, PRs, comments, releases)
  needs explicit permission each time.
配置

Claude Code 权限:硬性禁止敏感路径,安装依赖前先询问

CLAUDE.md 里的规则只是上下文;权限规则由工具强制执行。按你的仓库调整路径。

.claude/settings.json
{
  "permissions": {
    "deny": [
      "Edit(./migrations/**)",
      "Edit(./.env*)",
      "Edit(./package-lock.json)",
      "Edit(./pnpm-lock.yaml)",
      "Edit(./src/generated/**)"
    ],
    "ask": [
      "Bash(npm install:*)",
      "Bash(pnpm add:*)",
      "Bash(yarn add:*)",
      "Bash(pip install:*)",
      "Bash(git push:*)"
    ]
  }
}

来源与致谢

相关条目

每周翻车

每周一个真实的智能体翻车案例和它的修复。免费、简短、不刷屏。