How to Connect Claude Code to Your Salesforce Org (Step-by-Step)
You've heard the hype: AI pair-programmers that write Salesforce Apex, build flows, and generate SOQL in seconds. But out of the box, Claude Code knows nothing about your specific org — your custom objects, field names, validation rules, or permission sets. Without that context, you get hallucinated field names, incorrect API versions, and code that fails on deploy.
This guide walks you through the exact steps to connect Claude Code to your Salesforce org so every suggestion is grounded in your real metadata.
What You Need Before You Start
Before connecting Claude Code to Salesforce, make sure you have: (1) Claude Code installed via npm install -g @anthropic-ai/claude-code, (2) Salesforce CLI (sf) installed and authenticated to your org, (3) A Salesforce Developer Edition or sandbox org (never connect AI tooling directly to production first), and (4) VS Code or your preferred IDE open on a Salesforce DX project.
Step 1: Authenticate the Salesforce CLI
Run sf org login web --alias my-dev-org to open a browser and authenticate. Once logged in, confirm with sf org display --target-org my-dev-org. You should see your username and instance URL. This gives the CLI — and by extension your AI tools — the ability to pull live metadata from your org.
Step 2: Create Your CLAUDE.md Context File
The CLAUDE.md file is Claude Code's memory for your project. Create it in the root of your SFDX project. At minimum, include: your org's API version, the names of your key custom objects and their API names, your naming conventions (e.g. Radix2__ prefix), which profiles and permission sets matter, and any Apex coding standards your team follows. The more accurate this file is, the fewer hallucinations you'll see.
Step 3: Pull Live Metadata into Your Project
Run sf project retrieve start --metadata CustomObject --target-org my-dev-org to pull your custom object definitions locally. Claude Code can then read these XML files directly, giving it accurate field names, data types, and picklist values. Do the same for ApexClass, Flow, and any other metadata types you'll be working with. Store these in your project's force-app directory and commit them to Git.
Step 4: Use the Salesforce MCP Server (Advanced)
For a tighter integration, configure the Salesforce MCP server so Claude Code can query your org live during a session. Add it to your .mcp.json: { "mcpServers": { "salesforce": { "command": "npx", "args": ["@salesforce/mcp-server"], "env": { "SF_ORG_ALIAS": "my-dev-org" } } } }. With this configured, Claude can run SOQL queries, check field existence, and validate API names in real time — without ever leaving the conversation.
Step 5: Test the Integration
Open Claude Code in your terminal from the project root and type: /What custom objects exist in this org? Claude should reference your local metadata files and list your objects accurately. Then ask it to Write a trigger on Account that updates a custom field — it should use the correct API names from your pulled metadata rather than inventing plausible-sounding names.
Common Mistakes to Avoid
Don't skip the metadata pull — Claude Code is only as accurate as the files it can read. Don't use a production org for initial testing; mistakes in AI-generated code should hit a sandbox first. Don't leave your CLAUDE.md empty; a blank context file means Claude falls back to generic Salesforce knowledge, which may not match your org's customizations. And don't forget to update CLAUDE.md when you add new custom objects or change field names.
Next Steps
Once Claude Code is connected to your org, explore slash commands for common Salesforce tasks, set up the AiOS (AI Operating System) for persistent org context across sessions, and consider adding automated tests to your CI/CD pipeline that validate AI-generated Apex before it reaches production. The setup takes under an hour, but the productivity gains compound every single day.
Stop re-explaining your Salesforce org to every AI
AiOS installs a living knowledge base into your org so Claude, Cursor, and Codex start every session with full context — field names, objects, conventions and all. Free and open source.
Get AiOS Free →