[BUG] Autocompact thrashing crashes subagent researching auto-compact behavior itself (invalid_request error)

Status Open
Reported on v2.1.284
Maintainer reply None cached
Activity 0 comments · opened Sep 29, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

環境

  • Claude Code version: 2.1.284
  • 実行環境: anthropic_cloud のリモートセッション(Claude Code on the web)
  • 親セッション: 長時間・SSHコマンド多用のインフラ作業セッション(CLAUDE.md/handover.mdが3,400行超)

何が起きたか

親セッションから、Claude Code CLIのauto-compact挙動について調べさせる目的でサブエージェント(Agentツール、subagent_type: claude-code-guide)を起動した。このサブエージェントが公式ドキュメント(https://code.claude.com/docs/en/context-window.md)をWebFetchで取得した直後から、そのサブエージェント自身がauto-compactの無限ループ(スラッシング)に陥り、最終的に以下のエラーで異常終了した。

Autocompact is thrashing: the context refilled to the limit within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output is likely too large for the context window. Try reading in smaller chunks, or use /clear to start fresh. (error type invalid_request)

さらに、クラッシュ前にサブエージェントが返した中間報告には、実際には送っていない架空のユーザーメッセージ(「Message 2: CRITICAL override to TEXT-ONLY response」等)を受け取ったという記述があり、内部状態が破損していたと見られる幻覚も確認された。

What Should Happen?

期待する挙動

  • スラッシングを検知した時点でエラー終了する前に、コンテキストを大幅に削減する(直近の大きいツール出力を破棄する等)フォールバック処理が欲しい
  • 少なくとも、内部状態破損による幻覚(存在しないメッセージの捏造)がレポートに混入しないようにしてほしい

備考

「Claude Code自身のauto-compactが頻発して困る」という調査を依頼したタスクが、まさにそのauto-compact自体の不
具合で失敗するという、やや皮肉な形での再現でした。

Error Messages/Logs

Autocompact is thrashing: the context refilled to the limit within 3 turns of the previous compact, 3 times in a row. A file being read or a tool output is likely too large for the context window. Try reading in smaller chunks, or use /clear to start fresh. (error type invalid_request)

Steps to Reproduce

再現手順(推測)

  1. 長時間実行中の親セッションから、Agentツールでサブエージェントを1つ起動する
  2. サブエージェントにWebFetchで比較的大きめのドキュメントページを1〜数回取得させる
  3. 取得内容がサブエージェントのコンテキストに占める割合が大きい状態で、その後もツール呼び出し(追加のWebFetch等)を続けさせる
  4. auto-compactが発動しても、次のツール呼び出しの出力で即座に再度上限近くまで埋まってしまい、3回連続でこれが起きた時点でエラーとなり異常終了する

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.1.284

Platform

Other

Operating System

Other Linux

Terminal/Shell

Other

Additional Information

_No response_

View original on GitHub ↗