CLAUDE.md for Salesforce development: AI context file generator
Quick answer
Pick your assistant, choose which Salesforce topics to include and enter a few project facts. The tool builds a CLAUDE.md, AGENTS.md, Cursor rule or Copilot instructions file you can copy or download, with rules such as bulkify Apex, no SOQL or DML in loops, one trigger per object, with sharing by default and use the sf CLI.
Generate your instruction file
The generator needs JavaScript. The worked example, rule summary and guidance below work without it.
Save as CLAUDE.md
What these files are and where assistants read them
AI coding assistants start every session without knowing your project. An instruction file is a short Markdown document in your repository that they load automatically, so the assistant follows your conventions instead of generic ones. For Salesforce this matters because generic code often runs fine in a unit test with one record and then fails in production with a governor limit or a missing permission check.
| Assistant | File | Notes |
|---|---|---|
| CLAUDE.md | CLAUDE.md | Claude Code reads it from the project root (or .claude/CLAUDE.md). |
| AGENTS.md | AGENTS.md | Open format read by many coding agents, including Cursor and Claude Code when no CLAUDE.md exists. |
| Cursor rule | .cursor/rules/salesforce.mdc | Cursor project rules live in .cursor/rules and use .mdc with frontmatter. |
| Copilot instructions | .github/copilot-instructions.md | GitHub Copilot reads this repository-wide file from the .github folder. |
The Cursor file is the only one with frontmatter. This is what the generator writes at the top of
salesforce.mdc: a description, comma-separated globs for your Salesforce source files, and alwaysApply: false
so the rule attaches when matching files are in context.
---
description: "Salesforce development rules: Apex, SOQL, LWC, security, testing and deployment"
globs: force-app/**/*.cls, force-app/**/*.trigger, force-app/**/lwc/**, force-app/**/aura/**, force-app/**/*-meta.xml, sfdx-project.json
alwaysApply: false
---
Formats were checked against Claude Code memory, Cursor rules, GitHub Copilot custom instructions and AGENTS.md.
Worked example
This CLAUDE.md was generated at build time by the same code the tool runs, with four topics selected, API version 68.0 and an 85% coverage target.
# Acme Sales: Salesforce development instructions
Follow these rules when writing or changing code in this Salesforce DX project. Ask when a rule conflicts with the task.
## Project facts
- Salesforce API version: 68.0. Keep `sourceApiVersion` in sfdx-project.json and new metadata at this version.
- Source directory: `force-app`
- Orgs: scratch orgs for development, one UAT sandbox
- Apex test coverage target: at least 85% per class, with meaningful assertions.
## Apex
- Write every method to handle a list of records (bulkify), never a single record. Triggers, Flows and batches deliver up to 200 records at a time.
- Never run SOQL or DML inside a loop. Query once into a Map, then loop over the Map. Each query and DML statement counts against per-transaction limits.
- Never hard-code record IDs, profile names or org-specific URLs. Query them, or use Custom Metadata, Custom Labels or Named Credentials.
- Do not try to catch LimitException to recover. It cannot be caught, so check the Limits class before expensive work instead.
- Use bind variables in SOQL. If a query must be dynamic, bind values or escape them with String.escapeSingleQuotes(). Prevents SOQL injection.
- Choose async Apex deliberately: Queueable for most new work, Batch Apex for large volumes, Schedulable for timed jobs. Avoid new @future methods.
- Keep methods small and name them for what they do. Put reusable logic in service classes, not in triggers or controllers.
## Triggers
- Create one trigger per object and keep it logic-free: it only calls a handler class. Order of multiple triggers on one object is not guaranteed.
- Branch on Trigger.operationType in the handler. Use before triggers to change the records being saved, and after triggers for work that needs the record ID.
- Guard against recursion and compare Trigger.oldMap with Trigger.new so logic runs only when a relevant field actually changed.
- Do not make synchronous callouts from a trigger. Enqueue a Queueable that implements Database.AllowsCallouts instead.
## Security and sharing
- Declare classes with `with sharing` by default. Use `without sharing` or `inherited sharing` only deliberately, with a comment explaining why.
- Enforce object and field permissions: use `WITH USER_MODE` in SOQL and `as user` or AccessLevel.USER_MODE for DML, or Security.stripInaccessible() on records you read or write. Apex runs in system mode by default and ignores the user's CRUD and FLS.
- Never build SOQL, SOSL or JavaScript from raw user input. Use bind variables and escape output.
- Never put secrets, tokens or passwords in code, metadata or logs. Use Named Credentials or protected Custom Metadata.
- Do not use Schema describe calls to hide fields as a substitute for real permission checks. Rely on permission sets and the enforcement mechanisms above.
## Testing
- Every test must assert expected behavior with System.Assert methods. Never write tests whose only purpose is code coverage.
- Create test data in the test or in a test data factory. Do not rely on existing org data, and do not use SeeAllData=true.
- Use @TestSetup for data shared by the methods of a test class.
- Test in bulk (200 records), test a negative path, and test as a user with limited permissions using System.runAs().
- Wrap the code under test in Test.startTest() and Test.stopTest(), and call Test.stopTest() before asserting on async results.
- Mock callouts with Test.setMock() and HttpCalloutMock. Real callouts are not allowed in tests.
What each topic covers
The generator holds 53 rules in 10 topics. They are our own conservative guidance, and all topics are on by default. Links go to related guides and tools.
- Apex (7 rules): Bulk-safe, readable Apex that respects governor limits. See Governor limits, Async Apex chooser
- Triggers (4 rules): One thin trigger per object that delegates to a handler class. See Trigger handler pattern
- SOQL (4 rules): Selective, minimal and safe queries. See SOQL formatter
- Security and sharing (5 rules): Sharing, CRUD and field-level security by default.
- Testing (6 rules): Tests that assert behavior, not tests that only add coverage.
- Lightning Web Components (6 rules): Modern LWC patterns and safe Apex calls from components. See Call Apex from LWC
- Flow and automation (5 rules): Declarative automation that coexists with Apex.
- Integration and callouts (5 rules): Authenticated, mockable, async-friendly callouts. See Named Credentials and callouts
- Salesforce CLI and deployment (6 rules): Modern sf commands, source-driven development. See Salesforce CLI reference, Salesforce Code Analyzer
- Known AI mistakes (5 rules): Things coding assistants commonly get wrong on Salesforce. See Governor limits
How to keep the file short and effective
- Aim for under 200 lines. Anthropic notes that longer CLAUDE.md files use more context and reduce adherence.
- Turn off topics your project does not use, for example LWC in a backend-only package.
- Write specific, checkable rules ("never run SOQL in a loop") instead of vague ones ("write clean code").
- Add only what the assistant cannot infer from the code: your API version, source directory, namespace, how to run tests and how you deploy.
- Use the extra line for one project-specific rule, and prune the file when rules become outdated.
- Remember the file is guidance, not enforcement. To block an action reliably, use tooling such as hooks, CI checks and branch protection.
Instructions help, they do not guarantee correct code
An instruction file raises the chance an assistant follows your rules, but it can still invent a method, misremember a limit or skip a rule. Review every change, run your Apex tests and Jest tests, and scan with Salesforce Code Analyzer. Check limits in the governor limits reference and pick async patterns with the async Apex chooser.
Frequently asked questions
What is a CLAUDE.md file for Salesforce development?
It is a Markdown file in your project root that Claude Code reads at the start of every session. For a Salesforce DX project it holds rules such as bulkify Apex, no SOQL or DML in loops, one trigger per object, and use the sf CLI, plus facts like the API version and source directory.
Where do I put each file?
CLAUDE.md and AGENTS.md go in the project root. Cursor rules go in .cursor/rules/ as an .mdc file with description, globs and alwaysApply frontmatter. GitHub Copilot reads .github/copilot-instructions.md. The tool shows the target path above the preview.
Do I need both CLAUDE.md and AGENTS.md?
Usually not. Claude Code can read AGENTS.md as the project instructions when no CLAUDE.md exists, and Cursor also reads AGENTS.md. If your team uses several assistants, one AGENTS.md is the simplest choice. If a CLAUDE.md exists, Claude Code reads it instead of AGENTS.md.
How long should the file be?
Keep it short. Anthropic recommends targeting under 200 lines per CLAUDE.md because longer files use more context and reduce how well the instructions are followed. Deselect topics you do not need and add only rules specific to your project.
Will these instructions guarantee correct Apex?
No. Instructions improve the odds that an assistant follows your conventions, but assistants can still invent methods, miss limits or ignore a rule. Review every change, run your Apex and Jest tests, and run Salesforce Code Analyzer.
Why does the file tell the assistant to verify against the API version?
Assistants sometimes use methods, fields or metadata that do not exist, or deprecated features, especially for new releases. Naming the API version and telling the assistant to say when it is unsure reduces confident guessing.
Is my project information uploaded?
No. The file is built in your browser. Your settings (selected topics and the facts you type) are saved only in your browser's local storage, and nothing is sent to SFDX Talk or anyone else.
Related guides
More tools
SFDX Talk is unofficial documentation. It is not affiliated with, endorsed by, or sponsored by Salesforce, Inc. Salesforce changes its platform every release, so confirm against the official page before relying on a value.