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, including main instructions and subagent-specific instructions.
Follow these steps carefully:
- Target Selection Phase: First, determine what instructions to update:
- CLAUDE.md: Main project instructions that apply to all contexts
- Subagent: Instructions specific to a subagent (located at
.claude/agents/[agent-name].md) - Slash Command: Instructions specific to a custom slash command (located at
.claude/commands/[command-name].md)
Ask the user which target they want to update. If the user mentions issues with a specific subagent (e.g., "the backend agent had trouble with..."), default to that subagent's file. If the user mentions a specific slash command, default to that command's file. If no specific target is mentioned, default to CLAUDE.md.
- Analysis Phase: Review the chat history in your context window to understand what worked and what didn't.
Then, examine the relevant instructions, commands and config: <claude_instructions> For CLAUDE.md:
- /CLAUDE.md
- /.claude/commands/*
- **/CLAUDE.md
- .claude/settings.json
- .claude/settings.local.json
For subagent files:
- /.claude/agents/[subagent-name].md
- /.claude/commands/* (if relevant to the subagent)
- .claude/settings.json
- .claude/settings.local.json </claude_instructions>
Analyze the chat history, instructions, commands and config to identify areas that could be improved. Look for:
- Inconsistencies in Claude's or subagent's responses
- Misunderstandings of user requests by the main assistant or subagent
- Areas where Claude/subagent could provide more detailed or accurate information
- Opportunities to enhance the ability to handle specific types of queries or tasks
- For subagents: specific patterns, libraries, or workflows they struggled with
- New commands or improvements to a commands name, function or response
- Permissions and MCPs we've approved locally that we should add to the config, especially if we've added new tools or require them for the command to work
- 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 or the subagent'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.
-
Implementation Phase: For each approved change: a) Clearly state which file you're modifying (CLAUDE.md or specific subagent file) b) Clearly state the section of the instructions you're modifying c) Present the new or modified text for that section d) Explain how this change addresses the issue identified in the analysis phase
-
Output Format: Present your final output in the following structure:
<target_file> [Specify which file is being updated: CLAUDE.md, [subagent-name].md, or [command-name].md] </target_file>
[List the issues identified and potential improvements specific to this target] [For each approved improvement: 1. File being modified 2. Section being modified 3. New or modified instruction text 4. Explanation of how this addresses the identified issue]<final_instructions> [Present the complete, updated set of instructions for the target file, incorporating all approved changes] </final_instructions>
Remember, your goal is to enhance Claude's or the subagent'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.
When updating subagent files:
- Focus on domain-specific improvements (e.g., backend patterns, API design, testing strategies for backend-engineer)
- Include specific examples, libraries, or patterns that the subagent should follow
- Document common issues and their solutions specific to that domain
- Preserve the existing structure and metadata (name, description, tools, model, color) in the frontmatter