codex - 💡(How to fix) Fix Allow agent to clear context between tasks and continue with previous session ID

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…

Code Example

Previous session ID: X.
Work on the next issue.

---

{
  "action": "clear_context_and_continue",
  "previousSessionId": "<current-session-id>",
  "prompt": "Previous session ID: <current-session-id>. Work on the next issue."
}
RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

CLI

What feature would you like to see?

Add a first-class agent capability for moving cleanly from one task to the next by intentionally clearing the current context and starting a fresh continuation prompt seeded with the previous session ID.

This is a happy-path workflow, not a failure recovery path. The goal is to let the agent finish or pause one unit of work, drop the now-stale working context for that task, and begin the next unit of work with a clean context while preserving an audit/reference link back to the prior session.

A common workflow would be:

  1. The agent finishes the current issue or reaches a natural task boundary.
  2. The agent invokes a supported control operation to clear/reset the active context.
  3. Codex starts a fresh context whose initial state includes the previous session/thread ID.
  4. Codex executes a new prompt supplied by the agent, for example:
Previous session ID: X.
Work on the next issue.

In a project that uses an issue tracker or local task workflow, the fresh prompt can trigger the normal “work on the next issue” flow without carrying over all the old file reads, command output, intermediate reasoning, and task-specific details from the previous issue.

A rough API shape could be something like:

{
  "action": "clear_context_and_continue",
  "previousSessionId": "<current-session-id>",
  "prompt": "Previous session ID: <current-session-id>. Work on the next issue."
}

The important part is not the exact API shape, but that this is a real Codex control path. Sending /clear, /compact, or similar text back to the model should not be required.

Why this would help

Long-running project work often consists of many discrete tasks. Context from the previous task can be useful for auditability, but it is usually not useful enough to keep in the active model context once the next task begins.

A task-boundary context clear would let agents run cleaner multi-issue workflows:

  • finish one issue and start the next with less stale context
  • preserve a durable reference to the prior session for traceability
  • avoid carrying previous-task implementation details into unrelated work
  • keep issue-tracker workflows moving without requiring the user to manually start a new chat
  • make the transition explicit and understandable to the user

Desired semantics

  • The operation should be agent-accessible only through a guarded control/tool path.
  • The new context should contain the previous session/thread ID in a machine-readable way.
  • The agent should provide the first prompt to run in the new context.
  • Codex should make the transition visible to the user so it is clear that a task-boundary context clear happened.
  • The previous session should remain inspectable/resumable for audit and recovery.
  • The old context should not automatically be copied wholesale into the new context.
  • The feature should support normal issue-tracker prompts such as “work on the next issue” after the clear.
  • Safeguards should prevent accidental loops or repeated clears without user-visible progress.

Related issues

  • #21777 asks to expose compaction to the agent.
  • #21673 asks for a compact handoff command with copyable context.
  • #23153 asks for hooks to request real compaction before continuing.

This request is related, but distinct: it asks for an agent-controlled task-transition path that clears active context, carries the previous session ID, and immediately executes a new prompt for the next task.

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 Allow agent to clear context between tasks and continue with previous session ID