Skip to content

Commit 033291b

Browse files
committed
fix(cli): gracefully exit when user declines to fork session from another project
When --resume <session-id> targets a session in a different project, the CLI prompts whether to fork into the current directory. If the user answers 'n', the previous code threw an uncaught Error that bubbled up as an ugly stack trace. Instead, return undefined from createSessionManager and handle it in runRootCommand by printing a dimmed message and returning cleanly. Fixes the uncaught exception: Error: Session "..." is in another project (C:\tmp). at createSessionManager (.../main.ts:407:16)
1 parent 159f2d8 commit 033291b

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

packages/coding-agent/src/main.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ async function createSessionManager(
412412
if (normalizedCwd !== normalizedMatchCwd) {
413413
const shouldFork = await promptForkSession(match.session);
414414
if (!shouldFork) {
415-
throw new Error(`Session "${sessionArg}" is in another project (${match.session.cwd}).`);
415+
return undefined;
416416
}
417417
return await SessionManager.forkFrom(match.session.path, cwd, parsed.sessionDir);
418418
}
@@ -852,7 +852,12 @@ export async function runRootCommand(
852852
cwd,
853853
settingsInstance,
854854
);
855-
855+
// User declined to fork a session from another project — exit gracefully
856+
if (typeof parsedArgs.resume === "string" && !sessionManager) {
857+
process.stdout.write(`${chalk.dim(`Resume cancelled: session is in another project.`)}
858+
`);
859+
return;
860+
}
856861
// Handle --resume (no value): show session picker
857862
if (parsedArgs.resume === true && !parsedArgs.fork) {
858863
const sessions = await logger.time("SessionManager.list", SessionManager.list, cwd, parsedArgs.sessionDir);

0 commit comments

Comments
 (0)