
Switching Org
Point Salesforce CLI commands at the right sandbox, scratch org, or production alias before deploys and metadata work.
Overview
Switching-org is an agent skill for the Build phase that switches the Salesforce CLI default target-org to a named username or alias.
Install
npx skills add https://github.com/forcedotcom/sf-skills --skill switching-orgWhat is this skill?
- Sets target-org locally per project or globally when explicitly requested
- Lists authenticated orgs with sf org list when no alias is given
- Three-step flow: identify org, sf config set target-org, verify with sf config get
- Surfaces sf org login web when authorization may be missing
- Documents that verify JSON omits local vs global scope
- 3-step procedure: identify org, set target-org, verify
- Supports local (project) vs global scope for sf config set
Adoption & trust: 690 installs on skills.sh; 513 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You have several authenticated Salesforce orgs and CLI commands keep running against the wrong default.
Who is it for?
Indie Salesforce developers alternating between scratch orgs, sandboxes, and prod aliases in one laptop workspace.
Skip if: Teams that need org switching via DevOps pipelines only, with no local sf CLI on the machine.
When should I use this skill?
User wants to switch org, change default org, set org to an alias, or point CLI work at a specific scratch org, sandbox, or production.
What do I get? / Deliverables
After the skill runs, target-org is set and verified so subsequent sf commands use the org you intended.
- Confirmed target-org value after sf config get
- Clear local vs global scope choice when setting default
Recommended Skills
Journey fit
Org context is a daily prerequisite when building on Salesforce inside a repo tied to sf CLI workflows. Default target-org selection is an integration/DevOps control, not ideation or launch marketing.
How it compares
Use for explicit CLI default-org changes instead of ad-hoc guessing which alias sf is using.
Common Questions / FAQ
Who is switching-org for?
Solo and indie builders using Salesforce CLI v2+ who need a repeatable way to set which org sf commands target.
When should I use switching-org?
During Build integrations work whenever you start on a Salesforce project, after logging into a new sandbox, or before deploy and test commands that must not hit production by mistake.
Is switching-org safe to install?
It only guides sf config and org-list commands; review the Security Audits panel on this page before granting shell access in your agent.
SKILL.md
READMESKILL.md - Switching Org
## Steps 1. Identify the org: the user provides a username or alias (`orgIdentifier`). If not provided, run `sf org list` to show authenticated orgs and ask the user which one to use. 2. Set the default org: - Local (default): `sf config set target-org <orgIdentifier>` - Applies only within the current project directory. Use this for normal project work. - Global (only if user explicitly requests): `sf config set target-org <orgIdentifier> --global` - Applies system-wide across all directories. Use when working outside a project or when the user asks for global scope. - If this fails, report the error and suggest running `sf org login web` if the org may not be authorized. 3. Verify: - `sf config get target-org --json` - Note: the JSON output does not include a scope/location field — it cannot confirm whether the value is local or global. Confirm the value only, e.g.: `target-org is now set to: <value>` - If it fails, report the error and advise running `sf config get target-org`. ## Notes - Unified CLI uses keys like `target-org` and `target-dev-hub`. Legacy sfdx keys (`defaultusername`, `defaultdevhubusername`) are deprecated in this context. - The sf CLI does not have `--local` or `--scope` flags for config set. Local scope is the default behavior. - If the org does not change after setting the config, check whether `SF_TARGET_ORG` is set — environment variables override config values. - Salesforce CLI config (unified) reference: https://developer.salesforce.com/docs/atlas.en-us.sfdx_cli_reference.meta/sfdx_cli_reference/cli_reference_config_commands_unified.htm#cli_reference_config_set_unified