Skip to main content

Module claude_layout

Module claude_layout 

Source
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’s ke/Ht). Anything that doesn’t check out — a .git file that isn’t gitdir:, a missing commondir, a worktree whose gitdir doesn’t point back — leaves root as it is, as the CLI does.
git_root 🔒
The nearest directory at or above dir holding a .git directory or file (the CLI’s Gt).
has_linked_worktrees
Whether the repository whose main checkout is root has linked worktrees — each of which shares root’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’s String.hashCode). i32::MIN’s absolute value doesn’t fit an i32, 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 Windows canonicalize returns 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 with cwd as its working directory.
radix_36 🔒
Number.prototype.toString(36) for a non-negative integer.
real_path
p with symlinks resolved, as the CLI’s process would name it. On Windows canonicalize returns a \\?\ verbatim path, which names the folder ----C--repo where the CLI, seeing C:\repo, names it C--repo. Tests that build a working directory take it from here too: a raw canonicalize gives them a path no real cwd has (#3749).
without_verbatim_prefix 🔒
p without a leading \\?\. A verbatim UNC path (\\?\UNC\server\…) is kept: dropping only the prefix would leave UNC\server\…, which is not the path the CLI sees.