AI-assisted development is moving fast, and Salesforce work is no exception. Claude Code — Anthropic's agentic coding tool — can retrieve metadata, write Apex and SOQL, and deploy changes, all through the Salesforce CLI you already know. But getting started raises a basic question: what exactly do you install? The answer is that Claude Code is one tool with three faces: a terminal app, a tab inside the Claude desktop app, and a VS Code extension. All three authenticate to your org the same way, through the Salesforce CLI.
In this guide, I'll walk you through the one-time Salesforce-side setup and then each of the three options, so you can pick the one that matches how you work. Before you start, check your organization's policy on AI tools accessing Salesforce metadata and data — and use a sandbox, never production.
Part 1: The One-Time Salesforce Setup
Do this once. Every option below relies on it.
1. Install Node.js. Grab the LTS version from nodejs.org and run the installer. Verify it with:
node --version
2. Install the Salesforce CLI. In your terminal, run:
npm install -g @salesforce/cli
sf --version
You should see something like @salesforce/cli/2.x.x.
3. Install Git (recommended). Check with git --version. Windows users can download it from git-scm.com.
4. Create a Salesforce DX project. Claude Code works inside a folder, and a DX project gives it the standard layout it expects:
cd ~/Documents
sf project generate --name claude-sf-lab
cd claude-sf-lab
git init
5. Log in to your sandbox.
sf org login web --alias my-sandbox --instance-url https://test.salesforce.com
A browser window opens — log in with your sandbox credentials (the username usually ends in something like admin@company.com.dev) and close the tab once you see "Authentication successful."
6. Set the sandbox as the default org for the project:
sf config set target-org my-sandbox
7. Test the connection.
sf org display
sf data query --query "SELECT COUNT() FROM Account"
If both work, the Salesforce side is done. Everything below reuses this login.
Part 2: Pick Your Interface
Option A — Terminal
Best if you're comfortable on the command line: a chat session running inside your terminal.
- Mac/Linux:
curl -fsSL https://claude.ai/install.sh | bash - Windows (PowerShell):
irm https://claude.ai/install.ps1 | iex - Alternative on any OS:
npm install -g @anthropic-ai/claude-code
Then cd into your project folder and run claude. On first launch you'll pick a theme, choose your Claude account login (Pro, Max, Team, Enterprise, or an Anthropic Console account), approve the browser login, and confirm you trust the folder. Test it with:
Run
sf org displayand tell me which org this project is connected to. Then run a SOQL query to count Accounts.
Claude shows each command and asks for approval before running it — approve them and confirm the org and count match what you saw in Part 1.
Handy session commands: /help lists commands, /clear starts a fresh conversation, /init drafts a CLAUDE.md file for your project, /mcp shows connected MCP servers, Esc stops Claude mid-task, and double Ctrl+C exits.
Option B — Claude Desktop App
Best if you'd rather skip the terminal entirely: a familiar chat window that can work with files on your computer.
- Download the app from claude.ai/download and sign in.
- Open the Code tab at the top.
- Start a new session and point it at your
claude-sf-labfolder (run it locally on your computer when asked). - Run the same connection-test prompt and approve the commands.
Because the session runs on your machine, it picks up the same Salesforce CLI login from Part 1. One caveat: Claude Code on the web at claude.ai/code runs in the cloud and can't reach your local CLI, so use the desktop app for Salesforce work.
Troubleshooting tip: if Claude reports sf: command not found, quit the desktop app completely (Cmd+Q or a full quit — not just closing the window) and reopen it so it picks up your PATH.
Option C — VS Code Extension
Best if you already live in VS Code with the Salesforce Extension Pack: Claude works in a side panel next to your metadata.
- Install the Salesforce Extension Pack from the Extensions view (
Cmd+Shift+X/Ctrl+Shift+X). - Search for "Claude Code" and install the one published by Anthropic.
- Open your
claude-sf-labfolder (File → Open Folder) and trust the authors. - Click the Claude icon, sign in, and run the connection-test prompt.
Why developers like this option: edits appear as side-by-side diffs you can accept or reject, you can @-mention files (e.g. @force-app/main/default/objects/Opportunity) to point Claude at specific metadata, and you can still deploy or retrieve individual files yourself with the Extension Pack after reviewing Claude's work.
Part 3: Add Guardrails Before Doing Real Work
Whichever option you chose, set these up first:
-
Create a
CLAUDE.mdfile in the project root with rules Claude reads every session — e.g. "Default org is the sandbox aliasmy-sandbox. Never target production. Ask before deploying." (Running/initin Claude Code can draft one for you.) - Keep command approvals on. By default, Claude asks before running commands or editing files. Leave it that way — especially for anything that modifies your org or deletes metadata.
-
Commit a clean starting point with
git add .andgit commit -m "Initial Salesforce DX project"so you can always roll back.
Quick Troubleshooting
-
sf: command not found→ reinstall the Salesforce CLI, then restart your terminal, app, or VS Code. -
claude: command not found→ reopen the terminal; reinstall Claude Code if it persists. - "No default org set" → run
sf config set target-org my-sandboxin the project folder. - Expired session → log in again with the
sf org login webcommand from Step 5. - Claude connected to the wrong org → run
sf org listto see all orgs and the default. - "Claude Code isn't available on your plan" → you need Pro, Max, Team, Enterprise, or a Console account.
Recap
- Install Node.js, the Salesforce CLI, and Git.
- Scaffold a DX project and authorize your sandbox.
- Pick one interface: terminal, desktop app, or VS Code.
- Run the test prompt and confirm the org and Account count.
- Add
CLAUDE.mdguardrails and commit your starting point.
Pick the option that fits your workflow, and you're ready to let Claude Code handle the repetitive parts of Salesforce development — safely, in a sandbox.
Originally published at Way2Force.
Top comments (0)