Repository navigation
Description
Description
session_dir_slug() never truncates. Claude Code does: past 200 characters it keeps the first 200 and appends a hash of the path. So for any project whose slugged path exceeds 200 characters, the computed slug does not match the directory Claude Code created, SESSION_DIR points at nothing, the hook finds no transcript, and memory silently never saves.
This is the same failure mode as #144, reached by a different route — long path instead of non-ASCII path — and it is not fixed by #156.
Reproduction
Confirmed on a real session, not inferred. A project path 262 characters long:
$ cd /very/deep/…/gggggggggggggggggggg # 262 chars
$ claude -p 'reply with the single word ok'
ok
$ ls -t ~/.claude/projects/ | head -1 | awk '{print length, $0}'
207 -private-tmp-…-dddddddddddddddddddd--on930v
Claude Code wrote a 207-character directory. session_dir_slug returns the full 262-character slug. No overlap, so nothing is ever found.
The algorithm
From the shipped CLI bundle:
var jXA = 200;
function JXA(A) {
let q = A.replace(/[^a-zA-Z0-9]/g, "-");
if (q.length <= jXA) return q;
let K = 0;
for (let _ = 0; _ < A.length; _++) K = (K << 5) - K + A.charCodeAt(_), K |= 0;
return `${q.slice(0, jXA)}-${Math.abs(K).toString(36)}`;
}So: djb2-ish rolling hash over the original path (not the slug), charCodeAt so UTF-16 code units, forced to signed 32-bit by |0 each round, then Math.abs(...).toString(36).
I reimplemented that and it reproduces the observed directory name exactly (…dddddddddddddddddddd--on930v), so the algorithm above is verified rather than read-and-hoped.
Suggested fix
Extend session_dir_slug in scripts/detect-tools.sh: if the slug exceeds 200 characters, emit ${slug:0:200}-${hash}. The hash needs 32-bit signed wraparound and base36, which is awkward in pure bash — $PYTHON is already a hard dependency of every hook, and this branch is only reached for long paths, so paying a subprocess there costs nothing on the common path.
Worth pinning with a test that builds a >200-character path, since this class of bug is invisible until someone's checkout happens to be deep.
Notes
- Reachable in ordinary use: a monorepo with deep module nesting plus a long home directory gets there without anything unusual. The path that reproduced it is a scratch directory, but this repo's own module tree already reaches ~165 characters relative.
- Same silent-failure signature as session_dir_slug() mis-slugs non-ASCII (CJK) paths under byte-wise sed, silently disabling saves #144: no error, no
hook-errors.logentry, memory simply never appears. Since fix(windows): non-ASCII paths silently disabled the whole pipeline (#144, #145) #156 the hook does at least log a warning when the session directory is missing, which would surface this rather than leaving it invisible. - Found while reviewing fix(windows): non-ASCII paths silently disabled the whole pipeline (#144, #145) #156; deliberately left out of that PR to keep it scoped to the reported non-ASCII bugs.
Activity
fix(slug): one session-directory slug, and make it truncate (#187)
fix(paths): normalise CLAUDE_CONFIG_DIR, and cover it where it can break
fix(paths): normalise CLAUDE_CONFIG_DIR, and cover it where it can break
fix(paths): normalise CLAUDE_CONFIG_DIR, and cover it where it can break
fix(paths): normalise CLAUDE_CONFIG_DIR, and cover it where it can break
fix(paths): normalise CLAUDE_CONFIG_DIR, and cover it where it can br…
fix(slug): strip cygpath's \\?\ long-path prefix before the drive-let…