MCPcopy Index your code
hub / github.com/liuup/claude-code-analysis / processResumedConversation

Function processResumedConversation

src/utils/sessionRestore.ts:409–551  ·  view source on GitHub ↗
(
  result: ResumeLoadResult,
  opts: {
    forkSession: boolean
    sessionIdOverride?: string
    transcriptPath?: string
    includeAttribution?: boolean
  },
  context: {
    modeApi: CoordinatorModeApi | null
    mainThreadAgentDefinition: AgentDefinition | undefined
    agentDefinitions: AgentDefinitionsResult
    currentCwd: string
    cliAgents: AgentDefinition[]
    initialState: AppState
  },
)

Source from the content-addressed store, hash-verified

407 * and --resume paths in main.tsx.
408 */
409export async function processResumedConversation(
410 result: ResumeLoadResult,
411 opts: {
412 forkSession: boolean
413 sessionIdOverride?: string
414 transcriptPath?: string
415 includeAttribution?: boolean
416 },
417 context: {
418 modeApi: CoordinatorModeApi | null
419 mainThreadAgentDefinition: AgentDefinition | undefined
420 agentDefinitions: AgentDefinitionsResult
421 currentCwd: string
422 cliAgents: AgentDefinition[]
423 initialState: AppState
424 },
425): Promise<ProcessedResume> {
426 // Match coordinator/normal mode to the resumed session
427 let modeWarning: string | undefined
428 if (feature('COORDINATOR_MODE')) {
429 modeWarning = context.modeApi?.matchSessionMode(result.mode)
430 if (modeWarning) {
431 result.messages.push(createSystemMessage(modeWarning, 'warning'))
432 }
433 }
434
435 // Reuse the resumed session's ID unless --fork-session is specified
436 if (!opts.forkSession) {
437 const sid = opts.sessionIdOverride ?? result.sessionId
438 if (sid) {
439 // When resuming from a different project directory (git worktrees,
440 // cross-project), transcriptPath points to the actual file; its dirname
441 // is the project dir. Otherwise the session lives in the current project.
442 switchSession(
443 asSessionId(sid),
444 opts.transcriptPath ? dirname(opts.transcriptPath) : null,
445 )
446 // Rename asciicast recording to match the resumed session ID so
447 // getSessionRecordingPaths() can discover it during /share
448 await renameRecordingForSession()
449 await resetSessionFilePointer()
450 restoreCostStateForSession(sid)
451 }
452 } else if (result.contentReplacements?.length) {
453 // --fork-session keeps the fresh startup session ID. useLogMessages will
454 // copy source messages into the new JSONL via recordTranscript, but
455 // content-replacement entries are a separate entry type only written by
456 // recordContentReplacement (which query.ts calls for newlyReplaced, never
457 // the pre-loaded records). Without this seed, `claude -r {newSessionId}`
458 // finds source tool_use_ids in messages but no matching replacement records
459 // → they're classified as FROZEN → full content sent (cache miss, permanent
460 // overage). insertContentReplacement stamps sessionId = getSessionId() =
461 // the fresh ID, so loadTranscriptFile's keyed lookup will match.
462 await recordContentReplacement(result.contentReplacements)
463 }
464
465 // Restore session metadata so /status shows the saved name and metadata
466 // is re-appended on session exit. Fork doesn't take ownership of the

Callers 1

runFunction · 0.85

Calls 15

createSystemMessageFunction · 0.85
switchSessionFunction · 0.85
asSessionIdFunction · 0.85
resetSessionFilePointerFunction · 0.85
recordContentReplacementFunction · 0.85
restoreSessionMetadataFunction · 0.85
restoreWorktreeForResumeFunction · 0.85
adoptResumedSessionFileFunction · 0.85
restoreAgentFromSessionFunction · 0.85
saveModeFunction · 0.85

Tested by

no test coverage detected