Let the agent clear its own context after saving its state to a journal, then continue from that journal

Status Open
Maintainer reply None cached
Activity 0 comments · opened Oct 6, 2026

What I'd like

When an agent finishes a part of a long job, it writes what it needs to a journal file: the user's instructions, what
it did, and the numbers it is tracking. It should then be able to clear its own context right away, with no /clear
typed by the user, and carry on from that journal. Two ways this could work, either would do:

  1. Clear, then load from the journal. A hook or tool output clears the context exactly like /clear does. The

new session starts with the journal file as its first context, and the agent continues without waiting for the
user. For example, from a Stop or PostToolUse hook:

``json
{ "clearContext": { "contextFile": ".agentjournal/JOURNAL.md", "continueWith": "Continue from the journal." } }
``

  1. Use the journal as the context. A hook can replace the conversation sent to the model with the contents of a

file: the journal instead of the full history. The pi coding agent already allows this through its context
extension event.

Why

Long jobs today have two options:

  • Let the context fill until auto-compaction. The summary is written at an arbitrary point, in the middle of the

work, and rules or counts from early on get lost.

  • Have the user type /clear and "continue" at the right moment. That only works while someone is watching.

The agent knows when a piece of work is finished and has already saved what matters. If it could clear right there
and reload from its own notes, long sessions would keep a small, clean context without a person stepping in.

What exists today, and where it stops

AgentJournal (https://github.com/PiPercentHuman/agentjournal) does everything except the clear itself:

  • hooks save every user message word for word and one line per action to .agentjournal/;
  • the agent closes a topic with agentjournal sleep "<summary>";
  • after a /clear, the SessionStart hook loads the journal back.

The one missing step is the clear itself: hooks and tools cannot trigger it, and initialUserMessage works only with
-p, so the user has to type /clear and then "continue".

In pi, where an extension can replace the context, the same design clears the context the moment the agent asks.
In our tests with a local 9B model, it finished long jobs that pi's own compaction did not.

Earlier requests

These were all closed by the inactivity bot, not declined: #16659 (clearContext on Stop hooks), #35150 (clear plus a
continuation prompt), #9118, #37307, #68127, #82658, and the duplicate #20267.

View original on GitHub ↗