Claude Code

How to Set Up Claude Code for Salesforce: Terminal, Claude Desktop App, and VS Code

How to Set Up Claude Code for Salesforce: Terminal, Claude Desktop App, and VS Code

setting it up can feel confusing. Is it a terminal tool? An app? A VS Code extension?

It’s all three. Claude Code is one tool that you can run three ways:

  1. In the terminal, the command-line version
  2. In the Claude desktop app, through the Code tab, with no terminal needed day to day
  3. In your IDE, as an extension for VS Code (and editors based on VS Code, like Cursor)

All three run on your computer and connect to Salesforce the same way, through the Salesforce CLI (sf). Once you connect the Salesforce CLI to your org, any of the three can use it.

Today we will covers the one-time Salesforce setup first, then each of the three options step by step. You only need one option, so pick the one that fits how you work

Before you start: Check your organization's policy on AI tools accessing Salesforce metadata and data. Metadata and query results that Claude reads leave your org and are sent to the model provider for processing. Depending on your setup, this could be Anthropic, Amazon Bedrock, or Google Vertex AI. Always start with a sandbox, never production.

Which option should you pick?

OptionBest forWhat it feels like
A. TerminalComfortable with the command lineA chat inside your terminal window
B. Claude desktop appWho want to avoid the terminalA chat window, like regular Claude, that can work with files on your computer
C. VS Code extensionWho already use VS Code with Salesforce ExtensionsA Claude panel next to your metadata files, with changes shown as side-by-side diffs

Not sure? Start with Option B if you’ve never used a terminal, or Option C if you already have VS Code set up for Salesforce.


What you need

RequirementWhy
A Claude Pro, Max, Team, or Enterprise plan (or an Anthropic Console account)Claude Code needs one of these. The free plan doesn’t include it.
Node.js (LTS version)Used to install the Salesforce CLI
Salesforce CLI (sf)Claude uses it to retrieve metadata, run queries, and deploy
A Salesforce sandbox/dev loginA safe place to test
Git (recommended)Tracks changes to your metadata. Task 7 in the next post uses Git history.
VS CodeOnly needed for Option C

Part 1: Set Up the Salesforce Side (Do This Once)

Everyone completes this part, whichever option you choose.

Step 1: Install Node.js

Download the LTS version from nodejs.org and run the installer.

Test it. Open Terminal (Mac) or PowerShell (Windows) and run:

				
					node --version
				
			

Node Version

You should see a version number like v22.x.x.

Step 2: Install the Salesforce CLI

				
					npm install -g @salesforce/cli
				
			

Test it:

				
					sf --version
				
			

You should see something like @salesforce/cli/2.x.x.sf --version

Step 3: Install Git (recommended)

  • Mac: Run git --version. If Git isn’t installed, macOS offers to install it for you.
  • Windows: Download Git for Windows from git-scm.com and install it with the default options.

Test it:

				
					git --version
				
			

Step 4: Create a Salesforce DX project

Claude Code works inside a folder. A Salesforce DX project gives it the standard structure for retrieving and deploying metadata.

Move to the folder where you keep your work, for example your Documents folder:

				
					cd ~/Documents
				
			

Create the project:

				
					sf project generate --name claude-admin-lab
				
			

Move into it:

				
					cd claude-admin-lab
				
			

Turn it into a Git repository so you can track changes:

				
					git init
				
			

You now have a folder called claude-admin-lab with files like sfdx-project.json and a force-app folder.

Step 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 username (it usually ends in .sandboxname, for example admin@company.com.dev). When you see “Authentication successful,” you can close the browser tab.

Tip: If your org uses My Domain, you can use your sandbox's My Domain URL instead, for example https://yourcompany--dev.sandbox.my.salesforce.com.

Step 6: Make the sandbox the default org for this project

				
					sf config set target-org my-sandbox
				
			

Step 7: Test the Salesforce connection

				
					sf org display
				
			

You should see your sandbox username, instance URL, and a Connected Status of Connected.

Also try a quick query:

				
					sf data query --query "SELECT COUNT() FROM Account"
				
			

 Test the Salesforce connection

Checkpoint: If both commands work, the Salesforce side is ready. Claude Code will use this same login in all three options.


Part 2: Choose Your Option

Option A: Claude Code in the Terminal

Step A1: Install Claude Code

Mac or Linux. Open Terminal and run:

				
					curl -fsSL https://claude.ai/install.sh | bash
				
			

Windows. Open PowerShell and run:

				
					irm https://claude.ai/install.ps1 | iex
				
			

Alternative (any OS, if you already have Node.js):

				
					npm install -g @anthropic-ai/claude-code
				
			

Test it:

				
					claude --version
				
			

Step A2: Open your project folder

				
					cd ~/Documents/claude-admin-lab
				
			

This step matters. Claude Code works with the folder you start it in. Start it in your DX project so it can see your metadata and your Salesforce CLI settings.

Step A3: Start Claude Code and log in

				
					claude
				
			

Start Claude Code and log in

The first time you run it:

  1. Claude Code asks you to choose a theme. Pick any.
  2. It asks how you want to log in. Choose your Claude account (Pro, Max, Team, or Enterprise) or an Anthropic Console account.
  3. A browser window opens. Approve the login.
  4. Back in the terminal, Claude Code may ask whether you trust the files in this folder. Choose Yes, since this is your own project.

You’ll now see a prompt where you can type messages to Claude.

prompt where you can type messages to Claude.

Step A4: Run the connection test

Type this prompt and press Enter:

"Run sf org display and tell me which org this project is connected to. Then run a SOQL query to count the Account records."

Claude shows you each command before running it and asks for approval. Choose Yes for each one.

Run the connection test

Checkpoint: Claude should report your sandbox username and an Account count. Compare the count with the one you got in Part 1, Step 7.

Useful terminal commands

CommandWhat it does
/helpShows available commands
/clearStarts a fresh conversation
/initCreates a CLAUDE.md file describing your project (see Part 3)
/mcpShows connected MCP servers
EscStops Claude mid-task
Ctrl + C twiceExits Claude Code

Option B: Claude Code in the Claude Desktop App

With this option, you use Claude Code through a regular app window. You never type commands yourself. Claude runs them for you, with your approval.

Step B1: Install the Claude desktop app

  1. Go to claude.ai/download.
  2. Download the version for Mac or Windows.
  3. Install it and sign in with your Claude account.

Step B2: Open the Code tab

At the top of the app, you’ll see tabs for chat and Code. Click Code.

The regular chat tab can't run commands on your computer. For Salesforce work, you need the Code tab.

Step B3: Start a session in your project folder

  1. Start a new session.
  2. When the app asks which folder to use, select the claude-admin-lab folder you created in Part 1 (for example, Documents/claude-admin-lab).
  3. Pick the option to run the session locally on your computer, if the app asks.

Because the session runs on your computer, it uses the same Salesforce CLI login from Part 1. You don’t need to log in to Salesforce again.

Important: Claude Code on the web (claude.ai/code) runs in a cloud environment, not on your computer. It can't see your local Salesforce CLI login. For this series, use the desktop app, the terminal, or VS Code.

Step B4: Run the connection test

Type the same prompt:

"Run sf org display and tell me which org this project is connected to. Then run a SOQL query to count the Account records."

The app shows each command and asks for approval before running it. Approve them.

Run the connection test

 Checkpoint: You should see your sandbox username and the same Account count as in Part 1.

Troubleshooting for the desktop app

If Claude says sf: command not found, quit the Claude desktop app completely and reopen it. The app has to pick up the Salesforce CLI you just installed. On Mac, use Cmd + Q, not just closing the window.


Option C: Claude Code in VS Code

This option works well for admins who already use VS Code with Salesforce. Claude works in a panel next to your metadata files, and you can review each change as a side-by-side diff before accepting it.

Step C1: Install VS Code

Download it from code.visualstudio.com and install it.

Step C2: Install the Salesforce Extension Pack (recommended)

  1. In VS Code, click the Extensions icon in the left sidebar (four squares), or press Cmd + Shift + X (Mac) or Ctrl + Shift + X (Windows).
  2. Search for Salesforce Extension Pack.
  3. Click Install on the one published by Salesforce.

You don’t strictly need this for Claude Code, but it adds Salesforce syntax highlighting, org browsing, and deploy/retrieve right-click menus. These make it much easier to review what Claude retrieves.

Step C3: Install the Claude Code extension

  1. In the Extensions panel, search for Claude Code.
  2. Click Install on the one published by Anthropic. Check the publisher name so you get the official extension.
  3. After it installs, you’ll see a Claude icon in the sidebar or the editor toolbar.
This extension also works in editors based on VS Code, like Cursor and Windsurf. For JetBrains IDEs, such as IntelliJ with Illuminated Cloud, there's a separate Claude Code plugin in the JetBrains Marketplace.

 Install the Claude Code extension

Step C4: Open your project folder

  1. Go to File → Open Folder.
  2. Select the claude-admin-lab folder.
  3. If VS Code asks whether you trust the authors of the files, choose Yes, I trust the authors.

You should see force-app, sfdx-project.json, and your other project files in the Explorer on the left.

Step C5: Open Claude Code and sign in

  1. Click the Claude icon.
  2. The first time, the extension asks you to sign in. Follow the prompts to log in with your Claude account in the browser.
  3. A Claude panel opens where you can type prompts.

Step C6: Run the connection test

Type the same prompt:

"Run sf org display and tell me which org this project is connected to. Then run a SOQL query to count the Account records."

Approve the commands when asked.

Checkpoint: You should see your sandbox username and the same Account count as in Part 1.

Install the Claude Code extension

Why VS Code is handy for Salesforce work

  • Side-by-side diffs: When Claude edits a Flow or validation rule file, VS Code shows the before and after. You accept or reject the change.
  • Mention files: Type @ in the Claude panel to point Claude at a specific file, for example @force-app/main/default/objects/Opportunity.
  • Salesforce Extensions: Right-click a metadata file to deploy or retrieve it yourself, after reviewing Claude’s work.

Part 3: Add Guardrails Before Real Work

This part applies to all three options.

Step 1: Create a CLAUDE.md file

CLAUDE.md is a file in your project folder that Claude reads at the start of every session. Use it to set rules.

Create a file named CLAUDE.md in the claude-admin-lab folder with this content:

				
					# Salesforce Admin Project


## Orgs 
- Default org is the sandbox alias `my-sandbox`.
- Never target production unless I name the production alias in my prompt. 

## Safety rules
- Never deploy without asking me first. 
- Prefer `sf project deploy validate` (validation only) over real deployments. 
- Never delete metadata or records. - Don't query sensitive fields (SSN, salary, health data, personal phone numbers) unless I ask.

## Output 
- Save reports, CSV exports, and documentation to a `reports/` folder. 
- Use Markdown tables for summaries.
				
			

You can also type /init in Claude Code to have Claude draft a starting CLAUDE.md for you, then add the rules above.

Step 2: Keep command approvals on

By default, Claude Code asks before running commands and editing files. Leave it that way while you learn. Before you approve anything, check for:

  • deploy (changes your org)
  • delete (removes metadata or data)
  • A production alias in --target-org

Step 3: Commit your starting point to Git

Before trying any tasks, save a clean starting point:

				
					git add .
				
			
				
					git commit -m "Initial Salesforce DX project"
				
			

If Claude changes something you don’t like, you can always return to this point. You can also ask Claude to run these commands for you.


Troubleshooting

ProblemFix
sf: command not foundReinstall the Salesforce CLI, then restart your terminal, the Claude desktop app, or VS Code
claude: command not foundClose and reopen the terminal. If it still fails, reinstall Claude Code.
“No default org set”Run sf config set target-org my-sandbox inside the project folder
Expired or invalid sessionLog in again: sf org login web --alias my-sandbox --instance-url https://test.salesforce.com
Claude is connected to the wrong orgRun sf org list to see all orgs and which one is the default
Claude can’t see your filesMake sure you started Claude Code in, or opened, the claude-admin-lab folder
“Claude Code isn’t available on your plan”Claude Code needs Pro, Max, Team, Enterprise, or a Console account

Quick Recap

  1. Install Node.js, the Salesforce CLI, and Git.
  2. Create a DX project and log in to your sandbox.
  3. Pick one option: Terminal, Claude desktop app, or VS Code.
  4. Run the test prompt and confirm the org and Account count.
  5. Add a CLAUDE.md file with safety rules and commit your starting point.
Shares:

Related Posts

Nothing Found! Ready to publish your first post? Get started here.