[PR #4878] Fixed: prompt now preserved when creating new session #11153

Closed
opened 2026-02-16 18:15:57 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/4878

State: closed
Merged: No


Excellent! The fix has been successfully implemented and committed. Let me create a summary of what was done:

Summary

I've successfully fixed the issue where the prompt input was being cleared when creating a new session with <C-x> n. Here's what was implemented:

Changes Made:

  1. Extended HomeRoute Type (context/route.tsx):

    • Added optional initialPrompt field to carry prompt state when navigating to home
  2. Created PromptRef Context (context/prompt.tsx):

    • New context provider to track the currently active prompt ref across the app
    • Allows the session.new command to access the current prompt
  3. Enhanced PromptRef Interface (component/prompt/index.tsx):

    • Added current: PromptInfo property to expose the current prompt state
    • Allows other parts of the app to read the current prompt text and attachments
  4. Updated App Component (app.tsx):

    • Imported and added PromptRefProvider to the provider tree
    • Modified session.new command handler to capture the current prompt and pass it through the route
    • Only passes the prompt if the prompt input is focused
  5. Updated Home Component (routes/home.tsx):

    • Now checks for initialPrompt from the route first
    • Falls back to args.prompt if no initialPrompt is provided
    • Automatically restores the prompt when navigating to home

How It Works:

When a user presses <C-x> n to create a new session:

  1. The session.new command checks if there's an active focused prompt
  2. If yes, it captures the current prompt state (text and attachments)
  3. The state is passed through the route to the home screen
  4. The Home component receives this state and restores it automatically
  5. The user's prompt is preserved and ready to be submitted

This allows users to seamlessly switch to a new session without losing their typed prompt!

Closes #4872

New%20session%20-%202025-11-28T20%3A43%3A35.984Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4878 **State:** closed **Merged:** No --- Excellent! The fix has been successfully implemented and committed. Let me create a summary of what was done: ## Summary I've successfully fixed the issue where the prompt input was being cleared when creating a new session with `<C-x> n`. Here's what was implemented: ### Changes Made: 1. **Extended HomeRoute Type** (`context/route.tsx`): - Added optional `initialPrompt` field to carry prompt state when navigating to home 2. **Created PromptRef Context** (`context/prompt.tsx`): - New context provider to track the currently active prompt ref across the app - Allows the session.new command to access the current prompt 3. **Enhanced PromptRef Interface** (`component/prompt/index.tsx`): - Added `current: PromptInfo` property to expose the current prompt state - Allows other parts of the app to read the current prompt text and attachments 4. **Updated App Component** (`app.tsx`): - Imported and added PromptRefProvider to the provider tree - Modified session.new command handler to capture the current prompt and pass it through the route - Only passes the prompt if the prompt input is focused 5. **Updated Home Component** (`routes/home.tsx`): - Now checks for `initialPrompt` from the route first - Falls back to args.prompt if no initialPrompt is provided - Automatically restores the prompt when navigating to home ### How It Works: When a user presses `<C-x> n` to create a new session: 1. The session.new command checks if there's an active focused prompt 2. If yes, it captures the current prompt state (text and attachments) 3. The state is passed through the route to the home screen 4. The Home component receives this state and restores it automatically 5. The user's prompt is preserved and ready to be submitted This allows users to seamlessly switch to a new session without losing their typed prompt! Closes #4872 <a href="https://opencode.ai/s/cZYKH1tV"><img width="200" alt="New%20session%20-%202025-11-28T20%3A43%3A35.984Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI1LTExLTI4VDIwOjQzOjM1Ljk4NFo=.png?model=opencode/claude-haiku-4-5&version=1.0.119&id=cZYKH1tV" /></a> [opencode session](https://opencode.ai/s/cZYKH1tV)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/sst/opencode/actions/runs/19773483134)
yindo added the pull-request label 2026-02-16 18:15:57 -05:00
yindo closed this issue 2026-02-16 18:15:57 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11153