MCPcopy Create free account
hub / github.com/WJX20/claude-code / saveWorktreeState

Function saveWorktreeState

src/utils/sessionStorage.ts:2890–2921  ·  view source on GitHub ↗
(
  worktreeSession: PersistedWorktreeSession | null,
)

Source from the content-addressed store, hash-verified

2888 * so --resume knows not to cd back into it.
2889 */
2890export function saveWorktreeState(
2891 worktreeSession: PersistedWorktreeSession | null,
2892): void {
2893 // Strip ephemeral fields (creationDurationMs, usedSparsePaths) that callers
2894 // may pass via full WorktreeSession objects — TypeScript structural typing
2895 // allows this, but we don't want them serialized to the transcript.
2896 const stripped: PersistedWorktreeSession | null = worktreeSession
2897 ? {
2898 originalCwd: worktreeSession.originalCwd,
2899 worktreePath: worktreeSession.worktreePath,
2900 worktreeName: worktreeSession.worktreeName,
2901 worktreeBranch: worktreeSession.worktreeBranch,
2902 originalBranch: worktreeSession.originalBranch,
2903 originalHeadCommit: worktreeSession.originalHeadCommit,
2904 sessionId: worktreeSession.sessionId,
2905 tmuxSessionName: worktreeSession.tmuxSessionName,
2906 hookBased: worktreeSession.hookBased,
2907 }
2908 : null
2909 const project = getProject()
2910 project.currentSessionWorktree = stripped
2911 // Write eagerly when the file already exists (mid-session enter/exit).
2912 // For --worktree startup, sessionFile is null — materializeSessionFile
2913 // will write it on the first message via reAppendSessionMetadata.
2914 if (project.sessionFile) {
2915 appendEntryToFile(project.sessionFile, {
2916 type: 'worktree-state',
2917 worktreeSession: stripped,
2918 sessionId: getSessionId(),
2919 })
2920 }
2921}
2922
2923/**
2924 * Extracts the session ID from a log.

Callers 6

setupFunction · 0.85
callFunction · 0.85
restoreWorktreeForResumeFunction · 0.85
clearConversationFunction · 0.85
REPLFunction · 0.85

Calls 3

getProjectFunction · 0.85
appendEntryToFileFunction · 0.85
getSessionIdFunction · 0.85

Tested by

no test coverage detected