anomalyco / anomalyco/opencode
history_previous drops older session history and mixes prompt history across projects
@kommander is already working on this.
Since Sep 3, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- PR merge metrics
- PR metrics pending
Description
Description
Desc:
This looks related to #25811 and #19536, both of which were closed as not planned, but I think there is a little more going on here than just whether history should be project-scoped.
Two symptoms:
- Pressing up-arrow eventually shows prompts from completely unrelated projects.
- After restarting OpenCode, some of the prompts I previously entered in the current session/project are no longer available in history.
This is still happening in 1.18.27 and it is most obvious when resuming a session with opencode -c or opencode -s because one up-arrow to see the previous prompt usually pulls in a random prompt from a random project and session.
I dug into it because at first I thought I was somehow switching sessions without realizing it. It looks like prompt history is actually stored in one global file:
~/.local/state/opencode/prompt-history.jsonl
On my machine that file currently has exactly 50 lines:
wc -l ~/.local/state/opencode/prompt-history.jsonl
and those 50 entries contain prompts from at least three unrelated repos.
The JSONL records don't appear to contain any session or project identifier:
{"input":"...","parts":[],"mode":"normal"}
I also found the PromptHistory code in the bundled code reading prompt-history.jsonl, and the same code path appears to cap the history with a trailing slice(-N).
So unless I'm missing something, this is one global fixed-size prompt-history buffer shared by every OpenCode instance/project on the machine.
That would explain both things I'm seeing:
- history from project B appears when I press up-arrow in project A
- prompts from project A can disappear from history simply because enough prompts were entered elsewhere
The session itself is still fine. This is only the up-arrow prompt recall that gets lost.
One other possibly relevant detail: current OpenCode storage on this install is SQLite:
~/.local/share/opencode/opencode.db
and the DB already has a session_input table with session_id and prompt columns. Mine currently has no rows:
SELECT COUNT(*) FROM session_input;
-- 0
So it doesn't look like history_previous is using that table.
Expected behavior:
At minimum, pressing up-arrow in one project/session should not show prompts entered in a completely different project.
I would also expect prompts from the current session not to disappear from history because I used OpenCode somewhere else.
Steps to reproduce
- Run OpenCode in repo A and enter several recognizable prompts.
- Run OpenCode in unrelated repo B and enter several different prompts.
- Go back to repo A.
- Press up-arrow repeatedly in the prompt box.
Eventually prompts entered in repo B show up in repo A.
To see the eviction behavior, enter enough prompts across other projects to roll the global history forward, then restart OpenCode in repo A and check its up-arrow history again.
You can also inspect the backing file directly:
wc -l ~/.local/state/opencode/prompt-history.jsonl
cat ~/.local/state/opencode/prompt-history.jsonl
OpenCode version: 1.18.27
OS: Linux
Plugins: None that should affect prompt history.
Screenshot / share link
I don't have a useful screenshot for this, and I don't want to create a public share containing prompts from unrelated/private projects.
Plugins
No response
OpenCode version
No response
Steps to reproduce
No response
Screenshot and/or share link
No response
Operating System
No response
Terminal
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.