From 738d6c889956ec9924f9537d703764f116990bc7 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Sun, 1 Feb 2026 21:01:15 -0500 Subject: [PATCH 1/3] feat: save prompt to history when cleared with Ctrl+C When users press Ctrl+C to clear the input field, the current prompt is now saved to history before clearing. This allows users to navigate back to cleared prompts using arrow keys, preventing loss of work. Addresses #11489 --- packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx | 4 ++++ 1 file changed, 4 insertions(+) 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 8576dd5763ab..9032b0940c4d 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -832,6 +832,10 @@ export function Prompt(props: PromptProps) { // If no image, let the default paste behavior continue } if (keybind.match("input_clear", e) && store.prompt.input !== "") { + history.append({ + ...store.prompt, + mode: store.mode, + }) input.clear() input.extmarks.clear() setStore("prompt", { From 2c6ff354004bd6134ee0387c9691b21cd8b47519 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Sun, 1 Feb 2026 21:12:48 -0500 Subject: [PATCH 2/3] feat: add toggle to control whether cleared prompts are saved to history Adds a toggle command in the System category that allows users to enable or disable saving cleared prompts to history. The feature is disabled by default to preserve existing behavior. When enabled via the command palette ("Include cleared prompts in history"), pressing Ctrl+C will save the current prompt to history before clearing it, allowing users to navigate back with arrow keys. The setting persists in kv.json. --- packages/opencode/src/cli/cmd/tui/app.tsx | 9 +++++++++ .../src/cli/cmd/tui/component/prompt/index.tsx | 10 ++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/cli/cmd/tui/app.tsx b/packages/opencode/src/cli/cmd/tui/app.tsx index 713def2e5af4..12f68a15c5e2 100644 --- a/packages/opencode/src/cli/cmd/tui/app.tsx +++ b/packages/opencode/src/cli/cmd/tui/app.tsx @@ -582,6 +582,15 @@ function App() { dialog.clear() }, }, + { + title: kv.get("clear_prompt_save_history", false) ? "Don't include cleared prompts in history" : "Include cleared prompts in history", + value: "app.toggle.clear_prompt_history", + category: "System", + onSelect: (dialog) => { + kv.set("clear_prompt_save_history", !kv.get("clear_prompt_save_history", false)) + dialog.clear() + }, + }, ]) createEffect(() => { 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 9032b0940c4d..801a2364138b 100644 --- a/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx +++ b/packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx @@ -832,10 +832,12 @@ export function Prompt(props: PromptProps) { // If no image, let the default paste behavior continue } if (keybind.match("input_clear", e) && store.prompt.input !== "") { - history.append({ - ...store.prompt, - mode: store.mode, - }) + if (kv.get("clear_prompt_save_history", false)) { + history.append({ + ...store.prompt, + mode: store.mode, + }) + } input.clear() input.extmarks.clear() setStore("prompt", { From 8805dfc8496858bf090cabe12157db1b75d142b4 Mon Sep 17 00:00:00 2001 From: Ariane Emory Date: Tue, 10 Feb 2026 22:21:39 -0500 Subject: [PATCH 3/3] fix: deduplicate prompt history entries Avoid adding duplicate entries to prompt history when the same input is appended multiple times (e.g., clearing with ctrl+c then restoring via history navigation and clearing again). --- packages/opencode/src/cli/cmd/tui/component/prompt/history.tsx | 1 + 1 file changed, 1 insertion(+) 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 e90503e9f52e..d7bf1486146b 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 = clone(item) let trimmed = false setStore(