Skip to content

Commit fefe98c

Browse files
feat(code): add /clear command to reset conversation history (#1248)
Co-authored-by: Jonathan Mieloo <32547391+jonathanlab@users.noreply.github.com>
1 parent 350c434 commit fefe98c

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { AvailableCommand } from "@agentclientprotocol/sdk";
2+
import { getSessionService } from "@features/sessions/service/service";
23
import { ANALYTICS_EVENTS, type FeedbackType } from "@shared/types/analytics";
34
import { track } from "@utils/analytics";
45
import { toast } from "@utils/toast";
@@ -51,6 +52,18 @@ const commands: CodeCommand[] = [
5152
makeFeedbackCommand("good", "good", "Positive"),
5253
makeFeedbackCommand("bad", "bad", "Negative"),
5354
makeFeedbackCommand("feedback", "general", "General"),
55+
{
56+
name: "clear",
57+
description: "Clear conversation history and start fresh",
58+
async execute(_args, ctx) {
59+
if (!ctx.repoPath || !ctx.taskId) {
60+
toast.error("Cannot clear: no active session");
61+
return;
62+
}
63+
await getSessionService().resetSession(ctx.taskId, ctx.repoPath);
64+
toast.success("Conversation cleared");
65+
},
66+
},
5467
];
5568

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

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,11 +1793,23 @@ export class SessionService {
17931793

17941794
/**
17951795
* Start a fresh session for a task, abandoning the old conversation.
1796-
* Clears the backend sessionId so the next reconnect creates a new
1797-
* session instead of attempting to resume the stale one.
1796+
* Tears down the current session and creates a new task run so that
1797+
* S3 logs start clean — old messages won't reappear on restart.
17981798
*/
17991799
async resetSession(taskId: string, repoPath: string): Promise<void> {
1800-
await this.reconnectInPlace(taskId, repoPath, null);
1800+
const session = sessionStoreSetters.getSessionByTaskId(taskId);
1801+
if (!session) return;
1802+
1803+
const { taskTitle } = session;
1804+
1805+
await this.teardownSession(session.taskRunId);
1806+
1807+
const auth = this.getAuthCredentials();
1808+
if (!auth) {
1809+
throw new Error("Unable to reach server. Please check your connection.");
1810+
}
1811+
1812+
await this.createNewLocalSession(taskId, taskTitle, repoPath, auth);
18011813
}
18021814

18031815
/**

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)