# Claude Code for Salesforce Devs: Setup That Actually Works

Claude Code is Anthropic's AI coding assistant, and it works remarkably well with Salesforce — once you set it up properly. The confusing part is that "Claude Code" isn't a single thing. It runs three ways: as a terminal app, as a tab inside the Claude desktop app, and as an extension inside VS Code. All three connect to your org the same way, through the Salesforce CLI, so the connection only needs to be configured once.

This guide covers that one-time Salesforce setup, walks through each of the three options step by step, and finishes with the guardrails you should put in place before an AI agent touches your metadata.

## Which flavor should you pick?

- **Terminal** — if you're comfortable on the command line. A chat conversation living inside your terminal window.
- **Claude desktop app** — if you'd rather never open a terminal. A familiar chat window that works with files on your computer.
- **VS Code extension** — if you already use VS Code for Salesforce. Claude works in a side panel, and every change shows up as a side-by-side diff you can accept or reject.

You only need one. Never used a terminal? Start with the desktop app. Already living in VS Code? Go with the extension.

## What you'll need

- A Claude Pro, Max, Team, or Enterprise plan (or an Anthropic Console account). Claude Code isn't available on the free plan.
- **Node.js** (LTS version) — required to install the Salesforce CLI.
- The **Salesforce CLI** (`sf`) — Claude uses it to retrieve metadata, run queries, and deploy.
- A **Salesforce sandbox or developer org** — your safe testing ground.
- **Git** (recommended) — so you can track and roll back whatever Claude changes.
- **VS Code** — only needed for the extension option.

One thing to sort out first: everything Claude reads from your org leaves Salesforce and is processed by the model provider. Check your organization's AI policy before you begin, and start with a sandbox — never production.

## Part 1: The Salesforce setup (do this once)

Everyone completes this part, no matter which option they pick.

**1. Install Node.js.** Download the LTS installer from nodejs.org and run it. Check the install with `node --version` — you should see something like `v22.x.x`.

**2. Install the Salesforce CLI.** Run `npm install -g @salesforce/cli`, then verify with `sf --version` (look for `@salesforce/cli/2.x.x`).

**3. Install Git.** On a Mac, running `git --version` will offer to install it if it's missing. On Windows, download Git for Windows from git-scm.com with the default options.

**4. Create a Salesforce DX project.** Claude Code works from inside a folder, and a DX project gives it the standard structure:

```
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 tab opens — sign in with your sandbox username (usually your email plus the sandbox name, e.g. `admin@company.com.dev`). If your sandbox uses My Domain, you can use that URL instead.

**6. Set it as the default org.**

```
sf config set target-org my-sandbox
```

**7. Test the connection.**

```
sf org display
sf data query --query "SELECT COUNT() FROM Account"
```

If `sf org display` shows your sandbox with a Connected status and the query returns an Account count, the Salesforce side is ready. Claude Code will reuse this login in every option.

## Part 2: Install Claude Code your way

### Option A: Terminal

On Mac or Linux: `curl -fsSL https://claude.ai/install.sh | bash`. On Windows (PowerShell): `irm https://claude.ai/install.ps1 | iex`. Or, if you already have Node.js: `npm install -g @anthropic-ai/claude-code`. Check with `claude --version`.

Then move into your project folder — this matters, because Claude Code only sees the folder you launch it from:

```
cd ~/Documents/claude-sf-lab
claude
```

On first launch you'll pick a theme, choose how to log in (your Claude account or an Anthropic Console account), approve the browser login, and confirm that you trust the files in the folder. Then type this test 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."*

Claude shows each command before running it and asks for approval. Approve them, and it should report your sandbox username and the same Account count you saw in Part 1. Handy commands: `/help`, `/clear` for a fresh conversation, `/init` to generate a CLAUDE.md (see Part 3), and Esc to stop Claude mid-task.

### Option B: Claude desktop app

Download the app from claude.ai/download, install it, and sign in. Switch to the **Code tab** at the top — the regular chat tab can't run commands on your computer, so for Salesforce work you need the Code tab. Start a new session, point it at your `claude-sf-lab` folder, and choose to run locally on your computer. Because the session runs on your machine, it picks up the same Salesforce CLI login from Part 1 — no second Salesforce login needed.

Type the same test prompt and approve the commands. Two gotchas: if Claude says `sf: command not found`, quit the app completely (Cmd+Q on Mac, not just closing the window) and reopen it. And avoid the web version at claude.ai/code for this workflow — it runs in the cloud, so it can't see your local Salesforce CLI login.

### Option C: VS Code extension

Install the **Salesforce Extension Pack** first — not strictly required, but the syntax highlighting and right-click deploy/retrieve menus make reviewing Claude's work much easier. Then search the Extensions panel for **Claude Code** and install the one published by **Anthropic** (check the publisher name). Open your `claude-sf-lab` folder, click the Claude icon, sign in through the browser, and run the test prompt in the Claude panel.

The big advantage here: when Claude edits a Flow or validation rule, VS Code shows a side-by-side diff so you can review the change before accepting it. Type `@` in the Claude panel to point at a specific file, like `@force-app/main/default/objects/Opportunity`.

## Part 3: Guardrails before real work

This applies to all three options.

**Create a CLAUDE.md file.** Claude reads it at the start of every session. Include rules like: the default org is the sandbox alias `my-sandbox`; never target production unless you name the production alias; never deploy without asking; 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 asked; and save reports to a `reports/` folder. You can also run `/init` inside Claude Code to generate a starting file, then add your rules.

**Keep command approvals on.** The default setting asks before running commands or editing files — leave it that way. Before approving anything, scan for `deploy`, `delete`, or a production alias hiding in `--target-org`.

**Commit your starting point** with `git add .` and `git commit -m "Initial Salesforce DX project"`. Now if Claude changes something you don't like, you can always roll back.

## Wrapping up

Set up the Salesforce CLI once, pick the Claude Code option that matches how you work, and put your guardrails in place. From there, you can ask Claude to write Apex, explain a Flow, audit your validation rules, or generate test classes — always against your sandbox, always with you approving every move.

---

Originally published at [Way2Force](https://way2force.com/how-to-set-up-claude-code-for-salesforce-terminal-claude-desktop-app-and-vs-code/).
