Description
Summary
opencode run --archived no longer keeps scripted sessions out of session lists: the run archives the session, then the prompt it sends immediately unarchives it. Regression introduced by #66348 (first shipped in v2.4.2). The flag was added in v2.2.6 (#61270) specifically for scripted/CI runs and is now a no-op.
Environment
- opencode version: 2.4.3
- Client:
opencode run(non-interactive, scheduled via launchd; reproduces both with--standaloneand against the shared background service) - Model and provider: Not relevant (any)
- OS: macOS, Darwin 25.6.0 (arm64)
- Terminal: Not relevant (headless scheduled run)
- Shell: /bin/zsh
- Install/channel: release (Homebrew
opencode-v2) - Active plugins: None
Reproduction
- Run
opencode run --archived --title "archived run test" "Reply with OK". - After it finishes, list non-archived sessions:
opencode api get '/api/session?search=archived%20run%20test&archived=false'. - The session is returned, i.e. it is not archived. In the database,
session_v2.time_archivedis NULL.
Reproduces consistently, on every run.
Expected Behavior
Per the flag help ("Create the session archived so it stays out of session lists (useful for scripted or CI runs)") and the v2.2.6 release notes, the session should remain archived after the run and stay out of the TUI session list / /resume.
Actual Behavior
The session ends up unarchived and appears in /resume. An hourly scheduled agent run accumulated 70+ visible sessions in two weeks before this was noticed.
Additional Context
Root cause (verified in the v2.4.3 bundle):
runNonInteractiveapplies the flag before sending the prompt: it callssession.update({ sessionID, title, archived: true })when--archivedis set.- fix(server): unarchive a session when a person sends it input #66348 made
POST /api/session/:id/promptunarchive archived sessions (the endpoint description now says "An archived session is unarchived"). So the run's own prompt immediately undoes the archive.
#66348's description acknowledges the adjacent case ("any HTTP client counts as a person, so an external script that prompts through the API (for example opencode run --session … from a system cron) also unarchives. If that turns out to matter, a payload flag can opt out"), but the built-in --archived flag itself is now broken, which does not seem intended.
Workaround that works today: archive the session after the run completes via PATCH /api/session/{id} with {"archived": true}.
Possible fixes: apply the archived state after the run's execution completes, or have run --archived use the opt-out payload flag suggested in #66348.
Related: #66604 (archiving a running session via the API).
Activity
opencodejr commentedon Nov 30, 2026
Thanks for the detailed report and the root-cause analysis. I reproduced this on the released 2.4.3, with nothing faked.
opencode run --standalone --archived --title "archived run test" "Reply with OK"finishes normally. Afterwards,opencode api --standalone get '/api/session?search=…&archived=false'returns the session, it has notime.archived, and thearchived=truequery is empty.dev(ca4c03d). I ran it there against a server started from the checkout. The session ended up unarchived even though the model call failed, because the server unarchives as soon as it accepts the prompt.The script below reproduces it. Until there's a fix, your workaround of sending
PATCH /api/session/{id}with{"archived": true}after the run should still keep these sessions out of the lists. Related: #66348, the change that made a prompt unarchive a session.Reproduction script (repro.sh)
Run it:
sh repro.shsakaintp commentedon Nov 30, 2026
I would like to take this issue. I found no open PR directly fixing
run --archived; #66503 is a broader session archive-management feature. On currentdev,runNonInteractivestill archives before its first prompt, while the server unarchives on admitted prompt input. Could you assign this to me? I can keep the existing API unarchive behavior and have the run preserve its explicit archived state, with focused CLI regression coverage. Any Protocol/HttpApi change would follow the required generation workflow.