Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

The Context Window Is Full Before the First Prompt — When Project Rules in Claude Code Become a Fixed Cost of Every Session

说明与用途

Claude Code 中的项目规则在用户输入之前可能占用大量上下文窗口,导致 "Prompt is too long" 错误。通过将规则绑定到文件路径、移动库存和重写指令,将令牌数从 454,900 降至 64,700,解决了该问题。

问题

Project rules in Claude Code repositories grow large enough to fill the context window before any user prompt, causing subagents to abort with a "Prompt is too long" error.

结果

Project rules can consume a fixed, large portion of the context window, but by scoping rules to file paths, separating inventories, and refactoring instructions, the token cost dropped from 454,900 to 64,700, eliminating the subagent abort.

工作流

  • Measure context size with "/context" before changes.
  • Identify rule files that load at start and separate them from records.
  • Bind rules to file paths using the paths frontmatter so they load only when needed.
  • Move large inventory tables into a separate file that is not loaded at start.
  • Rewrite rule instructions to reference the inventory file instead of embedding it.
  • Re‑measure context size to confirm reduction.
  • Verify subagent no longer aborts on start.
  • Maintain guardrails in CI to prevent future growth.

证据

Project rules are a fixed cost of every session: Everything in the project's CLAUDE.md, its imports and the rule files without a file scope loads in Claude Code at start, before the first prompt arrives.

来源

After a good six months of maintenance, the largest rule file consisted to 84 percent of an inventory table with one row per test file.

来源

Three levers, measured before and after: Bind rules with a file scope to paths, move inventories into a neighboring file, and phrase instructions so that the agent looks things up instead of preloading everything. Afterwards the project instructions stood at 64,700 instead of 454,900 tokens.

来源

The subagent that had aborted before started again after the reduction.

来源

  • 记录日期: 2026-10-22T21:11:40.600Z