Feature request: supported offline session export + cache visibility

Resolved 💬 1 comment Opened Feb 2, 2026 by baba20o Closed Mar 14, 2026

Feature request: supported offline session export + cache visibility for long-running Codex agent loops

Problem (general)

We run Codex CLI headless as part of an orchestrator (Discord-first), often on ephemeral machines, for long-running “agent loop” workloads (e.g. backtests / batch jobs). Two issues make debugging and cost-control hard:

1) Offline postmortems: When a run finishes, we need a supported, stable artifact to archive and analyze offline (errors, tool outputs, timings, token/cost sanity checks). Today the only durable per-session artifact we can reliably grab is the on-disk rollout JSONL, but maintainers have clarified it’s an internal detail and may change.

2) Prompt caching / cost visibility: In long loops, a large, stable “project instructions” prefix (e.g. AGENTS.md/workspace instructions) dominates prompt size. We understand Codex aims to preserve the prefix to maximize prompt caching, but we don’t have a supported way to see caching effectiveness (cached vs uncached input tokens, cache hit rate) or to quickly validate when something is accidentally appended repeatedly.

Why this matters
  • Without a supported export, teams build brittle tooling on internal files or lose the ability to audit runs after ephemeral hosts are gone.
  • Without cache visibility, it’s hard to explain billing spikes, debug instruction bloat, and validate that prompt caching is actually being hit.
Requested functionality

A. Supported offline export (pick any design that fits Codex):

  • A codex export command that emits a stable, documented schema (JSON/JSONL) for a session.
  • Ideally includes: message/response items, tool calls/outputs (or references), timestamps, errors.
  • Can omit large bodies by default with pointers/hashes and provide a --include-tool-output switch.
  • OR a flag/config to persist the app-server event stream to a file.
  • OR a documented way to persist OTel events to a local file/SQLite for later analysis.

B. Cache / usage visibility

  • Surface prompt caching stats for each request (or aggregated per session):
  • cached vs uncached input tokens
  • cache hit/miss or “prefix reused” indicator
  • Expose via: CLI verbose logs, an event stream field, and/or OTEL metrics.

C. Best-practice guidance

  • Document how to keep project instructions stable/minimal for caching.
  • Document where AGENTS.md/project instructions are sourced from and how they’re injected.
Non-goals
  • We are not asking to stabilize the internal rollout JSONL format.
Workarounds we’re using today (undesirable)
  • Parsing internal on-disk rollout JSONLs for postmortems.

Thanks — happy to provide more concrete repros / sample artifacts if helpful.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗