Claude Code already compacts automatically.

I believe Codex CLI also auto compacts when the context limit is met, but in addition to that, you can manually issue a /compact command at any time.

Claude Code had this /compact command for a long time, you can even specify your preferences for compaction after the slash command. But this is quite limited and to get the best results out of your agent you need more than rely on how the tool decides to prune your context. I ask it explicitly to write down the important parts of our conversation into an md file, and I review and iterate over the doc until I'm happy with it. Then /clear the context and give it instructions to continue based on the MD doc.

Codex was only explicit last time I checked

CC also has the same `/compact` command if you want to force it

/compact accepts parameters, so you can tell it to focus on something specific when compacting.

/clear too