@@ -139,6 +139,11 @@ type UI struct {
139 // keeps track of read files while we don't have a session id
139 // keeps track of read files while we don't have a session id
140 sessionFileReads []string
140 sessionFileReads []string
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
142 lastUserMessageTime int64
147 lastUserMessageTime int64
144 // The width and height of the terminal in cells.
149 // The width and height of the terminal in cells.
@@ -242,7 +247,7 @@ type UI struct {
244// New creates a new instance of the [UI] model.
249// 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 {
246 // Editor components
251 // Editor components
247 ta := textarea.New()
252 ta := textarea.New()
248 ta.SetStyles(com.Styles.TextArea)
253 ta.SetStyles(com.Styles.TextArea)
@@ -298,6 +303,8 @@ func New(com *common.Common) *UI {
298 mcpStates: make(map[string]mcp.ClientInfo),
303 mcpStates: make(map[string]mcp.ClientInfo),
299 notifyBackend: notification.NoopBackend{},
304 notifyBackend: notification.NoopBackend{},
300 notifyWindowFocused: true,
305 notifyWindowFocused: true,
306+ initialSessionID: initialSessionID,
307+ continueLastSession: continueLast,
303 status := NewStatus(com, ui)
310 status := NewStatus(com, ui)
@@ -346,9 +353,34 @@ func (m *UI) Init() tea.Cmd {
346 cmds = append(cmds, m.loadCustomCommands())
353 cmds = append(cmds, m.loadCustomCommands())
347 // load prompt history async
354 // load prompt history async
348 cmds = append(cmds, m.loadPromptHistory())
355 cmds = append(cmds, m.loadPromptHistory())
356+ // load initial session if specified
357+ if cmd := m.loadInitialSession(); cmd != nil {
358+ cmds = append(cmds, cmd)
349 return tea.Batch(cmds...)
360 return tea.Batch(cmds...)
363+// loadInitialSession loads the initial session if one was specified on startup.
364+func (m *UI) loadInitialSession() tea.Cmd {
366+ case m.state != uiLanding:
367+ // Only load if we're in landing state (i.e., fully configured)
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())
377+ return m.loadSession(sess.ID)()
352// sendNotification returns a command that sends a notification if allowed by policy.
384// sendNotification returns a command that sends a notification if allowed by policy.
353func (m *UI) sendNotification(n notification.Notification) tea.Cmd {
385func (m *UI) sendNotification(n notification.Notification) tea.Cmd {
354 if !m.shouldSendNotification() {
386 if !m.shouldSendNotification() {