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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
All notable changes to this project are documented here, following
[Keep a Changelog](https://keepachangelog.com/) and semantic versioning.

## [0.1.6] - 2026-09-08

### Fixed

- Write and report each ignore file only once when `--targets` contains duplicates.

## [0.1.5] - 2026-09-07

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ npx ctxtrim --fail-on-waste 40 # CI: exit 1 if 40%+ of context is junk

**Ignore files it writes** (all real formats the tools honor): `.cursorignore` (Cursor), `.aiexclude` (Gemini Code Assist / Firebase Studio), `.aiignore` (generic). Writes are **idempotent** — a managed block between markers, so your own rules are preserved and re-runs just update the block.

Repeated names in `--targets` are ignored; each ignore file is written and reported once, in the order first requested.

## What it is (and isn't)

- A **fast, deterministic, zero-dependency** heuristic — no model calls, nothing uploaded.
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.5",
"version": "0.1.6",
"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
2 changes: 1 addition & 1 deletion src/ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function merge(existing, patterns) {
/** @returns {{file, action:'created'|'updated', patterns:number}[]} */
export function writeIgnores(root, patterns, targets) {
const results = [];
for (const t of targets) {
for (const t of new Set(targets)) {
const fname = TARGETS[t];
if (!fname) continue;
const path = join(root, fname);
Expand Down
19 changes: 18 additions & 1 deletion test/ctxtrim.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,28 @@ test("unknown --targets values fail before writing ignore files", (t) => {
assert.equal(existsSync(join(root, ".aiexclude")), false);
assert.equal(existsSync(join(root, ".aiignore")), false);
});
test("duplicate --targets writes and reports each ignore file once", (t) => {
const root = mkdtempSync(join(tmpdir(), "ctxtrim-duplicate-target-"));
t.after(() => rmSync(root, { recursive: true, force: true }));
writeFileSync(join(root, "package-lock.json"), "{}\n");

const result = spawnSync(process.execPath, [
cli, root, "--write", "--format", "json", "--targets", "cursor, gemini,cursor,gemini",
], { encoding: "utf8" });

assert.equal(result.status, 0, result.stderr);
assert.deepEqual(JSON.parse(result.stdout).wrote, [
{ file: ".cursorignore", action: "created", patterns: 1 },
{ file: ".aiexclude", action: "created", patterns: 1 },
]);
assert.equal(existsSync(join(root, ".cursorignore")), true);
assert.equal(existsSync(join(root, ".aiexclude")), true);
});
test("textReport with top: 0 omits Top offenders header", () => {
const scan = scanRepo(repo);
const out = textReport(scan, { price: 3, top: 0 });
assert.ok(
!out.includes("Top offenders"),
"should not show Top offenders header when top is 0",
);
});
});
Loading