codex - 💡(How to fix) Fix Auto-run a skill when context is near exhaustion before compaction

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

This should be opt-in, because some users may not want automatic file writes or automatic context resets. But for users who explicitly enable it, it would remove the need to manually watch the context meter and manually type $context-handoff before clearing/compacting.

Fix Action

Fix / Workaround

Currently, the closest workaround seems to be:

Code Example

when context_remaining_percent <= 15:
  invoke: $context-handoff
  require_file_update: docs/CODEX_HANDOFF.md
  after_handoff: compact # or clear/new
  require_user_confirmation: false

---

[context_handoff]
enabled = true
trigger_remaining_percent = 15
skill = "context-handoff"
handoff_file = "docs/CODEX_HANDOFF.md"
after_handoff = "compact" # or "clear" / "new"
require_repo_verification = true
require_user_confirmation = false

---

context threshold reached
→ automatically invoke configured skill
→ skill updates handoff file
Codex compacts/clears/starts new session according to config
→ no manual intervention required
RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

cli

What feature would you like to see?

I would like Codex CLI to support context-threshold automations that can automatically run a configured skill before automatic compaction or context exhaustion.

Use case:

When a long Codex session gets close to the context limit, I want Codex to automatically create a clean handoff file before the conversation gets compacted or polluted by stale context. This would reduce hallucinations and make long-running coding sessions much safer.

Example behavior:

when context_remaining_percent <= 15:
  invoke: $context-handoff
  require_file_update: docs/CODEX_HANDOFF.md
  after_handoff: compact # or clear/new
  require_user_confirmation: false

The skill could be responsible for writing a verified handoff containing:

  • current goal
  • repo facts verified from files
  • files changed and why
  • commands/tests run and exact results
  • known failures
  • unknowns explicitly marked as UNKNOWN
  • next recommended steps

Then Codex could automatically continue with the configured policy:

[context_handoff]
enabled = true
trigger_remaining_percent = 15
skill = "context-handoff"
handoff_file = "docs/CODEX_HANDOFF.md"
after_handoff = "compact" # or "clear" / "new"
require_repo_verification = true
require_user_confirmation = false

This should be opt-in, because some users may not want automatic file writes or automatic context resets. But for users who explicitly enable it, it would remove the need to manually watch the context meter and manually type $context-handoff before clearing/compacting.

Additional information

Currently, the closest workaround seems to be:

  1. Set model_auto_compact_token_limit.
  2. Use a PreCompact hook.
  3. Have the hook run a command that warns or launches a separate codex exec process to update a handoff file.

But this is awkward because hooks currently run command handlers, not full agent/skill handlers. So a hook cannot cleanly say: “run this skill as the current Codex agent, update the handoff file, then proceed with compact/clear.”

The missing feature is not just a warning. The desired behavior is:

context threshold reached
→ automatically invoke configured skill
→ skill updates handoff file
→ Codex compacts/clears/starts new session according to config
→ no manual intervention required

This would be especially useful for long autonomous coding sessions, where the user does not want to interrupt the agent just to manually run a context handoff workflow.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Auto-run a skill when context is near exhaustion before compaction