keepcalculator

06 Numbers and Powers

Claude Code Customization for Salesforce

Card No. 06·73660 · Updated · Standard formula, shown below

To choose the right Claude Code customization for Salesforce, you need to map your team’s workflow to specific configuration files: CLAUDE.md for project-wide rules, .claude/settings.json for permissions and hooks, and custom slash commands for repetitive tasks. This article explains each layer, when to use it, and how to combine them for Apex, Lightning Web Components, and Salesforce CLI workflows.

Background: Why Claude Code Needs Customization for Salesforce

Claude Code is an agentic coding tool that runs in your terminal and can read, edit, and execute commands in your repository. Out of the box, it has no knowledge of Salesforce-specific conventions like Apex governor limits, SOQL queries, or the structure of a Salesforce DX project. Without customization, the model may generate code that violates org limits, uses outdated APIs, or ignores your team’s deployment process.

Salesforce development has unique constraints: every Apex transaction has a 100 SOQL query limit, a 50MB heap size limit, and a 10,000 character limit for dynamic SOQL. A generic coding assistant won’t know these unless you tell it. Customization files let you embed this context directly into the tool, so every prompt and edit is guided by your project’s rules.

How Claude Code Customization Works

Claude Code reads configuration from three main places, in order of increasing specificity:

  • User-level settings (~/.claude/CLAUDE.md) – applies to all your projects, good for personal preferences like always using 4-space indentation.
  • Project-level memory (CLAUDE.md in the repo root) – the primary file for Salesforce-specific instructions, read on every session.
  • Subdirectory memory (force-app/main/default/classes/CLAUDE.md) – applies only to files in that folder, useful for Apex-specific rules.
  • Settings and hooks (.claude/settings.json) – controls permissions, allowed commands, and lifecycle hooks that run before/after actions.
  • Slash commands (.claude/commands/*.md) – custom prompts you can invoke with /command-name.

The files are plain markdown or JSON. Claude Code reads them at session start and uses them as system context. You can also reference other files with @path/to/file to include specific documentation.

How to Choose the Right Customization Layer

Start with the simplest layer that solves your problem. Here’s a decision guide:

  1. If you need to enforce coding standards (e.g., always use System.debug instead of System.debug() with no message), put them in the root CLAUDE.md.
  2. If you need to restrict what Claude can do (e.g., never run sfdx force:source:deploy without confirmation), add permissions to .claude/settings.json.
  3. If you have a repetitive task (e.g., generating a test class for a trigger), create a custom slash command that includes the exact prompt template.
  4. If you have folder-specific rules (e.g., LWC components must use shadow DOM), place a CLAUDE.md in that folder.

For most Salesforce teams, a combination of a root CLAUDE.md with project conventions and a few slash commands for common tasks is sufficient. Avoid over-customizing – too many rules can make the model overly cautious or confused.

Common Problems and Misconceptions

Misconception: You need a separate configuration for each Salesforce org. Actually, Claude Code works on the source code in your repo, not on the org itself. If you use Salesforce DX with scratch orgs, the same configuration works for all orgs because the code is the same. If you have multiple projects (e.g., one for managed packages, one for internal apps), each project should have its own CLAUDE.md.

Problem: The model ignores your Apex governor limits. This happens when the rules are too vague. Instead of saying “respect governor limits,” list the specific numbers: “SOQL queries per transaction: 100; DML statements: 150; heap size: 6MB for synchronous, 12MB for asynchronous.” Provide examples of bad vs. good code.

Problem: Claude tries to run destructive commands. Use settings.json to deny or require permission for commands like sfdx force:org:delete or rm -rf. You can also set allow lists for safe commands like sfdx force:source:push.

Comparing Customization Options

Here’s a quick comparison of the main customization files:

  • CLAUDE.md – Best for static instructions and context. Read every session, no setup. Downside: can get long; no conditional logic.
  • settings.json – Best for permissions and hooks. Can block or allow commands, set environment variables. Downside: JSON syntax is strict; not for prose.
  • Slash commands – Best for interactive workflows. You can define a command that asks for user input (e.g., “Enter the object name”) and then runs a script. Downside: requires markdown formatting.
  • Hooks – Best for automating checks (e.g., run sfdx force:source:lint after every edit). Downside: can slow down sessions if too many.

For most Salesforce needs, CLAUDE.md is the workhorse. Slash commands are great for complex prompts you reuse. Hooks are advanced and only needed for CI-like checks.

Costs and Considerations

Claude Code itself is a paid feature of Anthropic’s API, but the customization files are free and local. The cost is in your time to write and maintain them. A well-maintained CLAUDE.md can save hours per week by reducing back-and-forth corrections.

Be careful with secrets: never put org credentials or tokens in CLAUDE.md or settings.json if they are committed to a shared repo. Use environment variables referenced in the settings file, and keep sensitive data in .env files that are gitignored.

Safety and Best Practices

When customizing Claude Code for Salesforce, follow these safety rules:

  • Never allow destructive commands without confirmation. In settings.json, use "permissions": {"allow": ["sfdx force:source:push"], "deny": ["sfdx force:org:delete"]}.
  • Test custom slash commands in a scratch org before using them on a shared dev org.
  • Keep your CLAUDE.md under version control so changes are tracked and reviewable.
  • Use subdirectory CLAUDE.md files sparingly – they can fragment context and cause inconsistent behavior.

Remember that Claude Code is a tool, not a replacement for code review. Always review generated Apex for security (e.g., SOQL injection) and performance (e.g., N+1 queries).

Frequently Asked Questions

Q: Can I use the same CLAUDE.md for both Apex and LWC?
Yes, but it’s better to split: put common rules in the root CLAUDE.md and folder-specific rules in force-app/main/default/classes/CLAUDE.md and force-app/main/default/lwc/CLAUDE.md. This keeps instructions relevant to the file type.

Q: How do I make Claude Code run Salesforce CLI commands automatically?
Use hooks in settings.json. For example, a PostToolUse hook can run sfdx force:source:lint after every file edit. You need to define the hook in JSON and point it to a shell script.

Q: What’s the best way to teach Claude Code about my org’s custom objects?
Don’t put the entire schema in CLAUDE.md – it will be too long. Instead, reference a file with @force-app/main/default/objects/MyObject__c/fields/MyField__c.field-meta.xml or use a slash command that loads the relevant metadata on demand.

Q: Can I use Claude Code with Salesforce CLI without DX?
Yes, but it’s less ideal. If you use the Metadata API format (mdapi), you can still configure CLAUDE.md with rules for XML metadata files. However, DX is recommended because it provides a cleaner source structure.

Q: How often should I update my customization files?
Update them whenever your team’s conventions change, or when you notice Claude making the same mistake twice. A monthly review is a good habit.

Q: Does Claude Code support Salesforce-specific autocomplete?
No, it’s not an IDE plugin. It works in the terminal and can suggest commands, but it won’t autocomplete object names. You can mitigate by including a glossary of common objects in CLAUDE.md.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.

More cards in this drawer

The whole Numbers and Powers drawer →