Bug: settings.json counts.files always reports 0 (PAI/USER doubled prefix in v5.0.0)"
Summary
In v5.0.0, settings.json.counts.files is always 0 because two files in the count pipeline build the wrong path to USER/. The bug is silent — countFilesRecursive catches ENOENT and returns 0, so it looks identical to "USER is empty."
Affected files
Releases/v5.0.0/.claude/hooks/handlers/UpdateCounts.ts(line 174)Releases/v5.0.0/.claude/PAI/TOOLS/GetCounts.ts(line 175)
Root cause
In v5.0.0, getPaiDir() (hooks/lib/paths.ts) returns ~/.claude/PAI, and GetCounts.ts defaults PAI_DIR to the same. So joining with the literal 'PAI/USER' produces:
~/.claude/PAI/PAI/USER ← does not exist
Every other path in the same getCounts() function uses paiDir-relative paths like 'MEMORY/LEARNING', 'MEMORY/WORK', etc. — the 'PAI/' prefix on the files: line is the outlier.
countFilesRecursive then ENOENTs and silently returns 0:
function countFilesRecursive(dir: string, extension?: string): number {
let count = 0;
try {
for (const entry of readdirSync(dir, { withFileTypes: true })) { ... }
} catch {
// Directory doesn't exist or not readable
}
return count;
}
Downstream, PAI/TOOLS/Banner.ts reads counts.files into userFiles, so the banner/statusline userFiles is always 0.
The intent is documented in GetCounts.ts:16 — "Files: All files in PAI/USER/ (recursive)" — meaning the USER/ directory at ${PAI_DIR}/USER (i.e. ~/.claude/PAI/USER), which is the actual layout in the v5.0.0 release tree.
Fix
Drop the PAI/ prefix on the files: line in both files:
- files: countFilesRecursive(join(paiDir, 'PAI/USER')),
+ files: countFilesRecursive(join(paiDir, 'USER')),
- files: countFilesRecursive(join(PAI_DIR, "PAI/USER")),
+ files: countFilesRecursive(join(PAI_DIR, "USER")),
Reproduction
$ jq '.counts.files' ~/.claude/settings.json
0
$ ls ~/.claude/PAI/PAI/USER
ls: ~/.claude/PAI/PAI/USER: No such file or directory
$ ls ~/.claude/PAI/USER | wc -l
# >> some positive number
Why this hid
The try { ... } catch {} in countFilesRecursive makes a path typo indistinguishable from an empty directory. Worth considering logging the failure (or distinguishing ENOENT from other errors) so similar typos surface earlier — but that's a follow-up; this issue is just about the path.
PR
I have a 2-line fix ready — opening a PR alongside this issue.
Fixed in the upstream tree (the source the next release builds from):
PAI/TOOLS/GetCounts.ts:186now usescountFilesRecursive(join(PAI_DIR, "USER"))— noPAI/prefix.hooks/handlers/UpdateCounts.tswas refactored in the same pass — it no longer writessettings.json.counts.*directly. The header on that file now reads: "Previously this handler ALSO wrote settings.json.counts.{skills,hooks,...} … now call GetCounts.ts directly." So the only writer of the field isGetCounts.ts, and that path is correct.
Your PR #1230 carries the same fix against the frozen Releases/v5.0.0/ snapshot — that snapshot won't be rebuilt, so the PR is still the cleanest way to help users installing directly from v5.0.0. Will look at it separately.
Closing this issue as fixed in next release. Thanks for the careful write-up — the root-cause section (try/catch swallowing ENOENT, making a path typo look like an empty directory) is the kind of evidence that makes triage actually fast.