I Got Tired of Telling Claude "Our Backend Uses FastAPI" Every Single Time

When I started using Claude Code seriously while developing aickyway, it was great at first. But as conversations got longer, Claude would forget the context and generate NestJS code, or write PostgreSQL queries when we use MongoDB. I must have typed "I already told you..." ten times a day.

default alt text

The breakthrough came from the CLAUDE.md file.

CLAUDE.md is not just a place to store prompts. It is a customized 'guidebook' and 'long-term memory device' exclusively for our project. Through this file, Claude learns the core rules, structure, and conventions of the project before starting any conversation. It's like a new team member reading through onboarding documents before starting work.

Even within Anthropic, teams that effectively utilize this file have been reported to be 2-3 times faster in task processing than those that don't. After systematically implementing CLAUDE.md, I was able to cut the supplementary explanations I gave to AI by more than half while noticeably improving code quality.

From now on, I would like to share the 10 principles for writing CLAUDE.md that I learned through trial and error, which elevated Claude from a simple code generator to a reliable colleague.


1. Architecture Specification: The Project Compass

Before asking AI to write code, you need to show it the complete map of the system we are building. Architecture specification is the most important first step that allows Claude to see the forest before dealing with the trees.

  • Problem I Experienced: When I asked "Make a user info update API," it suggested code with database queries mixed directly in the controller logic.

  • How I Solved It: I clearly defined the frontend (Next.js), backend (NestJS), DB (PostgreSQL), and the role of each layer in CLAUDE.md.

  • Result: Claude now recognizes the MVC (or MVVM) pattern on its own and suggests the right location, saying "This logic would be better added to the service layer."

  • CLAUDE.md Example:

    ## ๐Ÿ—๏ธ System Architecture
    
    - **Frontend:** SSR web based on Next.js (App Router). Recoil for state management.
    - **Backend:** RESTful API server based on NestJS. Communicates with DB via TypeORM.
    - **Database:** PostgreSQL. Core tables are `users`, `posts`, `comments`.
    - **Core Pattern:** Backend follows a layered structure of modules, controllers, services, and repositories.
    
  • ๐Ÿ’ก Pro Tip: If your project has a Monorepo structure, place separate CLAUDE.md files within each package directory (apps/web, packages/ui) to provide more detailed and specific context.

default alt text

2. Command Recipes for Automation

Eliminate unnecessary questions and guesses like "How do I start the dev server?" By organizing the main scripts of your project, Claude becomes a smart assistant that finds and executes the necessary commands on its own.

  • CLAUDE.md Example:
    ## Main Execution Commands
    
    - `npm run dev`: Runs the development server. (HMR supported)
    - `npm run test:e2e`: Runs E2E tests. (Uses Cypress)
    - `npm run lint:fix`: Automatically fixes code according to ESLint rules.
    - `npm run db:migrate`: Migrates database schema to the latest state.
    
  • ๐Ÿ’ก Pro Tip: For complex execution commands involving multiple services like docker-compose up, briefly explaining the role of each container will further enhance Claude's understanding.

3. Code Style Principles for Consistency

AI also has its own 'artistic' style. To prevent the inconsistency of using double quotes one day and single quotes another, you need to clearly communicate your team's style guide.

  • CLAUDE.md Example:
    ## ๐ŸŽจ Code Style Principles
    
    - **Formatting:** Follows Prettier settings. (2-space indent, single quotes for strings, semicolons required)
    - **Naming:** Functions and variables use `camelCase`, classes and type interfaces use `PascalCase`.
    - **JS/TS:** Never use the `var` keyword. Prefer `async/await` syntax for `Promise`-based async handling.
    
  • ๐Ÿ’ก Pro Tip: Including not just code style but also commit message conventions (e.g., feat(API): ...) and PR template writing guides will help Claude produce consistent results from code writing to submission.

4. Test Writing Culture for Quality Assurance

Instead of saying "Write tests after implementing the feature" every time, make test writing a natural culture and process.

  • CLAUDE.md Example:
    ##  Test Writing Culture
    
    - **Basic Principle:** Unit tests must be written together when new business logic is added.
    - **Test Tools:** Use `Jest` for unit tests, `React Testing Library` for component tests.
    - **Mocking:** External API dependencies are mocked using `msw` (Mock Service Worker).
    
  • ๐Ÿ’ก Pro Tip: Setting specific goals like "Core functionality test coverage must be maintained at 80% or above" helps Claude recognize areas lacking tests and suggest additional test cases.

5. Error Handling Philosophy for Robust Code

Go beyond simply fixing bugs and train Claude to write code that is hard to break in the first place.


7. Security Principles from the First Line

Security is not a feature added later. Make Claude keep security in mind at every moment of writing code. Like a built-in security consultant.

  • CLAUDE.md Example:
    ## Security Principles (Security-First)
    
    - **Distrust Input:** All user-input data must be validated on the server.
    - **Password Storage:** Passwords are stored with one-way encryption (hash) using `bcrypt`.
    - **SQL Injection Prevention:** Database queries must be executed using ORM or Prepared Statements.
    - **XSS Prevention:** User-input content must be escaped when displayed on screen.
    
  • ๐Ÿ’ก Pro Tip: Adding rules like "API access must be controlled according to user roles" will make Claude naturally include permission check logic when suggesting new APIs.

default alt text


8. Team Agreements for Smooth Collaboration

8. Team Agreements for Smooth Collaboration

Code is not a personal diary. Guide Claude to follow collaboration rules like Git usage and documentation as a member of our team.

```markdown
## Team Collaboration Rules

- **Branch Strategy:** Feature development proceeds on branches in the format `feature/ticket-number`, with PRs sent to the `develop` branch.
- **Documentation:** When adding new API endpoints, the `docs/api.md` file must be updated.
- **Code Review:** PR creation must include clear explanations of the background and purpose of changes.
```
  • ๐Ÿ’ก Pro Tip: This CLAUDE.md file itself can be an excellent onboarding document. When new team members join, share this file to help them quickly learn our team's development culture and rules.

9. Edge Case Checklist

Code that only considers the happy path breaks easily in the real world. Guide Claude to always ask "What if...?" to increase code stability.

  • CLAUDE.md Example:
    ## Edge Case Checklist
    
    When writing code, always consider these edge cases:
      When empty arrays, empty strings, 0, ,  are input.
      When values at or beyond the allowed maximum/minimum are input.
      When events occur in unexpected order (e.g., click before loading completes).