Proposal: reduce token usage for common verbose exec_command outputs
Context
First, thank you for building and maintaining Codex.
I read the contribution policy in docs/contributing.md and understand that external code contributions are currently invitation-only.
I still wanted to share a concrete, tested implementation idea because this appears to be a common token-efficiency pain point in real usage.
Proposal
Reduce model token footprint for very common verbose shell outputs in exec_command responses:
- Strip ANSI escape sequences before truncation.
- Add conservative compaction for high-noise commands:
git status(non-porcelain): compact staged / unstaged / untracked summaryls -l/ls -la: compact file-type + filename listing
- Apply compaction only when it produces meaningful size savings; otherwise fallback to existing output.
Why this may help
In interactive coding sessions, git status and ls -la are frequently emitted.
Their default output often has high formatting overhead relative to decision-relevant signal, which increases context consumption.
A conservative compaction layer can preserve useful signal while reducing token pressure.
Ready Implementation (for reference)
I prepared a working patch on my fork with unit tests.
- Branch:
joey/token-compact-common-command-output - Commit:
9379013baf3f2c1c5242806cb9a9df027868c7ba - Fork branch URL: <https://github.com/joeeeeey/codex/tree/joey/token-compact-common-command-output>
- Commit URL: <https://github.com/joeeeeey/codex/commit/9379013baf3f2c1c5242806cb9a9df027868c7ba>
Files changed:
codex-rs/core/src/tools/context.rscodex-rs/core/src/tools/context_tests.rs
What I am asking
If this direction aligns with Codex priorities, could a maintainer advise whether:
- you would prefer this as a feature request only, or
- you would like to invite an external PR for this scope.
I am happy to adjust design details, naming, or test shape based on maintainer feedback.
Thank you for your time.
2 Comments
I wanted to follow up with concrete before/after samples to quantify potential impact.
I ran local fixture-based measurements using the same compaction heuristics as the patch on my fork:
git statuscompaction (non-porcelain)ls -lacompaction (long listing)120entries per section)For token estimates, I used
len(text) / 4(integer), which is the same lightweight approximation commonly used for trend analysis (not exact tokenizer counts).Before/After Samples
| Scenario | Before bytes | After bytes | Byte reduction | Before est tokens | After est tokens | Token reduction | Before lines | After lines |
|---|---:|---:|---:|---:|---:|---:|---:|---:|
| git status (typical mixed) | 14274 | 12927 | 9.4% | 3568 | 3231 | 9.4% | 132 | 126 |
| git status (heavy staged/unstaged) | 69861 | 25773 | 63.1% | 17465 | 6443 | 63.1% | 608 | 246 |
| git status -uall (large untracked) | 45224 | 28972 | 35.9% | 11306 | 7243 | 35.9% | 451 | 286 |
| ls -la (420 entries) | 53820 | 8241 | 84.7% | 13455 | 2060 | 84.7% | 447 | 122 |
| ANSI escape-only output | 32 | 14 | 56.2% | 8 | 3 | 62.5% | 2 | 2 |
Key takeaways
ls -laand largegit statusoutputs).git statuscase, reduction is still positive.Patch reference
If helpful for evaluation, the implementation and tests are ready on my fork:
joey/token-compact-common-command-output9379013baf3f2c1c5242806cb9a9df027868c7baIf this direction is aligned with maintainers' priorities, I would be grateful for guidance on whether you would like this to remain as a feature discussion, or whether an invited PR would be appropriate.
This feature hasn't received enough upvotes, so closing.