Skip to content

Track and persist Claude's returned session ID for conversation continuity #8

@adam91holt

Description

@adam91holt

Problem

When resuming a Claude session with --resume <session_id>, Claude may return a different session ID in its JSON output than the one requested. Currently, warelay doesn't track this, so subsequent messages may fail to continue the conversation properly.

Proposed solution

  1. Extract session_id from Claude's JSON output in command-reply.ts
  2. Compare returned session ID with the requested one
  3. If different, update the session store with the new ID

Affected files

  • src/auto-reply/command-reply.ts - add extractClaudeSessionId() and include sessionId in CommandReplyMeta
  • src/auto-reply/reply.ts - update session store when Claude returns a different session ID

Implementation

// command-reply.ts
export function extractClaudeSessionId(payload: unknown): string | undefined {
  if (!payload || typeof payload !== "object") return undefined;
  const obj = payload as Record<string, unknown>;
  return typeof obj.session_id === "string" ? obj.session_id : undefined;
}
// reply.ts - after getting response
if (meta.sessionId && sessionStore && sessionKey && meta.sessionId !== sessionId) {
  sessionStore[sessionKey] = {
    sessionId: meta.sessionId,
    updatedAt: Date.now(),
    systemSent,
  };
  await saveSessionStore(storePath, sessionStore);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions