# Addendum: Coding-Agent Context Compaction Coverage

Addendum date: 2026-04-13

Related report: `coding-agent-memory-compaction-2026-04-12.md`

GPT Researcher session: `research-1d0cd61d8c2c`

Codex source snapshot checked locally: `openai/codex` commit `6550007cca50c6d34408b0d3aa15e9923266aef0`

## Why This Addendum Exists

The original report had a useful high-level comparison, but the weakest coverage was around primary-source verification. In particular, Codex implementation details were partly based on community summaries and issue reports. This addendum adds:

- source-level observations from the current `openai/codex` repository
- official Anthropic API compaction/context-editing details
- Claude Code operator controls from official docs
- confidence changes and still-open gaps

## OpenAI Codex: Source-Level Verification

Official OpenAI documentation:

- OpenAI's engineering post "Unrolling the Codex agent loop" documents the high-level design: Codex carries a growing `input` list across turns, avoids `previous_response_id` for stateless/ZDR-compatible operation, uses prompt caching heavily, and now uses `/responses/compact` to replace the thread input with a smaller list containing a `type=compaction` item when `auto_compact_limit` is exceeded.
  Source: https://openai.com/index/unrolling-the-codex-agent-loop/

Repository observations from `openai/codex` commit `6550007cca50c6d34408b0d3aa15e9923266aef0`:

- `codex-rs/codex-api/src/endpoint/compact.rs` defines the compact endpoint path as `responses/compact`, posts a compaction request, parses `CompactHistoryResponse`, and returns `output: Vec<ResponseItem>`.
- `codex-rs/core/src/client.rs` has `compact_conversation_history`, described in code comments as a unary compact call that "returns a new list of `ResponseItem`s representing the compacted transcript." It sends model, input, instructions, tools, parallel tool-call setting, reasoning, and text parameters to the compact endpoint.
- `codex-rs/core/src/compact_remote.rs` implements remote compaction. It uses `CompactionImplementation::ResponsesCompact`, calls `model_client.compact_conversation_history`, filters remote compacted output, drops stale `developer` messages, preserves valid real user or hook-prompt user messages, preserves assistant messages, preserves `ResponseItem::Compaction`, and drops most raw tool/reasoning/call outputs from the compacted transcript before reinjecting canonical context as needed.
- `codex-rs/core/src/compact.rs` implements local or inline compaction. It uses `codex-rs/core/templates/compact/prompt.md`, whose prompt asks for a "CONTEXT CHECKPOINT COMPACTION" handoff summary including progress, decisions, constraints, remaining work, and critical references. The local path builds replacement history from the summary plus collected user messages and may inject initial context before the last user message for mid-turn compaction.
- `codex-rs/core/src/compact.rs` sets `COMPACT_USER_MESSAGE_MAX_TOKENS` to `20_000`, meaning preserved user-message material is bounded in the local compaction path.
- `codex-rs/protocol/src/openai_models.rs` documents `auto_compact_token_limit`: when omitted, core derives it from `context_window` at 90%; when provided, core clamps it to 90% of the context window if a context window is available.
- `codex-rs/core/src/codex.rs` runs automatic compaction when `total_usage_tokens >= auto_compact_limit`.
- `codex-rs/core/src/codex.rs` also has a model-downshift path: when switching to a smaller-context model, it can compact using the previous model context if total usage exceeds the new model's auto-compact limit.
- `codex-rs/core/src/compact.rs` chooses remote compaction for OpenAI providers through `should_use_remote_compact_task(provider) -> provider.is_openai()`. Non-OpenAI providers use the inline/local summarization path.

Confidence change:

- The original report's claim that Codex auto-compaction defaults around 90% of the context window is now stronger. It is present in current source comments and implementation.
- The original report's claim that Codex uses `/responses/compact` is now strong. It is documented by OpenAI's engineering post and implemented in the current repo.
- The original report should avoid treating exact UI behavior, compaction-loop root causes, or issue-specific failure modes as official facts unless backed by source or maintainer comments.

## OpenAI Codex: Issue Evidence

GPT Researcher found several `openai/codex` issue reports around compaction behavior:

- https://github.com/openai/codex/issues/8365
- https://github.com/openai/codex/issues/8481
- https://github.com/openai/codex/issues/9734
- https://github.com/openai/codex/issues/10734

These are useful for identifying field-reported failure modes: compaction loops, context not recovering after compaction, interaction with steer conversation, and plan-mode behavior after compaction. But they are bug reports, not official root-cause analysis. Treat them as evidence that users observed problems, not as evidence of why those problems happened.

## Anthropic Claude: Official API Compaction

Official Anthropic documentation for server-side compaction:

- https://platform.claude.com/docs/en/build-with-claude/compaction

Key details:

- Server-side compaction is enabled with the beta header `compact-2026-01-12`.
- The API monitors input token count after each response.
- When the input token count exceeds the trigger threshold, the API generates a summary, creates a compaction block, and continues with compacted context.
- On later requests, message blocks before the compaction block are automatically dropped.
- The default trigger threshold is 150,000 input tokens, with a minimum configurable threshold of 50,000.
- `pause_after_compaction` defaults to `false`; when set, the API can return after compaction with `stop_reason: "compaction"` so the caller can inject additional content before resuming.
- A custom `instructions` value replaces the default compaction prompt rather than appending to it.
- Anthropic's examples imply multi-compaction sessions are expected and show application-level budget control using compaction counts and trigger thresholds.

Confidence change:

- The original report should treat Anthropic API compaction as a first-class server-side mechanism, not just generic summarization.

## Anthropic Claude: Context Editing And SDK Compaction

Official Anthropic context-editing documentation:

- https://platform.claude.com/docs/en/build-with-claude/context-editing

Key details:

- Anthropic distinguishes server-side compaction from context editing.
- Tool-result clearing uses `clear_tool_uses_20250919`.
- Thinking-block clearing uses `clear_thinking_20251015`.
- Compaction is identified as `compact_20260112`.
- The docs say Anthropic recommends server-side compaction over SDK compaction because it reduces integration complexity, improves token-usage calculation, and avoids client-side limitations.
- SDK compaction remains useful when the caller needs client-side control over the summarization process.
- Context editing can be combined with the memory tool so Claude can preserve important information in memory files before older tool results are cleared.

Confidence change:

- The report should not collapse "compaction", "tool result clearing", and "thinking clearing" into one behavior. They are separate context-management strategies with different data-loss profiles.

## Claude Code: Operator Controls And Layered Memory

Official Claude Code best-practices documentation:

- https://code.claude.com/docs/en/best-practices

Official Claude Code memory documentation:

- https://code.claude.com/docs/en/memory

Useful operator controls and workflow details:

- `/clear` resets the context window between tasks.
- Auto-compaction summarizes important state such as code patterns, file states, and key decisions.
- `/compact <instructions>` lets the user steer what the compaction preserves.
- `Esc + Esc` or `/rewind` can select a message checkpoint and "Summarize from here", compacting only part of the conversation while preserving earlier context.
- `/btw` supports quick side questions whose answers do not enter conversation history.
- Subagents investigate in separate context windows and report back summaries, keeping the main conversation cleaner.
- Claude Code checkpoints make it possible to restore conversation, code, or both.

Useful memory framing:

- Treat Claude's "three levels" as an operational model rather than a single official taxonomy:
  1. Active transcript context: conversation, tool results, thinking, and compaction summaries.
  2. Persistent instruction/memory files: `CLAUDE.md` and related user/project memory surfaces that can be reloaded.
  3. Externalized/isolated context: subagents, memory files, checkpoints, and tool-managed state that avoid stuffing every detail into the main transcript.

Confidence change:

- The original report should make the user-facing controls more explicit because they are part of how compaction is managed in practice, not merely UX decoration.

## Prompt Caching Interaction

Anthropic prompt-caching product documentation:

- https://www.anthropic.com/news/prompt-caching

OpenAI Codex agent-loop documentation:

- https://openai.com/index/unrolling-the-codex-agent-loop/

Prompt caching matters because compaction changes the prompt prefix/history shape. OpenAI's Codex article explicitly frames Codex's stateless thread replay in terms of prompt-cache efficiency: keeping exact prefix matches allows cached computation to be reused. Anthropic's docs and product materials similarly frame prompt caching as a way to reduce cost and latency for long prompts, agentic search, tool use, and multi-turn conversations.

Open gap:

- The exact cache invalidation and cost/latency behavior immediately before and after compaction is not fully documented for either Codex CLI or Claude Code. This would need direct instrumentation or provider billing/usage data.

## Source-Quality Notes

- Strongest OpenAI sources: official OpenAI Codex agent-loop post and current `openai/codex` source at commit `6550007cca50c6d34408b0d3aa15e9923266aef0`.
- Useful but weaker OpenAI sources: GitHub issue reports. They document user-observed failure modes, not verified root causes.
- Strongest Anthropic sources: official compaction, context-editing, Claude Code memory, and Claude Code best-practices docs.
- Weak or secondary sources from the GPT Researcher addendum: third-party Claude Code tutorials, Penligent analysis, Reddit/Facebook links, and duplicate or localized docs. These can be used as leads, but should not carry architectural claims unless cross-checked against official docs or source.
- GPT Researcher reported two Tavily 400 errors during the run, but the run still completed with 13 sources and produced a report. The raw report is useful as a search artifact, but this cleaned addendum is the safer version to cite.

## Remaining Research Gaps

- Codex compaction prompt/scoring for the remote `/responses/compact` endpoint is still opaque. Source shows the client request and response shape, but the server-side compacting model/prompt is not visible.
- Codex compaction-loop root causes in the GitHub issue reports remain unverified without maintainer explanations or a reproducer tied to a specific commit.
- Exact Claude Code skill-listing reload behavior after compaction still needs primary verification if it matters operationally.
- Empirical behavior remains under-tested. A better next pass would run a synthetic long Codex/Claude Code task, force compaction, and compare preserved vs lost facts across transcript, memory files, and tool outputs.
