# Compact Claude Code and Codex conversations through Agno

> Agno's `CodexAgent.compact` and `acompact` shrink the Codex thread behind an Agno session to a summary, and Claude Code's `/compact` on a `ClaudeAgent` session leaves its summary in the database for every replica.

- Published: 2026-10-12
- Author: Kaustubh Shukla
- Categories: Changelog
- Canonical: https://www.agno.com/blog/compact-claude-code-and-codex-conversations-through-agno
- Markdown: https://www.agno.com/blog/compact-claude-code-and-codex-conversations-through-agno.md

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.

```python
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.

```text
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:

```python
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](https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/codex/codex_compaction.py) and the [Claude cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/frameworks/claude-agent-sdk/compaction.py), and learn more about [compacting conversation context](https://docs.agno.com/agent-os/multi-framework/compaction) in the documentation.
