The CLI works, Claude can reach your sandbox, and then a client asks you to “also look at UAT.” Adding another org is one command and a sensible nickname, on a Mac or a PC. Here is the whole thing, plus the cleanup you will need later.
sf org login web does the whole jobOn this page
You set up one org and forgot how.
You got the Salesforce CLI working, felt like a hacker for a solid afternoon, and moved on with your life. Now there is a second sandbox, and the first setup is a blur.
Good news: adding an org is much smaller than the first setup. Nothing gets installed. You log in once, give the org a nickname, and from then on the CLI (and Claude, when you ask it to use the CLI) knows which org you mean.
This is the quick version, for when the CLI is already installed. If you are starting from zero, do the Salesforce CLI setup guide first and come back.
Same commands on a Mac or a PC.
Every sf command in this post is identical on both. What changes is where you type it, and how you write a folder path.
| Mac | Windows | |
|---|---|---|
| Where you type | Terminal | Command Prompt (not PowerShell) |
| How to open it | Command + Space, type Terminal, press Return | Click Start, type cmd, open Command Prompt |
| Your home folder | ~ | %USERPROFILE% |
| Folder separator | / | \ |
| Go to a client folder | cd ~/salesforce-cli-projects/acme | cd %USERPROFILE%\salesforce-cli-projects\acme |
Why not PowerShell?
PowerShell can block some of these commands with a “running scripts is disabled on this system” error, which is a fun thing to debug ten minutes before a client call. Command Prompt does not have that problem. If you do see that error, you are in PowerShell. Open Command Prompt and run the same command again.
Only one command in this post needs a folder path (the default org one in Housekeeping), and it is written out both ways. Everything else you can paste as is.
Pick a boring nickname.
Every org you log in to gets a nickname, which the CLI calls an alias. You will type it constantly, so make it obvious.
Use client-environment: lowercase, dashes, no spaces. Claude uses the same nickname to work out which org you mean, so a clear name saves you from deploying to the wrong place.
acme-dev,acme-uat,acme-partialfor a client’s sandboxesacme-prodfor their production org, which gets its own lecture in Step 3my-dev-orgfor your own Developer Edition playground
Future you, at 4:45 on a Friday, will be grateful there is no org called sandbox2-new-FINAL.
Log in with the right address.
One command. The only part that changes from org to org is the login address you give it.
Open Terminal or Command Prompt. It doesn’t matter which folder you are in, because the CLI saves logins for your whole computer. Pick the address for the kind of org you are adding:
| Adding a | Use this --instance-url |
|---|---|
| Sandbox | https://test.salesforce.com |
| Production or Developer Edition org | https://login.salesforce.com |
| Org with single sign-on or a custom login page | That org’s My Domain address, such as https://acme--uat.sandbox.my.salesforce.com |
Adding Acme’s UAT sandbox looks like this, on either computer:
sf org login web --alias acme-uat --instance-url https://test.salesforce.com
- A browser window opens on the Salesforce login page. Log in with that org’s username. Sandbox usernames usually end in the sandbox name, like
you@acme.com.uat. - Click Allow when Salesforce asks to grant access.
- Go back to the terminal and wait for the success message.
What you should see: Successfully authorized you@acme.com.uat with org ID 00D…
The most common mistake here is logging in to the wrong org, and it usually isn’t your fault. The browser happily reuses whatever Salesforce session it already has open. Log out of Salesforce in that browser (or use a private window) and run the command again with the same alias. The new login replaces the wrong one.
Check that it is really there.
Two commands: one to see the list, one to open the org and confirm it is the one you meant.
sf org list
Your new alias should be in the table next to its username. To be extra sure, open it straight from the CLI:
sf org open --target-org acme-uat
If Setup opens in the org you expected, you are done.
The production lecture
You can log the CLI in to production, and sometimes you need to. Once you do, every command that names acme-prod runs for real, in the client’s live org, with no undo button. End the nickname in -prod so it jumps out of sf org list, double-check the org name before you run anything that changes something, and only log in to production when you actually need it. Build in the sandbox, test in the sandbox, deploy like a grown-up.
The cleanup you will need eventually.
Sandboxes get refreshed, nicknames turn out badly, and engagements end. Each one is a single command.
The sandbox got refreshed and now nothing works?
A refreshed sandbox is technically a brand-new org with a new org ID, so your old login stops working. Run the same login command from Step 2 again, with the same alias. Everything that used that nickname works again, and you don’t have to change anything else.
You named something badly?
Point a new alias at the same username, then delete the old one. The username is in the sf org list table.
sf alias set acme-uat=you@acme.com.uat
sf alias unset sandbox2-new-FINAL
Tired of typing --target-org?
Set a default org for one client’s project folder (a folder made with sf project generate). Go to that folder first, and the default only applies there.
Mac (Terminal):
cd ~/salesforce-cli-projects/acme
sf config set target-org=acme-dev
Windows (Command Prompt):
cd %USERPROFILE%\salesforce-cli-projects\acme
sf config set target-org=acme-dev
I would still name the org in every request to Claude. “Deploy to acme-uat” is a lot harder to misread than “deploy it.”
The engagement ended? Log out of the org.
Run sf org logout with the org’s nickname:
sf org logout --target-org acme-uat
The CLI asks if you are sure, and the answer defaults to No, so type y and press Return. Clean offboarding is a love language.

Run sf org list afterwards to check the nickname is gone. To log out of every org at once, use sf org logout --all.
Every command on one screen.
Swap in your own nickname and username. These are the same on a Mac and on Windows.
| I want to | Command |
|---|---|
| Add a sandbox | sf org login web --alias client-env --instance-url https://test.salesforce.com |
| Add production or a Developer Edition org | sf org login web --alias client-prod --instance-url https://login.salesforce.com |
| See every org I’ve added | sf org list |
| Open an org in the browser | sf org open --target-org client-env |
| Rename an alias | sf alias set new-name=username, then sf alias unset old-name |
| Set a default org for a folder | sf config set target-org=client-env (run it inside the project folder) |
| Remove an org | sf org logout --target-org client-env |
| Remove every org | sf org logout --all |
The things that go wrong, and the fixes.
It logged me in to the wrong org
command not found: sf, or ‘sf’ is not recognized
Windows says running scripts is disabled on this system
cmd) and run the same command.No browser window opened
--instance-url for that kind of org, or the org’s own My Domain address if it uses single sign-on.The terminal just sits there after I log in
sf org list. If the nickname is there, the login worked. If it isn’t, run the login command again.A command says it can’t find my org
sf org list exactly, dashes and all. If it does match, the login has probably expired, often because the sandbox was refreshed. Run the login command again with the same alias.Using the Salesforce-hosted connector in Claude instead of the CLI? That is a different setup with its own steps: connecting multiple orgs through the Claude Salesforce connector.
Bookmark the cheat sheet.
You will add an org maybe twice a year, which is exactly often enough to forget the command every time.
Know someone who just got handed a second sandbox?
Share on LinkedIn