
Ever find yourself constantly retyping or copy-pasting elaborate Claude Code prompts for recurring tasks like generating unit tests or refactoring code snippets? Itβs a common bottleneck that breaks your flow and wastes precious development time. Instead of treating your claude CLI sessions as fleeting conversations, treat them as reproducible workflows by leveraging CLAUDE.md files. These markdown files allow you to structure your prompts, embed context, and even define variables, turning ad-hoc requests into robust, reusable tools.
The power of CLAUDE.md lies in its ability to house more than just plain text. You can include code blocks to provide specific examples, clearly delineate sections, and even use a simple templating syntax to inject dynamic values. This makes your prompts more readable, maintainable, and adaptable. For instance, when generating JUnit tests, you can provide the source code and specify the testing framework directly within the CLAUDE.md file, ensuring Claude understands the exact context without needing lengthy, repeated explanations in the CLI.
Consider a scenario where you frequently need to generate mock data for a specific API endpoint. Instead of typing out the endpoint definition and desired output structure every time, you can create a CLAUDE.md file like this:
---
description: Generate mock JSON data for the user profile API.
variables:
user_id: "123e4567-e89b-12d3-a456-426614174000"
username: "testuser"
---
# Generate Mock User Profile Data
**API Endpoint:** `/api/v1/users/{user_id}`
**Context:**
This is a request to generate a realistic JSON payload for a user profile, adhering to common patterns.
**Instructions:**
Create a JSON object representing a user profile. Include fields such as `id`, `username`, `email`, `firstName`, `lastName`, `createdAt`, and `updatedAt`. The `id` should be a UUID, and `createdAt` and `updatedAt` should be ISO 8601 formatted timestamps.
**Example Structure:**
```json
{
"id": "...",
"username": "...",
"email": "...",
"firstName": "...",
"lastName": "...",
"createdAt": "...",
"updatedAt": "..."
}
Constraints:
- Ensure the
idis a valid UUID format. - Timestamps should be in the
YYYY-MM-DDTHH:MM:SS.sssZformat. - Populate the fields with plausible dummy data. ```
Then, you can invoke this with the claude CLI: claude --file CLAUDE.md --variable user_id=abcdef12-3456-7890-abcd-ef1234567890. The CLI will automatically substitute the variables and send the structured prompt to Claude.
By using CLAUDE.md files, you build a personal knowledge base of effective prompts. This not only speeds up your current tasks but also makes it easier to onboard new team members by sharing these well-defined, reusable workflows. Think of it as creating your own AI-powered development toolkit, one CLAUDE.md file at a time.
Try it: Create a new file named unit_tests.md and paste the example above, replacing the placeholder text with a simple Python function you want to test, and then run claude --file unit_tests.md.