Skip to content

feat(core): add reset-only /clear command#379

Open
xukp20 wants to merge 4 commits intochenhg5:mainfrom
xukp20:feat/clear-command
Open

feat(core): add reset-only /clear command#379
xukp20 wants to merge 4 commits intochenhg5:mainfrom
xukp20:feat/clear-command

Conversation

@xukp20
Copy link
Copy Markdown
Contributor

@xukp20 xukp20 commented Mar 30, 2026

Summary

Add a reset-only /clear command for the current session.

This implements the original request from #354: clear the current session context in place without creating a new session entry like /new.

What changed

  • add /clear as a first-class command
  • keep the current logical session and active session slot unchanged
  • clear local history for the current session
  • detach the current backend agent session binding
  • clean up the current interactive state so the next message starts a fresh backend session
  • add regression tests for:
    • clearing the current session in place
    • preserving the current session identity/name
    • workspace-scoped /clear
    • invalid /clear usage
  • update i18n strings and usage docs

Why

Today, the only way to start fresh is /new, which creates a brand new session.

That makes /list grow quickly even in cases where the user does not want a new logical session, and only wants to clear the current conversation context while keeping the same session identity.

This PR addresses the original feature request in #354.

Maintainer context on #354:

  • the feature was already acknowledged and marked as planned with P2 priority

Scope decision

While implementing /clear, I also evaluated whether cc-connect should support a native clear path in the underlying CLI session.

That native path is intentionally not included in this PR.

Reasons:

  1. Codex native slash commands are not reliable enough in exec/resume --json mode
    Related investigation: [Bug] Codex native slash commands are not reliable in exec/resume mode (/compact and /clear) #378

    In particular:

    • /clear is not behaviorally reliable in direct Codex CLI testing
    • /compact also does not appear stable enough to treat as a guaranteed native capability in the current integration mode
  2. Claude Code native /clear should be validated separately before exposing it in cc-connect
    Claude Code does support native slash commands in general, but /clear behavior in the current cc-connect integration path still needs separate validation, including Claude-side session/control semantics.

Because of that, this PR keeps the implementation conservative:

  • /clear only resets the session at the cc-connect layer
  • it reuses the same cc-connect logical session
  • it achieves a “fresh start” by dropping the old backend session binding and starting a new backend session on the next user message

Validation

  • go build ./...
  • go test ./... -v -race
  • go test ./... -coverprofile=coverage.out -covermode=atomic
  • $(go env GOPATH)/bin/staticcheck ./...
  • $(go env GOPATH)/bin/actionlint -color

Related issues

Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Useful feature for session management.

Review summary:

  • /clear resets session context without creating new session entry
  • ✅ Preserves session identity/name
  • ✅ Conservative implementation (cc-connect layer only)
  • ✅ Tests added
  • ✅ i18n updated
  • ✅ Fixes #354

Good addition to session management options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 支持 /clear 命令原地清空当前 session 上下文

2 participants