@@ -702,6 +702,10 @@ func (m *appModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
702702 // /new spawns a new tab when a session spawner is configured.
703703 return m .handleSpawnSession ("" )
704704
705+ case messages.ClearSessionMsg :
706+ // /clear resets the current tab with a fresh session in the same working dir.
707+ return m .handleClearSession ()
708+
705709 // --- Exit ---
706710
707711 case messages.ExitSessionMsg :
@@ -1116,6 +1120,46 @@ func (m *appModel) replaceActiveSession(ctx context.Context, sess *session.Sessi
11161120 return m , cmd
11171121}
11181122
1123+ // handleClearSession resets the current tab by creating a fresh session
1124+ // in the same working directory.
1125+ func (m * appModel ) handleClearSession () (tea.Model , tea.Cmd ) {
1126+ activeID := m .supervisor .ActiveID ()
1127+
1128+ // Cleanup old editor for the active session.
1129+ if ed , ok := m .editors [activeID ]; ok {
1130+ ed .Cleanup ()
1131+ }
1132+
1133+ // Create a fresh session in the same app, preserving the working dir.
1134+ m .application .NewSession ()
1135+ newSess := m .application .Session ()
1136+
1137+ // Rebuild all per-session UI components.
1138+ m .initSessionComponents (activeID , m .application , newSess )
1139+ m .dialogMgr = dialog .New ()
1140+ m .supervisor .SetRunnerTitle (activeID , "" )
1141+ m .sessionState .SetSessionTitle ("" )
1142+ m .sessionState .SetPreviousMessage (nil )
1143+
1144+ // Update persisted tab to point to the new session.
1145+ if m .tuiStore != nil {
1146+ ctx := context .Background ()
1147+ oldPersistedID := m .persistedSessionID (activeID )
1148+ if err := m .tuiStore .UpdateTabSessionID (ctx , oldPersistedID , newSess .ID ); err != nil {
1149+ slog .Warn ("Failed to update tab session ID after clear" , "error" , err )
1150+ }
1151+ }
1152+ m .persistActiveTab (newSess .ID )
1153+
1154+ m .reapplyKeyboardEnhancements ()
1155+
1156+ return m , tea .Sequence (
1157+ m .chatPage .Init (),
1158+ m .resizeAll (),
1159+ m .editor .Focus (),
1160+ )
1161+ }
1162+
11191163// handleSpawnSession spawns a new session.
11201164func (m * appModel ) handleSpawnSession (workingDir string ) (tea.Model , tea.Cmd ) {
11211165 // If no working dir specified, open the picker
0 commit comments