js-combine-iterations — Claude Code rule: what it does, how to install
js-combine-iterations tells the Claude agent to replace several filter or map passes over the same array with one loop that fills the results as it goes.
no license ★ 1,064 updated 2026-01-21
.claude/rules/js-combine-iterations.mdWhat js-combine-iterations does
A Claude rule about array passes. When filter or map calls run over the same array one after another, the agent should fold them into a single for...of loop that pushes matches into each result array. The rule's own example collapses three walks over users into one, filling the admin, tester and inactive lists on the same pass.
The file is plain markdown: a title, a few tags and a wrong/right pair written in TypeScript, where the correct version declares typed arrays and appends to them under a condition. It nudges the model rather than gating a build, so whether it takes effect depends on the agent reading it.
Impact is marked LOW-MEDIUM, and that reads right. One extra pass is rarely the bottleneck, and a single loop is harder to scan than a chain of filter calls. The rule trades brevity for speed, so it earns its place where the code runs constantly and is a matter of taste everywhere else.
What it helps with
- fold three array passes into one loop
- cut repeated
filtercalls on a hot path - fill several result arrays during a single walk
- keep array handling consistent across a TypeScript codebase
- catch code that walks the same array more than once
Example prompts for the agent
- Rewrite these three
filtercalls overusersas one loop, following thejs-combine-iterationsrule. - Check
users.tsand merge any repeated passes over the same array. - Collect admins, testers and inactive users in one pass.
How to install js-combine-iterations
Manually: put the files in place
.claude/rules/js-combine-iterations.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/js-combine-iterations.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/js-combine-iterations.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/js-combine-iterations.mdManually: put the files in place
.clinerules/js-combine-iterations.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about js-combine-iterations
How do I install js-combine-iterations in Claude Code?
Put the rule file at .claude/rules/js-combine-iterations.md in your project root; Claude picks up rules from that folder.
What does js-combine-iterations do?
It has the agent swap several filter or map calls over one array for a single for...of loop that builds the result arrays. Three passes over users become one.
Is it a big performance win?
The rule marks its own impact as LOW-MEDIUM. An extra pass over an array seldom sits on the hot path, and one loop takes longer to read than a chain of filter calls.