opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Fixed: prompt now preserved when creating new session

Open opencode-agent[bot] opened this issue 1 month ago • 1 comments

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

opencode-agent[bot] avatar Nov 28 '25 20:11 opencode-agent[bot]

this PR did not in fact fix the issue

DanielFGray avatar Dec 01 '25 19:12 DanielFGray