Skip to content

Commit a0c1945

Browse files
author
littlekirkycode
committed
feat(code): add /clear command to reset conversation history
Adds /clear slash command that resets conversation history and starts a fresh session. Suppresses the SDK's built-in /clear (which doesn't work in our context) and replaces it with our own implementation. resetSession() now clears UI history by skipping log replay on reconnect.
1 parent 76d9bd0 commit a0c1945

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

apps/code/src/renderer/features/message-editor/commands.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@ const commands: CodeCommand[] = [
5151
makeFeedbackCommand("good", "good", "Positive"),
5252
makeFeedbackCommand("bad", "bad", "Negative"),
5353
makeFeedbackCommand("feedback", "general", "General"),
54+
{
55+
name: "clear",
56+
description: "Clear conversation history and start fresh",
57+
async execute(_args, ctx) {
58+
if (!ctx.repoPath || !ctx.taskId) {
59+
toast.error("Cannot clear: no active session");
60+
return;
61+
}
62+
const { getSessionService } = await import(
63+
"@features/sessions/service/service"
64+
);
65+
await getSessionService().resetSession(ctx.taskId, ctx.repoPath);
66+
toast.success("Conversation cleared");
67+
},
68+
},
5469
];
5570

5671
export const CODE_COMMANDS: AvailableCommand[] = commands.map((cmd) => ({

apps/code/src/renderer/features/sessions/service/service.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,7 +1751,7 @@ export class SessionService {
17511751
* session instead of attempting to resume the stale one.
17521752
*/
17531753
async resetSession(taskId: string, repoPath: string): Promise<void> {
1754-
await this.reconnectInPlace(taskId, repoPath, null);
1754+
await this.reconnectInPlace(taskId, repoPath, null, true);
17551755
}
17561756

17571757
/**
@@ -1768,6 +1768,7 @@ export class SessionService {
17681768
taskId: string,
17691769
repoPath: string,
17701770
overrideSessionId?: string | null,
1771+
clearHistory = false,
17711772
): Promise<void> {
17721773
const session = sessionStoreSetters.getSessionByTaskId(taskId);
17731774
if (!session) return;
@@ -1788,7 +1789,13 @@ export class SessionService {
17881789
throw new Error("Unable to reach server. Please check your connection.");
17891790
}
17901791

1791-
const prefetchedLogs = await this.fetchSessionLogs(logUrl, taskRunId);
1792+
const prefetchedLogs = clearHistory
1793+
? {
1794+
rawEntries: [] as StoredLogEntry[],
1795+
sessionId: undefined,
1796+
adapter: undefined as Adapter | undefined,
1797+
}
1798+
: await this.fetchSessionLogs(logUrl, taskRunId);
17921799

17931800
// Determine sessionId: undefined = use from logs, null = strip (fresh), string = use as-is
17941801
const sessionId =

packages/agent/src/adapters/claude/session/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AvailableCommand } from "@agentclientprotocol/sdk";
22
import type { SlashCommand } from "@anthropic-ai/claude-agent-sdk";
33

44
const UNSUPPORTED_COMMANDS = [
5+
"clear",
56
"context",
67
"cost",
78
"keybindings-help",

0 commit comments

Comments
 (0)