Expand description
Where the Claude Code CLI keeps a conversation under a CLAUDE_CONFIG_DIR.
One implementation, because every reader has to agree with the CLI byte for byte: a resume check that computes a different folder name than the CLI reports a transcript that is sitting on disk as unreachable, and the agent loses its native resume. Three copies of this rule used to disagree, and the one on the resume path was wrong for any working directory holding an underscore, a space or most other punctuation.
Constants§
- PROJECT_
DIR_ 🔒NAME_ MAX - The CLI keeps this many characters of the sanitized path before it appends a hash instead.
Functions§
- canonical_
worktree_ 🔒root - For a linked worktree, the main checkout that owns it; otherwise
root(the CLI’ske/Ht). Anything that doesn’t check out — a.gitfile that isn’tgitdir:, a missingcommondir, a worktree whosegitdirdoesn’t point back — leavesrootas it is, as the CLI does. - git_
root 🔒 - The nearest directory at or above
dirholding a.gitdirectory or file (the CLI’sGt). - has_
linked_ worktrees - Whether the repository whose main checkout is
roothas linked worktrees — each of which sharesroot’s memory folder. - memory_
project_ root - The directory the CLI names a working directory’s auto-memory folder
after — not the working directory itself, unlike its sessions. The CLI’s
rule (its
defaultPath(), Claude Code v2.1.280): - path_
hash 🔒 Math.abs(TQ(cwd)): 31·h + c over UTF-16 code units, wrapping at 32 bits (Java’sString.hashCode).i32::MIN’s absolute value doesn’t fit ani32, and JavaScript numbers don’t wrap, so the magnitude is returned unsigned.- physical_
dir - The working directory as the CLI’s process sees it (
process.cwd()): symlinks resolved. On Windowscanonicalizereturns a\\?\verbatim path the CLI never sees, and the current directory keeps links as given. - project_
dir_ name - The folder under
<CLAUDE_CONFIG_DIR>/projects/that holds the sessions the CLI ran withcwdas its working directory. - radix_
36 🔒 Number.prototype.toString(36)for a non-negative integer.- real_
path pwith symlinks resolved, as the CLI’s process would name it. On Windowscanonicalizereturns a\\?\verbatim path, which names the folder----C--repowhere the CLI, seeingC:\repo, names itC--repo. Tests that build a working directory take it from here too: a rawcanonicalizegives them a path no real cwd has (#3749).- without_
verbatim_ 🔒prefix pwithout a leading\\?\. A verbatim UNC path (\\?\UNC\server\…) is kept: dropping only the prefix would leaveUNC\server\…, which is not the path the CLI sees.