MCPcopy
hub / github.com/codeaashu/claude-code / restoreWorktreeForResume

Function restoreWorktreeForResume

src/utils/sessionRestore.ts:332–366  ·  view source on GitHub ↗
(
  worktreeSession: PersistedWorktreeSession | null | undefined,
)

Source from the content-addressed store, hash-verified

330 * it back to disk.
331 */
332export function restoreWorktreeForResume(
333 worktreeSession: PersistedWorktreeSession | null | undefined,
334): void {
335 const fresh = getCurrentWorktreeSession()
336 if (fresh) {
337 saveWorktreeState(fresh)
338 return
339 }
340 if (!worktreeSession) return
341
342 try {
343 process.chdir(worktreeSession.worktreePath)
344 } catch {
345 // Directory is gone. Override the stale cache so the next
346 // reAppendSessionMetadata records "exited" instead of re-persisting
347 // a path that no longer exists.
348 saveWorktreeState(null)
349 return
350 }
351
352 setCwd(worktreeSession.worktreePath)
353 setOriginalCwd(getCwd())
354 // projectRoot is intentionally NOT set here. The transcript doesn't record
355 // whether the worktree was entered via --worktree (which sets projectRoot)
356 // or EnterWorktreeTool (which doesn't). Leaving projectRoot stable matches
357 // EnterWorktreeTool's behavior — skills/history stay anchored to the
358 // original project.
359 restoreWorktreeSession(worktreeSession)
360 // The /resume slash command calls this mid-session after caches have been
361 // populated against the old cwd. Cheap no-ops for the CLI-flag path
362 // (caches aren't populated yet there).
363 clearMemoryFileCaches()
364 clearSystemPromptSections()
365 getPlansDirectory.cache.clear?.()
366}
367
368/**
369 * Undo restoreWorktreeForResume before a mid-session /resume switches to

Callers 3

onSelectFunction · 0.85
REPLFunction · 0.85

Calls 9

saveWorktreeStateFunction · 0.85
setCwdFunction · 0.85
setOriginalCwdFunction · 0.85
getCwdFunction · 0.85
restoreWorktreeSessionFunction · 0.85
clearMemoryFileCachesFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected