JuliusBrussee/caveman · error
caveman-code: not a file
Error message
caveman-code: not a file: ${input.path} What it means
The read tool in packages/agent/src/code.ts resolves the requested path inside the workspace (contained()), stats it, and requires it to be a regular file. If stat succeeds but the target is a directory, symlink-to-directory, socket, or other non-file, it throws 'caveman-code: not a file: <path>'.
Solutions
- Pass the full path to a regular file (e.g. src/index.ts), not a directory.
- Use the list/glob tool to enumerate directory contents first, then read individual files.
- Resolve symlinks: point the read at the actual file the symlink targets.
- Strip trailing slashes or glob patterns from the path before calling read.
- If you need directory contents, use the codebase search/list tools instead of read.
Example fix
// before
tool.read({ path: "src" })
// after
tool.read({ path: "src/index.ts" }) Defensive patterns
Strategy: validation
Validate before calling
const st = await fs.promises.stat(path);
if (!st.isFile()) throw new Error(`${path} is not a regular file`); Type guard
const isRegularFile = (p: string) => fs.existsSync(p) && fs.statSync(p).isFile();
Try / catch
try {
await read({ path });
} catch (e) {
if (e.message.startsWith("caveman-code: not a file:")) {
const st = await fs.promises.stat(path);
if (st.isDirectory()) console.error(`${path} is a directory — list it first, then read files individually`);
} else throw e;
} Prevention
- Stat the path before reading; only pass regular files to the read tool.
- Resolve symlinks to their final target and verify it is a file.
- Use the list/glob tool for directories instead of attempting to read them.
- Strip trailing slashes and glob patterns from paths before reading.
When it happens
Trigger: Invoking the read tool with input.path pointing at a directory (e.g. 'src' or '.'), a device/pipe file, or a symlink resolving to a directory; passing a path without the filename when intending to read every file in a folder.
Common situations: The LLM/agent passes a directory path hoping for a directory listing; a config variable holding a directory root is reused as a read target; a symlink points at a directory after a refactor; trailing-slash or glob-style paths like 'src/*.ts' are supplied.
Related errors
- caveman-code: old_string and new_string are identical
- caveman-code: old_string not found in
- awscreds: read container authorization token file
- cannot persist MCP ownership journal at
- cannot safely launch Windows command shim
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/9b096beba3a286ad.
Report an issue: GitHub.
Appendix: source
Thrown at packages/agent/src/code.ts:242
containedPath(await workspaceRoot(), candidate);
const readFileTool = tool({
name: "read_file",
description:
"Read a UTF-8 file from the workspace. Optional offset/limit read a line range. " +
`Output is capped at ${caps.read_file} bytes.`,
input: schema.object({
path: schema.string(),
offset: schema.optional(schema.integer()),
limit: schema.optional(schema.integer()),
}),
effect: "read",
result: "inline",
timeoutMs: READ_TIMEOUT_MS,
async execute(input) {
const target = await contained(input.path);
const info = await stat(target);
if (!info.isFile()) throw new Error(`caveman-code: not a file: ${input.path}`);
const content = await readFile(target, "utf8");
const lines = content.split("\n");
const offset = Math.max(1, input.offset ?? 1);
const limit = input.limit === undefined ? lines.length : Math.max(1, input.limit);
const selected = lines.slice(offset - 1, offset - 1 + limit);
const numbered = selected
.map((line, index) => `${offset + index}\t${line}`)
.join("\n");
const text = capOutput(numbered, caps.read_file);
record(`read_file:${input.path}`, text);
return text;
},
});
const grepTool = tool({
name: "grep",
description:
"Search the workspace for a regular expression with ripgrep (grep fallback). " +View on GitHub (pinned to 3ee70a1026)