feat: defer session creation until first user+assistant message exchange
- Sessions are no longer created immediately on startup - Session files only created after at least 1 user message and 1 assistant response - Prevents empty session files when agent is launched and immediately quit - Messages are queued until session is initialized - Continue/resume modes properly mark sessions as already initialized
This commit is contained in:
@@ -425,8 +425,8 @@ export async function main(args: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
// Start session
|
||||
sessionManager.startSession(agent.state);
|
||||
// Note: Session will be started lazily after first user+assistant message exchange
|
||||
// (unless continuing/resuming, in which case it's already initialized)
|
||||
|
||||
// Inject project context (AGENT.md/CLAUDE.md) if not continuing/resuming
|
||||
if (!parsed.continue && !parsed.resume) {
|
||||
@@ -454,6 +454,11 @@ export async function main(args: string[]) {
|
||||
// Save messages on completion
|
||||
if (event.type === "message_end") {
|
||||
sessionManager.saveMessage(event.message);
|
||||
|
||||
// Check if we should initialize session now (after first user+assistant exchange)
|
||||
if (sessionManager.shouldInitializeSession(agent.state.messages)) {
|
||||
sessionManager.startSession(agent.state);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user