SEP-027: Compaction detection signal in WORKFLOW STATE injection
Status: Open
Created: 2026-03-17
Project: .claude
Dependency: SEP-026 (PreCompact snapshot must exist to detect compaction)
Blocked by: SEP-025, SEP-026
Blocks: SEP-028
Summary
The UserPromptSubmit injection in check_clear_approval_command.sh looks identical whether the model has full context or just lost everything to compaction. The model cannot distinguish "I've been working on this for 20 messages and have full context" from "I just compacted and know nothing except what's in this injection."
Without that signal, the model has no trigger to:
- Re-read the plan file
- Re-examine in-scope files for what's already changed
- Reconstruct its position before continuing
Motivation
The current injection for APPROVED state includes: session, plan dir, objective, phase, plan file path, scope, success criteria, edit count, dirty status. That's comprehensive state metadata.
What it does NOT include is any indication that context was lost. The ARCHITECTURE.md decision tree says "Read the plan file (path is in the injection)" — but that's in a doc the model has to find and read, not in the injection itself. The injection says "Next: Continue implementing approved changes" without first saying "READ THE PLAN FILE NOW BEFORE DOING ANYTHING."
Proposed Change
After a PreCompact snapshot exists (SEP-026), modify the UserPromptSubmit injection in check_clear_approval_command.sh to:
- Check if a compaction snapshot exists for the current session
- Compare the snapshot timestamp against a "last injection" marker to detect if compaction occurred since the last injection
- If compaction is detected, prepend a clear signal to the injection:
⚠️ CONTEXT COMPACTION DETECTED — You have lost working context.
BEFORE doing anything else, you MUST:
1. Re-read the plan file: [path]
2. Run: git diff --stat
3. Review in-scope files for changes already made
4. Reconstruct your implementation position from the snapshot below
- Include the PreCompact snapshot data in the injection block
Acceptance Criteria
- Injection detects compaction by comparing snapshot timestamps
- When compaction is detected, injection includes an explicit, unmissable warning
- Warning includes mandatory recovery steps (re-read plan, check git status)
- PreCompact snapshot data is included in the post-compaction injection
- Normal (non-compacted) injections are unchanged
- Model behavior after compaction measurably improves (re-reads plan before continuing)
SEP-027: Compaction detection signal in WORKFLOW STATE injection
Status: Open
Created: 2026-03-17
Project: .claude
Dependency: SEP-026 (PreCompact snapshot must exist to detect compaction)
Blocked by: SEP-025, SEP-026
Blocks: SEP-028
Summary
The
UserPromptSubmitinjection incheck_clear_approval_command.shlooks identical whether the model has full context or just lost everything to compaction. The model cannot distinguish "I've been working on this for 20 messages and have full context" from "I just compacted and know nothing except what's in this injection."Without that signal, the model has no trigger to:
Motivation
The current injection for APPROVED state includes: session, plan dir, objective, phase, plan file path, scope, success criteria, edit count, dirty status. That's comprehensive state metadata.
What it does NOT include is any indication that context was lost. The ARCHITECTURE.md decision tree says "Read the plan file (path is in the injection)" — but that's in a doc the model has to find and read, not in the injection itself. The injection says "Next: Continue implementing approved changes" without first saying "READ THE PLAN FILE NOW BEFORE DOING ANYTHING."
Proposed Change
After a PreCompact snapshot exists (SEP-026), modify the
UserPromptSubmitinjection incheck_clear_approval_command.shto:Acceptance Criteria