feat(agent): implement /clear command#3546
Open
haacked wants to merge 3 commits into
Open
Conversation
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
|
React Doctor found no issues in the changed files. 🎉 Reviewed by React Doctor for commit |
Intercept /clear in the Claude adapter instead of forwarding it to the SDK: retire the current query and swap in a brand-new SDK session (fresh id, no resume) under the same ACP session. Persist a _posthog/conversation_cleared marker plus an updated sdk_session mapping to the append-only session log, and make the rehydration paths (jsonl hydration, ResumeSaga) treat the marker as a conversation boundary so desktop reconnects and cloud resumes rebuild only the post-clear conversation. The UI renders a "Conversation cleared" divider and resets the context indicator. Generated-By: PostHog Code Task-Id: 7f180c25-f99b-4c96-ac84-f39c0e887a37
- Parallelize post-clear notifications instead of sequential awaits - Use isNotification() helper instead of set-based method checking - Remove unused variables and redundant state resets - Improve comments for session id handling
haacked
force-pushed
the
posthog-code/clear-command
branch
from
July 17, 2026 21:12
f58e90b to
30f05dc
Compare
Only broadcast (and thus log) the "/clear" prompt once the new session is confirmed live, so a timeout leaves no orphaned entry in the log. Add a "Clearing…" status indicator, mirroring the existing compaction spinner, so a slow or failed clear gives the user feedback instead of going silent. Delete the local session file left under the original session id after a clear so a cold reconnect can't mistake it for current and resume the pre-clear conversation.
haacked
marked this pull request as ready for review
July 18, 2026 00:24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Typing
/clearin PostHog Code reports "Unsupported slash command". Upstream hid the SDK's own/clearbecause it is unreliable in this embedding, but users still want a way to drop the conversation and free up context without abandoning the task, including on cloud runs, where the append-only session log is what rehydrates the conversation on resume.Here's an example session that shows it works.
Refs #670
Changes
packages/agent):prompt()intercepts/clear(never forwarded to the SDK). It retires the current SDK query (reusing therefreshSessionteardown, now extracted asretireQuery) and swaps in a brand-new SDK session, fresh id, no resume, under the same ACP session. The ACP session id stays stable; the newSession.sdkSessionIdtracks the underlying SDK session, andhasSessionaccepts either id so cancel/reconnect work from both sides./clearis advertised in the command list again._posthog/conversation_clearedmarker plus an updatedsdk_sessionmapping in the append-only log.rebuildConversation(jsonl hydration +ResumeSaga) treats the marker as a boundary, andResumeSaga.findSessionIdpicks up the post-clear session id, so cloud sandbox restarts and desktop cold reconnects resume the fresh SDK session with only post-clear turns.usage_update./clearprompt is only broadcast (and thus logged) once the new session is confirmed live, so a timeout leaves no orphaned entry in the log. A "Clearing…" status indicator mirrors the existing compaction spinner, so a slow or failed clear gives the user feedback instead of going silent, with aclearing_failedrow rendering the outcome. On success, the local session file left under the original session id gets deleted so a cold reconnect can't mistake it for current and resume the pre-clear conversation./clearalso now refuses while a turn is queued, not just while one is active.Codex sessions are unchanged,
/clearis Claude-adapter only for now.How did you test this?
/clearbehavior (fresh session swap, marker/mapping emission, busy/queued-turn guards, refresh-after-clear, timeout handling, stale jsonl cleanup, resumeSession id matching after a clear), command advertisement, clear-boundary handling in jsonl hydration andResumeSaga, and the UI divider and status-row rendering (includingclearing/clearing_failed).@posthog/agentsuite,@posthog/uisessions suite, andpnpm typecheckfor agent/core/ui plus Biome on the touched packages.Automatic notifications
Why:
/clearis a frequently reached-for command that PostHog Code currently rejects; implementing it cloud-first required making the session-log rehydration clear-aware.Created with PostHog Code