@@ -139,6 +139,11 @@ type UI struct {
139139 // keeps track of read files while we don't have a session id
140140 sessionFileReads []string
141141
142+ // initialSessionID is set when loading a specific session on startup.
143+ initialSessionID string
144+ // continueLastSession is set to continue the most recent session on startup.
145+ continueLastSession bool
146+
142147 lastUserMessageTime int64
143148
144149 // The width and height of the terminal in cells.
@@ -242,7 +247,7 @@ type UI struct {
242247}
243248
244249// New creates a new instance of the [UI] model.
245−func New(com *common.Common) *UI {
250+func New(com *common.Common, initialSessionID string, continueLast bool) *UI {
246251 // Editor components
247252 ta := textarea.New()
248253 ta.SetStyles(com.Styles.TextArea)
@@ -298,6 +303,8 @@ func New(com *common.Common) *UI {
298303 mcpStates: make(map[string]mcp.ClientInfo),
299304 notifyBackend: notification.NoopBackend{},
300305 notifyWindowFocused: true,
306+ initialSessionID: initialSessionID,
307+ continueLastSession: continueLast,
301308 }
302309
303310 status := NewStatus(com, ui)
@@ -346,9 +353,34 @@ func (m *UI) Init() tea.Cmd {
346353 cmds = append(cmds, m.loadCustomCommands())
347354 // load prompt history async
348355 cmds = append(cmds, m.loadPromptHistory())
356+ // load initial session if specified
357+ if cmd := m.loadInitialSession(); cmd != nil {
358+ cmds = append(cmds, cmd)
359+ }
349360 return tea.Batch(cmds...)
350361}
351362
363+// loadInitialSession loads the initial session if one was specified on startup.
364+func (m *UI) loadInitialSession() tea.Cmd {
365+ switch {
366+ case m.state != uiLanding:
367+ // Only load if we're in landing state (i.e., fully configured)
368+ return nil
369+ case m.initialSessionID != "":
370+ return m.loadSession(m.initialSessionID)
371+ case m.continueLastSession:
372+ return func() tea.Msg {
373+ sess, err := m.com.App.Sessions.GetLast(context.Background())
374+ if err != nil {
375+ return nil
376+ }
377+ return m.loadSession(sess.ID)()
378+ }
379+ default:
380+ return nil
381+ }
382+}
383+
352384// sendNotification returns a command that sends a notification if allowed by policy.
353385func (m *UI) sendNotification(n notification.Notification) tea.Cmd {
354386 if !m.shouldSendNotification() {