gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

Calling /clear drops entries from navigating history with the up arrow

Open jacob314 opened this issue 1 year ago • 6 comments

What happened?

When you type /clear it resets the chat history which is useful when trying to save chat tokens. However it breaks flows where users want to type clear and then repeat a prompt they just typed. For example, I often do this when trying to repeat the previous prompt to run and fix tests with a clean context window. Chats from before the current conversation are still shown just not chats from the latest conversation.

What did you expect to happen?

Expect the only effect of clear to be to clear the conversation history not break the history of chats accessible with the up arrow.

Client information

$ gemini /about
# paste output here

Login information

No response

Anything else we need to know?

No response

jacob314 avatar Aug 09 '25 05:08 jacob314

A simple solution would be to manage the history using a flag, which would ensure that the input history remains accessible after clearing the chat. However, considering future scalability and separation of concerns, we could also explore managing input history independently from the main chat history.

Which approach do you think would be more suitable for the project? Or do you have any other recommended solutions?

flowernotfound avatar Aug 09 '25 07:08 flowernotfound

I think managing input history separately might be the simplest. the two do not need to be the same. and the input history is small enough that storing it separately would not use significant memory.

jacob314 avatar Aug 09 '25 07:08 jacob314

@jacob314 Thank you for your response and suggestion. I will proceed with addressing the issue based on that approach.

flowernotfound avatar Aug 09 '25 09:08 flowernotfound

/clear is nuking two different things: the model context (good) and your local input history (bad when you want ↑ to repeat the last prompt). They should be separated.

Proposed behavior (short):

/clear: drop conversation context only; keep input history so ↑ still shows your previous prompt. /clear --all (optional): wipe both context and input history for privacy. Keep input history in a tiny separate ring buffer (e.g. 50–100 entries); negligible memory. Don’t store the /clear command itself as a history entry (or filter commands starting with /). Acceptance:

After /clear, pressing ↑ returns the last real prompt. After /clear --all, ↑ returns nothing. No noticeable performance or memory change. Happy to open a PR with that split if approved. Let me know.

MustafaKemal0146 avatar Aug 10 '25 16:08 MustafaKemal0146

In my case /clear doesnt clear the up arrow history. Is this has since been changed?

bekicot avatar Aug 17 '25 07:08 bekicot

It doesn't clear old history but it clears recently added history from your conversation which is really annoying if you cleared to reset the context and wanted to repeat a command you just entered.

jacob314 avatar Aug 21 '25 08:08 jacob314