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

Function restoreWorktreeForResume

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

Source from the content-addressed store, hash-verified

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