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

Function saveWorktreeState

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

Source from the content-addressed store, hash-verified

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