Set Up a Self-Improvement Protocol in CLAUDE.md
Use Claude Code in Plan mode to add a concise self-improvement protocol to the repository’s CLAUDE.md while preserving existing guidance and respecting a 2,500-token limit.
Example outputs
Prompt template
- Format
- Markdown
- Inputs
- Repository (code, document) · Required
- Outputs
- Updated_or_proposed_CLAUDE_md_changes (document, text)
In Claude Code, select Claude Opus 4.7, set Access permissions to Plan mode, and run this prompt:
Read and follow these instructions in this repository.
Update the CLAUDE.md file at the repository root. Create it if it does not exist. If it exists, read it in full and preserve its existing content. Add the block below immediately after the project heading; if there is no project heading, add it at the beginning. Consolidate duplicate rules when appropriate, but do not silently remove existing guidance.
Before editing, estimate the file’s total size in tokens after the addition. If it would exceed 2,500 tokens, first show me which overlapping or outdated rules you propose to consolidate or remove, and wait for my approval before making those changes. Keep the file within 2,500 tokens.
Add this block:
## Self-improvement protocol
- After any correction I make, propose a concise rule and add it to the appropriate section of this CLAUDE.md.
- Write each rule as one imperative sentence, without justification or examples unless the case is ambiguous.
- Search this file before adding a rule. If an existing rule already covers the case, refine that rule instead of duplicating it.
- Keep CLAUDE.md within 2,500 tokens by merging overlapping rules and removing outdated ones when needed.
- After fixing a bug, record a rule about the root-cause class, not the specific symptom.
What you'll create
A repository instruction update places a rule-learning block near the heading. It asks for imperative, concise lessons after corrections, refinement of existing rules before adding duplicates and review before consolidation that would otherwise exceed the stated token budget.
Frequently asked questions
Can existing guidance be silently deleted?
No. The source explicitly preserves existing content and requires approval before proposed consolidation when the addition exceeds the budget.
Comments
Tried this prompt? Share what you made, compare results, or ask a question