iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🕯️

Automatically Improving CLAUDE.md Instructions in Claude Code

に公開
2026/08/18

A post was shared on Reddit about a method to iteratively improve CLAUDE.md (I discovered a powerful way to continuously improve my CLAUDE\.md instructions for Claude Code : r/ClaudeAI). The idea is to bridge the gap between the recent chat history and CLAUDE.md by creating a custom command and executing it within Claude Code.

Creating the Command

I decided to try it out. I wasn't aware of this, but by placing an xxx.md file under the .claude/commands/ directory, you can run custom slash commands in Claude Code. Since the original Reddit article used a command called /project:reflection, I created a markdown file with the matching name as shown below.

mkdir -p .claude/commands
touch .claude/commands/reflection.md

According to the official documentation, custom commands can be created using the following method. To make them easier to deploy across different environments, it is generally best to place them within individual project directories.

  • When using in a specific project
    • Location: .claude/commands/
    • Prefix: /project:
  • When using globally across all projects
    • Location: ~/.claude/commands/
    • Prefix: /user:

Writing the Markdown Content

The content of the markdown file is as follows.

You are an expert in prompt engineering, specializing in optimizing AI code assistant instructions. Your task is to analyze and improve the instructions for Claude Code found in u/CLAUDE.md. Follow these steps carefully:

1. Analysis Phase:
Review the chat history in your context window.

Then, examine the current Claude instructions:
<claude_instructions>
u/CLAUDE.md
</claude_instructions>

Analyze the chat history and instructions to identify areas that could be improved. Look for:
- Inconsistencies in Claude's responses
- Misunderstandings of user requests
- Areas where Claude could provide more detailed or accurate information
- Opportunities to enhance Claude's ability to handle specific types of queries or tasks

2. Interaction Phase:
Present your findings and improvement ideas to the human. For each suggestion:
a) Explain the current issue you've identified
b) Propose a specific change or addition to the instructions
c) Describe how this change would improve Claude's performance

Wait for feedback from the human on each suggestion before proceeding. If the human approves a change, move it to the implementation phase. If not, refine your suggestion or move on to the next idea.

3. Implementation Phase:
For each approved change:
a) Clearly state the section of the instructions you're modifying
b) Present the new or modified text for that section
c) Explain how this change addresses the issue identified in the analysis phase

4. Output Format:
Present your final output in the following structure:

<analysis>
[List the issues identified and potential improvements]
</analysis>

<improvements>
[For each approved improvement:
1. Section being modified
2. New or modified instruction text
3. Explanation of how this addresses the identified issue]
</improvements>

<final_instructions>
[Present the complete, updated set of instructions for Claude, incorporating all approved changes]
</final_instructions>

Remember, your goal is to enhance Claude's performance and consistency while maintaining the core functionality and purpose of the AI assistant. Be thorough in your analysis, clear in your explanations, and precise in your implementations.

To briefly explain the content, it follows the structure below. It identifies the gap between the interactions in Claude Code and CLAUDE.md and improves CLAUDE.md while obtaining user approval.

- First, silently read the chat history to understand the tone of past interactions between the LLM and the user.
- Next, open the current instructions written in u/CLAUDE.md and read through them thoroughly.
- Compare the two to identify:
    - Inconsistencies or misunderstandings in responses
    - Missing or inaccurate information
    - Lack of capability for specific tasks
- For each identified issue, present the "Problem → Proposed Improvement → Expected Benefit" to the human and get approval one by one.
- For approved proposals, specify which section to rewrite and how, and provide the new draft.
- Add a brief reason for the change and update the instructions to the latest version.
- Finally, summarize the output into three parts:
    - Issue list: <analysis>
    - Approved improvements: <improvements>
    - Updated complete instructions: <final_instructions>

Execution

When I actually ran /project:reflection, the result was as follows. This is because the language is set to Japanese in docs/LLM_GUIDELINES.md, which is referenced by CLAUDE.md. If you want to stabilize the output, it might be even better to write the instructions in .claude/commands/reflection.md in Japanese.

1. Unclear method for obtaining environment variables
    - The current instructions do not clearly state how to generate environment variable files (.env).
    - It appears the user is confused about setting up environment variables.
2. Missing authentication procedures
    - Authentication procedures for obtaining environment variables are not described.
    - Explanation of when authentication is required is insufficient.
Proposed Changes:
  I propose adding the following section to CLAUDE.md:
  xxxxxxx

**Improvement Benefits:**
  - Developers will not be lost when setting environment variables.
  - Authentication procedures become clear.

Would you like to approve these changes? If approved, I will implement the specific changes to CLAUDE.md.

Personal Thoughts

While writing this article, I got the impression that slash commands might be more like shortcuts for Claude Code. For example, instead of entering a prompt like "Please read the documents under docs/" every time, it is better to prepare a command like /project:readdocs from the start.

  • /project:git-refactoring: Applies refactoring to the differences currently in the git status.
  • /project:readdocs: Reads CLAUDE.md and all markdown files under the docs directory.
  • /project:write-test: Writes test code based on the specifications.

While you still have to enter the commands manually, they are useful in that they make updating the chat context easy. Also, by preparing and sharing multiple commands across projects, development with Claude Code within a team could become much more efficient (though I've ended up talking about the potential of commands in general).

GitHubで編集を提案

Discussion