Skip to content

session_dir_slug: the drive-letter fold stops applying past MAX_PATH, because cygpath -w returns a \\?\ prefix #294

Closed

Description

@jqit-ricky

Summary

On Windows, session_dir_slug stops folding the drive letter once the project path crosses MAX_PATH (260 chars) — silently reintroducing #263 for long paths, and additionally emitting four leading dashes that make the slug miss Claude Code's own session directory.

The cause is that cygpath -w returns a \\?\-prefixed path for long paths, and the fold's case pattern only matches a bare drive letter.

Reproduction

Against the installed 0.12.3 tree (Git for Windows bash, cygpath present):

. "$PIPELINE_DIR/scripts/lib-slug.sh"

short='C:\dev\project'
long="C:\\dev\\$(printf 'a%.0s' $(seq 1 130))\\$(printf 'b%.0s' $(seq 1 130))"

session_dir_slug "$short"   # -> c--dev-project          (folded, correct)
session_dir_slug "$long"    # -> ----C--dev-aaaa…-9ewsib (NOT folded, 4 leading dashes)

Observed:

path length cygpath -w session_dir_slug
C:\dev\project 14 C:\dev\project c--dev-project
C:\dev\aaa…\bbb… 268 \\?\C:\dev\aaa… ----C--dev-aaa…-9ewsib

Root cause

session_dir_slug runs cygpath -w first (lib-slug.sh:175-179), then folds the drive letter with:

case "$path" in
    ?:*)

cygpath -w returns \\?\C:\... once the path exceeds MAX_PATH, and \\?\C:\dev\x does not match ?:*. Tested directly:

'C:\dev\x'      -> MATCHES ?:*   (drive letter folds)
'\\?\C:\dev\x'  -> no match      (drive letter does not fold)

Impact

Two distinct consequences, both on exactly the paths the 200-char truncation already exists to protect:

  1. The drive letter is not folded, so a long-path project can produce C--… where every other project produces c--…. That is the A lowercase drive letter in CLAUDE_PROJECT_DIR makes git add match nothing, and the backup reports success #263 condition — a slug that cannot match its own tracked history — reintroduced for a subset of paths after fix(git-backup): a slug that cannot match its own history is not an empty store (#263) #267 fixed it for the rest.
  2. The slug gains four leading dashes from \\?\. Claude Code does not add that prefix when it names its own session directory, so the computed slug does not correspond to the transcript directory at all — the session_dir_slug does not truncate at 200 chars + hash, so deep project paths silently never save #157/fix(windows): non-ASCII paths silently disabled the whole pipeline (#144, #145) #156 class of silent miss.

Both are invisible on a case-insensitive filesystem until git is involved, which is what makes them worth catching in the function rather than downstream.

Suggested direction

Strip a \\?\ (and \\?\UNC\) prefix from the cygpath -w result before the fold, so the existing case sees the shape it was written for. That keeps the long-path handling that cygpath is doing for other reasons while restoring both the fold and the leading characters.

Happy to raise a PR with a test if that shape suits you — the existing bench-slug.sh/tests layout looks like the natural home.

How we found it, and one small ask

We (JQiT) drive remember from PowerShell on Windows and had to answer "what slug will the plugin compute?" from a non-bash caller. Calling session_dir_slug per tool call means a bash fork per call, so we maintain a small PowerShell port and verify it against the real function in our test suite — which is how the long-path divergence surfaced.

We would much rather not maintain a second implementation. If there is appetite for a documented canonical spec of the slug rules, or a cheap way to ask the plugin for a slug from another language, we would use it and delete ours. Entirely understood if that is out of scope — the defect above stands on its own either way.

Environment: remember 0.12.3 (installed tree), Windows 11, Git for Windows bash with cygpath present.

Activity

  1. fdaviddpt commented on Aug 2, 2026

    @fdaviddpt
    Contributor

    Both halves of this are now on main and released as v0.13.0.

    The defect. Fixed in #295. Your diagnosis was right and reproduced exactly — a stub emitting the long-path shape produced your slug character for character, hash included. The strip lives inside the cygpath branch on purpose, so it undoes only what cygpath just did: a directory literally named \\?\C: is legal on Linux and still slugs literally, because stripping unconditionally would rename those stores. \\?\UNC\ maps back to \\ rather than to nothing, since \\?\UNC\server\share is \\server\share and eating the separators would split one directory into two slugs.

    Reading that line also turned up a second failure: cygpath can exit 0 and print nothing, which emptied the path outright — and an empty slug is not a miss, it resolves to ~/.claude/projects/ itself, a directory that exists and holds every project's transcripts. Guarded now.

    The ask — we'd rather you deleted your port too. Two things shipped in #296:

    1. docs/slug-vectors.json — 37 conformance vectors (input path, plain and base64, expected slug, and the environment each assumes). It covers the six Windows drive spellings, UNC both forms, \\?\ and \\?\UNC\, the 200-char truncation on both sides of its boundary with the base36 hash, non-ASCII either side of the UTF-16 surrogate boundary, and ill-formed UTF-8. It is generated from the implementation and byte-compared against it on every CI run, so it cannot drift without our build going red. Point your PowerShell tests at that file and a divergence becomes our failure, not just yours. Vectors that depend on cygpath being present are marked, so a caller without it can tell which rows apply.

      We deliberately did not write a prose spec: it would drift from scripts/lib-slug.sh and be read as current long after it stopped being true.

    2. <REMEMBER_DIR>/tmp/session-slug — the slug is a pure function of PROJECT_DIR, which does not change mid-session, so there is no reason to fork per tool call at all. Session start now writes it once as key=value lines. Three states, not two: absent means it never ran, status=unavailable (with no slug= key) means it ran and could not answer, status=ok means the value is usable. Staleness is decided by project_dir only — a record from a dead session is still correct, so a timestamp would only offer a test that answers the wrong question. One documented hole: in external-storage mode with {slug} in data_dir, REMEMBER_DIR is itself named by the slug, so the file is unreachable without already knowing it. The vectors cover that case.

    The per-tool-call path is byte-identical to before, and a test asserts it.

    Thank you for this one — the report was unusually complete, and the second implementation you did not want to maintain is exactly what made the divergence visible. If the vector format is missing something your port needs, say so and we will add it.

    Note on delivery: v0.13.0 is tagged and released here, but the official plugin catalogue pins by commit sha and advances on its own automation, so it is not yet live for catalogue installs.

  2. added a commit that references this issue on Aug 2, 2026
    b1a0b41
  3. added 2 commits that reference this issue on Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions