Authentication profiles
Wrangler authenticates as one user at a time. A profile is a named OAuth login that you scope to a chosen set of accounts can bind to a directory.
Use profiles to switch between accounts for different projects without re-running wrangler login. Profiles live under wrangler auth.
Use profiles when you work across more than one Cloudflare account on the same machine:
- Agency and client work — keep a separate login for each client account and bind it to that client's project directory. Commands run in each directory use the matching profile automatically.
- Account-separated environments — keep staging and production in different accounts, then bind a profile to each. Pair a profile with an
account_idin your Wrangler configuration file so a command cannot reach the wrong account.
A profile combines two things:
- A login, created through OAuth. During the OAuth flow you choose which accounts the profile may reach. One profile can hold access to several accounts that your user holds.
- A directory binding. When you activate a profile in a directory, that directory and its subdirectories use the profile.
For each command, Wrangler selects a profile in this order, highest priority first:
- The
CLOUDFLARE_API_TOKENenvironment variable. When set, it overrides all profiles. - The
--profileflag, which applies to a single command run. - The nearest activated ancestor directory. Wrangler resolves from the directory containing the configuration file when you pass
--config, otherwise from the working directory. - The default profile, managed by
wrangler loginandwrangler logout.
Within the resolved profile, Wrangler selects the target account in this order:
- The
account_idin your Wrangler configuration file, or theCLOUDFLARE_ACCOUNT_IDenvironment variable. - Otherwise, the account selected for the profile during login.
If a command targets an account that the active profile cannot reach, Wrangler fails with an error that names the account and profile. Wrangler does not fall back to another account.
Run wrangler auth create with a name. Wrangler starts the OAuth flow, where you choose which accounts the profile may reach.
wrangler auth create workRun the command again with the same name to re-authenticate an existing profile, for example after its token expires.
Run wrangler auth activate to bind a profile to a directory. The binding applies to that directory and its subdirectories. The directory defaults to the current working directory.
wrangler auth activate work ~/projects/workA subdirectory can override the profile bound above it by activating a different profile.
This example sets up one profile per client for agency work.
-
Create a profile for the first client. During the OAuth flow, choose the accounts this profile may reach.
Terminal window wrangler auth create client-a -
Bind the profile to the client's project directory.
Terminal window wrangler auth activate client-a ~/clients/client-a -
Repeat for the second client.
Terminal window wrangler auth create client-bwrangler auth activate client-b ~/clients/client-b
Commands run in ~/clients/client-a now use the client-a profile, and commands in ~/clients/client-b use the client-b profile. You do not need to log in again to switch between them.
When staging and production live in different accounts, bind a profile to each environment's directory and pin the account in each project's configuration. The account_id acts as a failsafe, so a command cannot deploy to the wrong account even if the profile can reach both.
-
Create and activate a profile for each environment.
Terminal window wrangler auth create stagingwrangler auth activate staging ~/projects/stagingwrangler auth create productionwrangler auth activate production ~/projects/production -
Set the matching
account_idin each project's Wrangler configuration file.JSONC {"$schema": "./node_modules/wrangler/config-schema.json","name": "my-worker","account_id": "<PRODUCTION_ACCOUNT_ID>"}TOML name = "my-worker"account_id = "<PRODUCTION_ACCOUNT_ID>"
Use the --profile flag to run one command with a specific profile, without changing any directory binding.
wrangler deploy --profile stagingThe --profile flag is not supported by the auth, login, logout, and whoami commands.
Run wrangler auth list to see every profile and the directories bound to it.
wrangler auth listTo stop a directory from using a profile, run wrangler auth deactivate in that directory. The directory returns to the profile bound above it, or to the default profile.
wrangler auth deactivate ~/projects/stagingTo remove a profile and all of its directory bindings, run wrangler auth delete.
wrangler auth delete stagingProfiles are a local-machine convenience. They do not apply in CI, containers, or other automated environments, which authenticate per environment with CLOUDFLARE_API_TOKEN. For more information, refer to Running Wrangler in CI/CD.
Two rules apply when environment variables are present:
- When
CLOUDFLARE_API_TOKENis set, Wrangler uses it instead of any profile. You cannot create, activate, deactivate, or delete profiles while it is set. CLOUDFLARE_ACCOUNT_IDand anaccount_idin your Wrangler configuration file are always respected, including within an active profile.