Skip to content
Changelog

Compact Claude Code and Codex conversations through Agno

October 12, 20261 min read

Agno's CodexAgent.compact(session_id, user_id=None, timeout=120.0) and its async twin acompact resume the Codex thread behind an Agno session, ask the Codex app-server to compact it and wait until the thread is idle again. They return True when the compaction finishes and False when the session has no thread yet. Native Agno agents gained compaction in the previous release, and this release covers Claude Code and Codex.

compacted = await agent.acompact("support-demo")  # agent is a CodexAgent with a db

Compaction resumes the thread with the same options a run uses, so the sandbox, approval mode and instructions all carry over. If the thread's rollout is gone, acompact forgets the stored thread id, as a run would, and returns False. A thread that stays busy past timeout raises TimeoutError.

Refused while a run is in flight

Compaction opens its own Codex app-server on the thread, and two processes must not append to one rollout, so it refuses to start while a run on the same session is pending or running. Here a background run was submitted on a SQLite-backed CodexAgent and acompact called straight after it. The output is real. No Codex login was on the machine, so nothing reached a model.

background run: 590d9e13-723e-48e9-983f-d24070e43815 RunStatus.pending
RuntimeError: Cannot compact session s1: run 590d9e13-723e-48e9-983f-d24070e43815 is PENDING. Wait for it to finish.

The release's eight compaction tests, covering the missing thread, the resume and idle wait, the in-flight refusal and the timeout, pass against their fake Codex clients.

Claude Code

ClaudeAgent needed no new method, because /compact is an ordinary run input:

run = await agent.arun("/compact", session_id="support-demo")  # agent is a ClaudeAgent with a db

With transcript storage on, the compaction is saved to agno_transcripts like every other transcript line, as a compact_boundary system entry followed by the summary entry. A later turn on any replica resumes from that summary. To watch compactions, pass a PreCompact hook in the agent's ClaudeAgentOptions. It fires with trigger manual for /compact and auto when Claude Code compacts on its own.

See the Codex cookbook and the Claude cookbook, and learn more about compacting conversation context in the documentation.

Frequently asked questions

Call agent.compact(session_id) on a CodexAgent, or await agent.acompact(session_id) in async code. It returns True once the Codex thread has finished compacting, and False when the session has no Codex thread to compact.

Send /compact as the run input on that session, for example agent.run("/compact", session_id="support-demo"). Claude Code compacts the conversation, and with a database that stores transcripts the summary is saved with the rest of the transcript.

No. CodexAgent.compact raises RuntimeError when the session has a pending or running run, because compaction opens its own Codex app-server on the thread and two processes would write to one rollout. Wait for the run to finish and call it again.

Yes, when the agent uses a database with transcript storage. The compaction is saved to agno_transcripts like any other transcript line, so a later turn on any replica resumes from the summary.

Shipped around the same time