anthropics / anthropics/claude-code
[FEATURE] Persist the Ctrl+S prompt stash across exit and restore it on --continue / --resume (parity with background sessions)
- Lingua principale
- Python
- Stelle
- 145k
- Fork
- 23.1k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
### Preflight Checklist
- [x] I have searched [existing requests](https://github.com/anthropics/claude-code/issues?q=is%3Aissue%20label%3Aenhancement) and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
### Problem Statement
A stashed prompt is work-in-progress that silently disappears when I exit a terminal session, so the stash is a lossy place to park a long prompt.
The stash is documented as a place to set a draft aside. [Interactive mode](https://code.claude.com/docs/en/interactive-mode) describes `Ctrl+S` as "Stash or restore prompt":
> With text in the input, stashes it and clears the prompt. Pressed again on an empty prompt, restores the stashed text, cursor position, and pasted content
[Keybindings](https://code.claude.com/docs/en/keybindings) lists the action as `chat:stash` / `Ctrl+S` / "Stash current prompt".
Nothing in those pages says the stash is scoped to the running process, so "set this aside and come back to it" reads like it survives coming back to the session. It does not, for a normal terminal session. [Manage sessions](https://code.claude.com/docs/en/sessions#what-a-resumed-session-restores) enumerates what comes back:
> A resumed session restores the conversation along with the state saved in it:
> * Conversation history [...]
> * Model [...]
> * Agent [...]
> * Permission mode [...]
> * Active goal [...]
> * Scheduled tasks [...]
The stash is not on that list, and the paragraph that follows covers only configuration flags (`--mcp-config`, `--settings`, `--plugin-dir`, `--fallback-model`, `--add-dir`), so there is no documented statement either way — the draft just isn't restored.
**This already works for background sessions.** [Agent view → What persists across restarts](https://code.claude.com/docs/en/agent-view#what-persists-across-restarts) says:
> A prompt you stashed with `Ctrl+S` while attached is kept with the session too. Reopen the session after its process was stopped or restarted, and `Ctrl+S` restores the stashed text. Pasted content in the stash doesn't survive the restart.
And the agent view version history for v2.1.257:
> A prompt stashed with `Ctrl+S` inside an opened background session is kept with the session, so `Ctrl+S` restores it after the session's process is stopped and started again. Before this release, the stash lived only in the running process and was lost when the session went idle long enough for its process to stop, or when it was stopped and then reopened.
So the stash is already written to per-session state and restored after a process restart — just only for background sessions. A foreground terminal session, which persists strictly more (history, model, agent, permission mode, active goal, scheduled tasks), throws the draft away.
**Reproduced on v2.1.270** in a scratch git repo:
1. `claude`, send one short prompt so the session is stored.
2. Type a distinctive draft, press `Ctrl+S`. The `› stashed` indicator appears and the input clears.
3. Press `Ctrl+S` again on the empty prompt — the draft comes back, confirming it is stashed. `Ctrl+S` once more to re-stash it.
4. `/exit`.
5. `claude --continue` in the same directory. The conversation history is restored.
6. Press `Ctrl+S` on the empty prompt. **Nothing is restored.** No indicator, no draft, no warning that a stash was discarded on exit.
This is only about the stash, not about [queued messages](https://code.claude.com/docs/en/interactive-mode#queue-messages-while-claude-works) (`Enter` while Claude is working). Those are an in-turn queue with their own semantics; I'm not asking for anything about them here.
### Proposed Solution
Persist the stash with the session and restore it on resume, using the same mechanism background sessions already use.
- Write the stash into the session's stored state when it is set (or at exit), and load it when the session is resumed, so `Ctrl+S` on an empty prompt restores it after `claude --continue`, `claude --resume `, `claude --resume `, the session picker, and `/resume`.
- Add "Stashed prompt" to the [What a resumed session restores](https://code.claude.com/docs/en/sessions#what-a-resumed-session-restores) list so the behavior is discoverable.
- Matching the documented background-session caveat is fine: restoring the text (and ideally cursor position) while pasted content does not survive the restart would already solve the problem, as long as the loss is documented rather than silent.
A per-project stash instead of per-session would also be acceptable, and would additionally help when a session is abandoned rather than resumed — but per-session parity with background sessions is the smaller, more obvious change and is what I'd like first.
### Alternative Solutions
Both current workarounds defeat the point of an in-TUI stash:
- **Retype the prompt.** For the long, carefully-worded prompts that are worth parking in the first place, this is exactly the work the stash was supposed to protect.
- **Park the draft in an external scratch file.** This means leaving the TUI, opening an editor, saving, then pasting back — the context switch the stash exists to avoid. It also loses cursor position and pasted content. `Ctrl+G` (external editor) helps compose but doesn't give you a durable parking spot tied to the session.
Neither is discoverable at the moment it matters, because nothing warns you that exiting will discard the stash.
### Related issues
- #75663 — stashed prompt lost when a background agent goes cold. Same root cause (stash held only in process memory), and it asked for exactly the on-disk persistence that v2.1.257 then shipped **for background sessions**. This request is the remaining half: the same persistence for foreground terminal sessions resumed with `--continue` / `--resume`.
- #93717 — copy or move the current draft to a *different* session. Overlapping mechanism (an on-disk stash would enable it), different ask: that one is about moving a draft between sessions, this one is about the same session surviving exit.
- #79185 — make the stash a LIFO stack instead of a single slot. Orthogonal and complementary: this request is about the stash's lifetime, not its capacity. Either can ship without the other.
- #26615 (closed) — "stash isn't saved to disk". Same underlying observation, filed against v2.1.45, before background-session stash persistence existed; it bundled the disk write together with the stack request.
- #30405 (closed, not planned) — a persistent prompt *library* with a new `/stash` command, `$1`/`$2` placeholders, project-level sharing, fuzzy search, and import/export. This request is deliberately much narrower: no new command, no library, no templating, no new storage concept. Just keep the existing single-slot stash with the session that Claude Code already persists.
### Priority
Medium — data loss, but recoverable by retyping.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Compare the existing background-session stash persistence with the foreground paths for `--continue`, `--resume`, the session picker, and `/resume`. Trace where the session state is written and restored, then verify that a stashed prompt returns after each resume path and that the sessions documentation lists the restored stash and its pasted-content limitation.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Ambito
- cli, documentation
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Attiva
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 52/100