awesome cli.

Work & messaging

Salesforce CLI for coding agents

Orgs, metadata, scratch environments, deploy validation, and JSON output.

Command: sf

Open the official project ↗

This article follows the official documentation. We haven’t tested this tool for a hands-on review.

When a coding agent can run shell commands in a Salesforce project, it can use Salesforce CLI to inspect local files and work with Salesforce orgs. An org is a Salesforce environment, such as a sandbox or production instance. CLI commands can read org information, validate metadata deployments, and make changes in an org, depending on which command the agent runs.

Use the CLI when you want an agent to handle a specific Salesforce task with documented commands. For example, the agent can list orgs a developer has already signed in to or check a metadata deployment before it goes live. Salesforce’s Agentforce development tools also use CLI commands, and Salesforce documents ways to use the CLI with other coding tools such as Cursor and Claude Code. Keep authentication outside the agent’s prompt, and make clear which commands are allowed to contact or change an org.

Install and authenticate

Install Salesforce CLI using one method from Salesforce’s installation instructions. For an npm installation, run:

npm install --global @salesforce/cli
sf --version

The first command installs the sf executable for all users; the second prints the installed version. On macOS, avoid installing the CLI through both an installer and npm, because multiple installations can make the shell run an unexpected copy.

Before an agent uses an org, authenticate from a browser-based terminal session:

sf org login web --alias <org-alias> --instance-url https://login.salesforce.com

Replace <org-alias> with a short local name for the org. The command opens a browser so the user can sign in. For a sandbox, use the login URL appropriate to that environment. Salesforce CLI stores the resulting authentication locally, so the agent does not need a password or access token in its prompt. Anyone or any process with access to the same CLI configuration can use that authentication. Give the agent only the shell and org access it needs for its task. The Salesforce CLI reference documents command topics and options.

Check available orgs

A useful first task is to ask the agent to report which orgs Salesforce CLI already knows about. This command reads the CLI’s local org list and prints JSON, a structured format an agent can parse:

sf org list --json

The command does not deploy metadata. Its output describes the locally configured orgs; it does not establish that each org is currently reachable or that the authenticated user has permission to perform a particular Salesforce action. Ask the agent to report the aliases and status information it finds, and have a person choose the target org before any write command.

A narrow prompt for this task could be:

Run sf org list --json. Summarize the available org aliases and reported statuses. Do not run login, deploy, or other commands that change an org.

Salesforce CLI also supports JSON output for commands that provide it. Use the documented --json option on the specific command rather than assuming every command returns the same fields.

Validate metadata before deploying

When an agent prepares Salesforce metadata for deployment, run Salesforce’s validation command before a separate deploy command. Validation checks a local project manifest against the target org and returns a validation job. It does not deploy the metadata.

sf project deploy validate \
  --target-org <org-alias> \
  --manifest <manifest-path> \
  --json

Replace <org-alias> with the alias created during authentication and <manifest-path> with the path to a manifest in the local project. A manifest lists the metadata components to include. The command contacts Salesforce and creates a server-side validation job, so it is not a local-only check. Review the JSON result and any reported errors before choosing what to do next.

A successful validation does not itself deploy the changes. The separate sf project deploy quick command uses the validation job ID to perform the deployment. That command changes the org, so run it only after a person approves the target org and the validated changes. Salesforce groups development commands under headings called topics, such as project. Check the Salesforce CLI command reference for the installed command’s options.

Add Salesforce-specific instructions

The CLI supplies commands, but the agent still needs task instructions that explain which Salesforce files and conventions matter. Salesforce describes Agentforce skills as folders containing instructions, scripts, and resources. Its Agentforce DX setup documentation covers the Salesforce tools and skills for building, modifying, debugging, and deploying agents, including use with third-party coding tools.

For Agentforce work, Salesforce CLI includes commands under the agent topic. The agent preview command lets a developer interact with an active agent for testing, as described in Agentforce’s getting-started documentation. When you preview an agent, you interact with an active Salesforce agent rather than inspect local files.

Tool details come from awesome-ai-cli.