Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/js-combine-iterations.md
Open on GitHub

What 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 filter calls 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 filter calls over users as one loop, following the js-combine-iterations rule.
  • Check users.ts and 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.md

The paths frontmatter field limits the files

Step 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.

Similar IDE rules

All IDE rules for Code review and refactoring →

From the same set20

The whole set →
rendering-svg-precision rendering-svg-precision — a rule for Claude Code that reduces SVG coordinate precision to one decimal place. Applies when creating icons or editing graphics. CX Codex +1 ★ 1,064repo stars _template _template — a rule-file scaffold with fields for its title and impact, plus sections for contrasting incorrect and correct code. CX Codex +1 ★ 1,064repo stars async-parallel async-parallel — a Claude rule that sends independent async calls through Promise.all() instead of awaiting them one by one. Useful when a handler piles up sequential awaits. CX Codex +1 ★ 1,064repo stars rerender-derived-state The rerender-derived-state rule favors derived boolean state over continuously changing values, reducing React re-renders. It fits responsive UI logic. CX Codex +1 ★ 1,064repo stars bundle-dynamic-imports bundle-dynamic-imports guides Claude Code to lazy-load heavy components using next/dynamic with SSR disabled. Keeps your initial client bundle lean to protect TTI and LCP metrics. CX Codex +1 ★ 1,064repo stars rendering-content-visibility The rendering-content-visibility rule applies content-visibility: auto to long lists so off-screen items can wait before rendering. It fits message feeds and other scrollable collections. CX Codex +1 ★ 1,064repo stars rerender-dependencies rerender-dependencies — a Claude rule that keeps useEffect dependency arrays on primitives like user.id rather than whole objects, so an effect stops firing on every field change. CX Codex +1 ★ 1,064repo stars testing The testing rule sets conventions for TypeScript test files and the __tests__ directory. Use it to guide checks for success cases, failures, and edge conditions. CX Codex +1 ★ 1,064repo stars

Project sponsors

Companies that keep this analytics open