Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/claude/claudeLocal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,21 @@ export async function claudeLocal(opts: {
process.stdin.pause();
await new Promise<void>((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) {
Expand Down
21 changes: 11 additions & 10 deletions src/claude/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down