file-splitting

Guidance for deciding when a large source-code file should be split into smaller files, based on its responsibilities rather than its line count. It also covers code changes made by multiple AI agents.

In plain words
What is it for?
Use it when reviewing or changing an oversized source file. It helps decide what to separate, what to leave alone, and how to make the split without changing behavior.
Why use it?
Large mixed-purpose files are harder to understand, edit safely, and merge when several agents work at once. Splitting unrelated responsibilities can reduce conflicts and repeated reading.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/lawofall/agentcore/file-splitting
Clone the repo
git clone --depth 1 https://github.com/Lawofall/AgentCore

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 542 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00542
Opus 5 $0.00000 $0.00271
Sonnet 5 $0.00000 $0.00108
Haiku 4.5 $0.00000 $0.00054

Measured yesterday against content hash 67c0d7584c3f, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

file-splitting scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/file-splitting.mdc · 38 lines

What it actually says

大文件拆分准则

核心:按「职责 / 变更原因」拆,不按行数机械拆。一个 1200 行的单一内聚单元可以不动;一个 600 行混了多个关注点的就该拆。

触发判断(软阈值)

  • ~800 行 = 软信号,~1200 行 = 必须自问。
  • 关键一问:这文件是否有 >1 个变更原因 / >1 个独立类·关注点?
    • 是 → 按职责拆成多文件。
    • 否(单一内聚)→ 留着,别拆。

为什么本项目尤其要拆(AI 主导 + 多 Agent 并行)

常规「为人的可读性」理由变弱,但三条 AI 特有理由让拆分更值:

  1. 合并冲突面:多 Agent / 多 worktree 并行,人人都动的 god file = 冲突重灾区;拆成小文件让各 Agent 改不相交文件。
  2. StrReplace 可靠性:文件越大、重复模式越多,越易「锚点不唯一」改错位置,浪费轮次。
  3. 上下文成本:改一处却反复读上千行,每轮都在烧 token 和时间。

怎么拆

  • 沿职责缝拆(按领域 / 聚合 / 关注点),让两个 Agent 能各改各的文件。
  • 别把一次逻辑改动打散到多文件——那样更难 review、更易冲突。
  • 拆分本身是「冲突炸弹」:做成小而快合并的独立改动,挑目标模块没人在动时做。
  • 纯搬移、不改行为;改完跑测试验证。

不要拆

  • 生成文件(如 api.generated.ts):重生成即可。
  • 第三方 / vendored(sidecarsite-packagesrelease)。
  • 真正单一内聚的文件,即便上千行。
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 38 lines · 542 tokens per session scan A 67c0d7584c3f

Subscribe to this mod's changes

file-splitting is a cursor rule published in the GitHub repository Lawofall/AgentCore (78 stars, last pushed 2d ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 542 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.