Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project are documented here, following
[Keep a Changelog](https://keepachangelog.com/) and semantic versioning.

## [0.1.15] - 2026-09-17

### Fixed

- Surface unreadable files (e.g. EACCES / mode-000) as estimated tokens from their
known size instead of reporting them as clean 0-token sources.

## [0.1.14] - 2026-09-16

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ctxtrim",
"version": "0.1.14",
"version": "0.1.15",
"description": "Trim what bloats your AI coding context. Scan a repo, find the high-cost/low-value files ballooning your Claude Code / Cursor / Codex context, and write ignore files to cut token cost. Zero dependencies.",
"type": "module",
"bin": {
Expand Down
5 changes: 4 additions & 1 deletion src/scan.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ function fileInfo(abs, size) {
closeSync(fd);
text = buf.toString("utf8", 0, bytesRead);
}
} catch { return { tokens: 0, sample: "" }; }
} catch {
// Unreadable (e.g. EACCES): don't silently drop it — surface an estimate from the known size.
return { tokens: Math.ceil((size || 0) / 4), sample: "" };
}
let tokens = estimateTokens(text);
if (bytesRead && bytesRead < size) tokens = Math.round(tokens * (size / bytesRead)); // scale partial reads
return { tokens, sample: text.slice(0, 4000) };
Expand Down
31 changes: 31 additions & 0 deletions test/ctxtrim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ test("scan includes symlinked source files", (t) => {
assert.deepEqual(result.files.map((file) => file.rel).sort(), ["linked.py", "real.py"]);
});

test("scan surfaces unreadable (EACCES) files with estimated tokens, not silent 0", (t) => {
const root = mkdtempSync(join(tmpdir(), "ctxtrim-unreadable-"));
t.after(() => rmSync(root, { recursive: true, force: true }));

writeFileSync(join(root, "locked.txt"), "x".repeat(200_000));

const readFileSync = fs.readFileSync;
t.mock.method(fs, "readFileSync", (abs) => {
if (String(abs).endsWith("locked.txt")) {
const err = new Error("EACCES: permission denied");
err.code = "EACCES";
throw err;
}
return readFileSync(abs);
});
syncBuiltinESMExports();

let result;
try {
result = scanRepo(root);
} finally {
t.mock.restoreAll();
syncBuiltinESMExports();
}

const file = result.files.find((f) => f.rel === "locked.txt");
assert.ok(file, "unreadable file should be present in the scan");
assert.ok(file.tokens > 0, `unreadable file silently reported as 0 tokens, got ${file.tokens}`);
assert.ok(result.totals.totalTokens >= file.tokens, "unreadable file should count toward totals");
});

test("scan finds trimmable bloat and keeps source", () => {
const s = scanRepo(repo);
assert.ok(s.totals.trimTokens > 0);
Expand Down
Loading