Skip to content

fix(installer): stop writing duplicate instructions block to CLAUDE.m…#532

Open
Bin-hy wants to merge 1 commit into
colbymchenry:mainfrom
Bin-hy:fix/claude-skip-claude-md-instructions
Open

fix(installer): stop writing duplicate instructions block to CLAUDE.m…#532
Bin-hy wants to merge 1 commit into
colbymchenry:mainfrom
Bin-hy:fix/claude-skip-claude-md-instructions

Conversation

@Bin-hy
Copy link
Copy Markdown

@Bin-hy Bin-hy commented May 28, 2026

Summary / 概述

Closes #529

EN: Claude Code already receives SERVER_INSTRUCTIONS via the MCP initialize response on every session (~1700 tokens, surfaced as a system reminder). The installer was also writing an INSTRUCTIONS_TEMPLATE block to CLAUDE.md (~1500 tokens, ~90% identical content), so agents read the same guidance twice on every turn with no benefit — pure token waste.

CN: Claude Code 每次会话已通过 MCP initialize 响应收到 SERVER_INSTRUCTIONS(~1700 tokens,以系统提醒形式展示)。安装器同时还会向 CLAUDE.md 写入一份 INSTRUCTIONS_TEMPLATE block(~1500 tokens,内容约 90% 重合),导致 agent 每轮都重复读取相同内容,纯粹的 token 浪费。

Changes / 改动

  • src/installer/targets/claude.ts: In install(), replace the writeInstructionsEntry() call with removeMarkedSection() — strips the existing block if a legacy install left one (automatic migration for upgrading users). Only reports action: 'removed' when content was actually stripped. uninstall() is unchanged (already calls removeMarkedSection). writeInstructionsEntry() stays exported for the deprecated config-writer.ts shim.
  • Other targets (Cursor, Codex, opencode, Gemini, Kiro, Hermes, Antigravity): unchanged — they don't reliably surface SERVER_INSTRUCTIONS and still need their own instructions files.
  • CHANGELOG.md: entry added under ## [Unreleased] / ### Changed.

  • src/installer/targets/claude.ts:在 install() 中将 writeInstructionsEntry() 改为调用 removeMarkedSection()——如果旧版安装留下了 block,自动将其清除(升级用户无需手动操作)。仅在实际移除内容时才向 files 添加 action: 'removed'uninstall() 保持不变。writeInstructionsEntry() 保留导出供已废弃的 config-writer.ts shim 使用。
  • 其他 target(Cursor、Codex、opencode、Gemini、Kiro 等):不受影响——这些 target 不能可靠地展示 SERVER_INSTRUCTIONS,仍需各自的指令文件。
  • CHANGELOG.md:在 ## [Unreleased] / ### Changed 下新增条目。

Test plan / 测试

  • __tests__/installer-targets.test.ts passes (134 tests) — all parametrized contract tests for Claude still pass (files.length > 0, idempotency, alreadyConfigured round-trip)
  • New: claude: install does not write CLAUDE.md instructions block
  • New: claude: install strips existing CLAUDE.md codegraph block (migration path) — verifies user content outside markers is preserved and removal is surfaced in result.files

🤖 Generated with Claude Code

…d for Claude Code

Claude Code already receives SERVER_INSTRUCTIONS via the MCP initialize
response every session (~1700 tokens as a system reminder). The installer
was also writing an INSTRUCTIONS_TEMPLATE block to CLAUDE.md (~1500
tokens, ~90% identical content), so agents paid the cost twice on every
turn with no benefit.

On install(), strip any existing block with removeMarkedSection() instead
of writing a new one — upgrading users have the legacy block removed
automatically. uninstall() is unchanged (already calls removeMarkedSection).
writeInstructionsEntry() stays exported for the deprecated config-writer.ts
shim. Other targets (Cursor, Codex, opencode, Gemini, Kiro) are unchanged.

Closes colbymchenry#529

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CLAUDE.md instructions duplicate MCP server instructions — wastes tokens every turn

1 participant