Repo-level instruction files (AGENTS.md/CLAUDE.md/etc.) are not preserved across /compact
还没有人认领这个 Issue。
- 主要语言
- Shell
- 星标
- 11.2k
- 派生
- 1.9k
- 平均合并
- 14 小时 16 分钟
- 30 天内合并 PR
- 6
描述
Describe the bug
(Written by Sonnet 5 as we mutually investigated the issue in-session in copilot-cli)
Early in a long session, the agent correctly read and followed a rule in the repo's AGENTS.md ("never commit directly to main ; create a topic branch first"). Mid-session, context compaction occurred. After compaction, the agent committed directly to main twice, violating the rule it had followed earlier — it had no indication the rule still applied and never re-read AGENTS.md after compaction.
Root cause: compaction summarizes conversation history, but standing repo instruction files aren't treated as pinned/reloaded — they're just facts that can get compressed away like anything else discussed early in the session.
Suggested fix: on compaction, either (a) re-inject the current contents of any active instruction files (AGENTS.md, CLAUDE.md, copilot-instructions.md, etc.) into the fresh context, or (b) explicitly prompt/require the agent to re-read them before resuming file-editing/git work post-compaction.
Impact: silent policy drift after compaction in any long session touching a repo with custom agent instructions — particularly dangerous for rules like branch protection, since a violation may not surface until a human notices.
Affected version
1.0.80
Steps to reproduce the behavior
- Open a session in a repo containing an AGENTS.md (or CLAUDE.md / copilot-instructions.md ) with an explicit git-workflow rule, e.g. "never commit directly to main ; create a topic branch first."
- Have the agent read that file early in the session (directly, or incidentally via a view / grep call) and perform at least one commit that correctly follows the rule (confirms the rule was live in context).
- Continue the session with enough unrelated work/turns that automatic or manual ( /compact ) context compaction occurs at least once.
- After compaction, ask the agent to make further code changes and commit them in the same repo, without re-mentioning the branching rule.
- Observe: the agent commits directly to the currently-checked-out default branch (e.g. main ), violating the rule it followed correctly in step 2 — with no re-read of AGENTS.md and no acknowledgment that a repo policy exists.
Expected behavior
The rule from AGENTS.md continues to be honored after compaction, either because the file's contents are re-injected into context at compaction time, or because the agent is prompted to re-read active instruction files before resuming work in that repo.
Actual: the rule silently stops being followed post-compaction, with no error, warning, or indication to the user that it had been dropped — only surfaced when the human happened to notice the resulting commits.
Additional context
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
该 issue 指出了活动指令文件(AGENTS.md、CLAUDE.md 和 copilot-instructions.md)以及 /compact 流程;首先跟踪压缩如何恢复会话,以及这些文件最初是如何加载的。复现编号工作流,然后验证压缩后的工作仍然遵循分支规则,或明确重新加载这些文件。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- git
- 领域
- cli, developer-experience
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 活跃
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100