From ae733666b88f63ae3fb16c0d07d833fd5065ead8 Mon Sep 17 00:00:00 2001 From: tomjamescn Date: Thu, 18 Dec 2025 04:54:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(claudeLocal.ts,=20session.ts):?= =?UTF-8?q?=20Enhance=20the=20handling=20logic=20for=20resume/continue=20f?= =?UTF-8?q?lags=20=F0=9F=92=A1=20docs(claudeLocal.ts,=20session.ts):=20Upd?= =?UTF-8?q?ate=20comments=20to=20reflect=20the=20new=20flag=20handling=20m?= =?UTF-8?q?ethod?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/claude/claudeLocal.ts | 12 +++++++++--- src/claude/session.ts | 21 +++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/claude/claudeLocal.ts b/src/claude/claudeLocal.ts index a0b9d861..9752d0fa 100644 --- a/src/claude/claudeLocal.ts +++ b/src/claude/claudeLocal.ts @@ -69,15 +69,21 @@ export async function claudeLocal(opts: { process.stdin.pause(); await new Promise((r, reject) => { const args: string[] = [] - + + // Check if user already provided resume/continue flags in claudeArgs + const hasResumeFlag = opts.claudeArgs?.some(arg => + arg === '-r' || arg === '--resume' || arg === '--continue' || arg === '-c' + ) ?? false; + if (startFrom) { // Resume existing session (Claude preserves the session ID) args.push('--resume', startFrom) - } else { + } else if (!hasResumeFlag) { + // Only add --session-id if user hasn't provided their own resume/continue flag // New session with our generated UUID args.push('--session-id', newSessionId!) } - + args.push('--append-system-prompt', systemPrompt); if (opts.mcpServers && Object.keys(opts.mcpServers).length > 0) { diff --git a/src/claude/session.ts b/src/claude/session.ts index 6cda75a2..2d7151b0 100644 --- a/src/claude/session.ts +++ b/src/claude/session.ts @@ -83,35 +83,36 @@ export class Session { /** * Consume one-time Claude flags from claudeArgs after Claude spawn - * Currently handles: --resume (with or without session ID) + * Currently handles: -r/--resume (with or without session ID) */ consumeOneTimeFlags = (): void => { if (!this.claudeArgs) return; - + const filteredArgs: string[] = []; for (let i = 0; i < this.claudeArgs.length; i++) { - if (this.claudeArgs[i] === '--resume') { + if (this.claudeArgs[i] === '--resume' || this.claudeArgs[i] === '-r') { + const flagName = this.claudeArgs[i]; // Check if next arg looks like a UUID (contains dashes and alphanumeric) if (i + 1 < this.claudeArgs.length) { const nextArg = this.claudeArgs[i + 1]; // Simple UUID pattern check - contains dashes and is not another flag if (!nextArg.startsWith('-') && nextArg.includes('-')) { - // Skip both --resume and the UUID + // Skip both -r/--resume and the UUID i++; // Skip the UUID - logger.debug(`[Session] Consumed --resume flag with session ID: ${nextArg}`); + logger.debug(`[Session] Consumed ${flagName} flag with session ID: ${nextArg}`); } else { - // Just --resume without UUID - logger.debug('[Session] Consumed --resume flag (no session ID)'); + // Just -r/--resume without UUID + logger.debug(`[Session] Consumed ${flagName} flag (no session ID)`); } } else { - // --resume at the end of args - logger.debug('[Session] Consumed --resume flag (no session ID)'); + // -r/--resume at the end of args + logger.debug(`[Session] Consumed ${flagName} flag (no session ID)`); } } else { filteredArgs.push(this.claudeArgs[i]); } } - + this.claudeArgs = filteredArgs.length > 0 ? filteredArgs : undefined; logger.debug(`[Session] Consumed one-time flags, remaining args:`, this.claudeArgs); }