thedotmack/claude-mem · warning
git ls-files failed, falling back to directory walk
Error message
git ls-files failed, falling back to directory walk
What it means
getTrackedFolders runs `git ls-files` to enumerate tracked folders for claude-md commands. If the git command fails (not a repo, git missing, permission errors), it logs the warning 'git ls-files failed, falling back to directory walk' and rebuilds the folder list via walkDirectoriesWithIgnore instead. This is a non-fatal degradation warning, not a thrown error.
Solutions
- Initialize or clone a git repo in the working directory (git init / git clone) so ls-files works
- Install git or fix PATH so the git binary is reachable
- For 'dubious ownership' errors run: git config --global --add safe.directory <path>
- Accept the fallback — it still returns folders via directory walk honoring ignore files — but expect slower/less accurate results than git-tracked enumeration
Example fix
// before (in a non-repo dir)
getTrackedFolders('/tmp/project'); // warns, walks directories
// after
execSync('git init', { cwd: '/tmp/project' });
getTrackedFolders('/tmp/project'); // uses git ls-files Defensive patterns
Strategy: fallback
Validate before calling
import { execSync } from 'child_process';
import { existsSync } from 'fs';
if (!existsSync(`${workingDir}/.git`)) console.warn('Not a git repo; folder discovery will use the slow directory-walk fallback'); Try / catch
try {
execSync('git rev-parse --is-inside-work-tree', { cwd: workingDir, stdio: 'ignore' });
} catch {
// not a repo or git missing: rely on walkDirectoriesWithIgnore fallback
} Prevention
- Run claude-md folder discovery inside a proper git clone when possible
- Ensure git is installed and on PATH in containers/CI images
- Add safe.directory config for Docker volume-mounted repos to avoid ownership failures
- Maintain ignore files (.gitignore) so the directory-walk fallback produces comparable results
When it happens
Trigger: Running claude-md folder discovery in a directory that is not a git work tree, with git not installed/on PATH, or when git exits non-zero (permissions, dubious ownership, broken .git).
Common situations: Running the tool in a plain folder or tarball extract without .git; containers/minimal images lacking git; git's 'dubious ownership' safe.directory check failing in Docker; symlinked or read-only working directories.
Understand the failure class
Background: "git command failed": what it means when a tool shells out to git and git exits non-zero — this error's family across 21 libraries.
Related errors
- API key prompt cancelled — falling back to Claude provider.
- API key prompt cancelled — leaving existing configuration…
- Chroma query failed
- CLAUDE_CODE_PATH is set to
- CLAUDE_CODE_PATH is set to
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/1194290b51c6eb2b.
Report an issue: GitHub.
Appendix: source
Thrown at src/cli/claude-md-commands.ts:74
(obs.subtitle?.length || 0) +
(obs.narrative?.length || 0) +
(obs.facts?.length || 0);
return Math.ceil(size / 4);
}
function getTrackedFolders(workingDir: string): Set<string> {
const folders = new Set<string>();
let output: string;
try {
output = execSync('git ls-files', {
cwd: workingDir,
encoding: 'utf-8',
maxBuffer: 50 * 1024 * 1024
});
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.warn('CLAUDE_MD', 'git ls-files failed, falling back to directory walk', { error: errorMessage });
walkDirectoriesWithIgnore(workingDir, folders);
return folders;
}
const files = output.trim().split('\n').filter(f => f);
for (const file of files) {
const absPath = path.join(workingDir, file);
let dir = path.dirname(absPath);
while (dir.length > workingDir.length && dir.startsWith(workingDir)) {
folders.add(dir);
dir = path.dirname(dir);
}
}
return folders;
}View on GitHub (pinned to d8bc9755e7)