diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index 29cca133bb..b540f15726 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -814,6 +814,17 @@ function App(props: { onSnapshot?: () => Promise }) { dialog.clear() }, }, + { + name: "app.toggle.clear_prompt_history", + title: kv.get("clear_prompt_save_history", false) + ? "Don't include cleared prompts in history" + : "Include cleared prompts in history", + category: "System", + run: () => { + kv.set("clear_prompt_save_history", !kv.get("clear_prompt_save_history", false)) + dialog.clear() + }, + }, ].map((command) => ({ namespace: "palette", ...command, diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx index 630f725c79..89b36b3d38 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx @@ -82,6 +82,7 @@ export const { use: usePromptHistory, provider: PromptHistoryProvider } = create return store.history.at(store.index) }, append(item: PromptInfo) { + if (store.history.at(-1)?.input === item.input) return const entry = structuredClone(unwrap(item)) let trimmed = false setStore( diff --git a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx index c80daf9cff..de2a75dc46 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -1369,7 +1369,8 @@ export function Prompt(props: PromptProps) { } function clearPrompt() { - if (store.prompt.input.trim().length >= DRAFT_RETENTION_MIN_CHARS || store.prompt.parts.length > 0) { + const shouldSave = store.prompt.input.trim().length >= DRAFT_RETENTION_MIN_CHARS || store.prompt.parts.length > 0 + if (shouldSave || kv.get("clear_prompt_save_history", false)) { history.append({ ...store.prompt, mode: store.mode,