I think my access token for my scratch org expired. I'm using sfdx in visual studio code. What's the easiest way to get/fresh my access token?

7 Answers 7


If reauthorizing doesn't help for some reasons(as I was facing) try deleting the alias as follows. It should definitely work

Step 1. Go to /home/.sfdx (In windows c:\user\.sfdx)

Step 2. Delete org specific json file(ORG_USERNAME.json).

Step 3. Edit alias.json file and remove the alias.

Step 4. Restart VS Code and reauthorize.

  • I was facing same issue. sfdx force:org:list had expired token, sfdx force:auth:web:login refreshed it, but couldn't log in. This clear then sfdx force:auth:web:login worked well for me. Commented Sep 1, 2021 at 15:35

The easiest way to refresh the access token is just to open the scratch org via Salesforce DX.

From the command palette, you can do > SFDX: Open Default Org. Or, from the integrated terminal, do

sfdx force:org:open

optionally with -u my_scratch_alias to select a specific org.

Once you do so, any other functionality you might use that depends on getting an access token via SFDX should work again, provide the scratch org is not expired.

  • 2
    This is what i am trying to do when i get the error
    – Ben Arnao
    Commented Mar 25, 2019 at 15:20
  • 1
    Are you certain that the scratch org is not expired? Could you show in your question the output of sfdx force:org:list?
    – David Reed
    Commented Mar 25, 2019 at 15:22
  • I guess it did expire.. thanks
    – Ben Arnao
    Commented Mar 25, 2019 at 15:25
  • What about CI / CLI tools?
    – Edmondo
    Commented Apr 10, 2019 at 8:26
  • This is happening every other day to me now. The org does not appear in force:org:list anymore, nor does org:open help. When I do a force:org:delete this command works - but I cannot access the scratch org anymore :( (Also tried manual login) Commented Apr 3, 2020 at 5:34

These steps in Visual Studio Code will fix the issue,

Step1: In the command palette SFDX: Authorize an Org

Step2: Enter alias name (example: lwc_sandbox)

Step3: Login into your Org from the default browser

Authorization Success and Token expired issue will be fixed.


Again log in using force:auth:web:login:

sfdx force:auth:web:login -d -a <alias> -r [<https://test.salesforce.com>,<https://login.salesforce.com>]
  • -d will set the authenticated org as the default Dev Hub org.
  • -a sets the alias for the authenticated org (e.g. "qa", "uat", "dev")
  • -r or --instanceurl is the URL you want to authenticate with.

Today I was facing the same issue and I am using vscode on Ubuntu 20. I don't know if it's a bug on vscode or what, but what I did was re-authenticate (SFDX: Authorize and Org) then closed the app and opened again and now it's working. Because I was re-authenticating and not closing the app it wasn't working and I kept re-authenticating a couple more times until I decided to close the app and open again. I hope it helps!

  • please read my latest answer, it might solve your problem Commented Jan 11, 2022 at 12:59
  • Restarting VS Code on Windows also solved my problems. Commented Jan 12, 2022 at 10:57


It is because you might have Authorized the same org twice or more with the same username and alias,

VS Code is a static entity that picks auth info from your folder: c:\user\.sfdx, and it will try to re-auth from old info (if it founds multiple)

that's why it is giving the auth error every time or sometimes (behavior is irregular).


please resolve all duplicates from your folder "c:\user\.sfdx" and they try again. it will work definitely.

PS: Files need to modify

  1. alias - remove all multiple aliases if any
  2. remove all username.json files from this folder
  3. Try to re-authenticate org

Enjoy :)


This solution works every time.

  1. Run SFDX:Authorize an Org. Use the same Alias as you did when you initially setup the org.
  2. Restart VsCode

Your deploy/retrieve will now succeed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .