How do I authenticate Coder in my automation or CI/CD environments?

Last updated: June 25, 2026

Summary

Set the CODER_URL and CODER_SESSION_TOKEN environment variables before using the CLI, rather than using the coder login command to use an API token with the Coder CLI.

 

About the coder tokens create command

$ coder tokens create --help
coder v2.16.0+683a720

USAGE:
  coder tokens create [flags]

 Create a token

OPTIONS:
    --lifetime duration, $CODER_TOKEN_LIFETIME (default: 720h0m0s)
        Specify a duration for the lifetime of the token.

 -n, --name string, $CODER_TOKEN_NAME
        Specify a human-readable name.

———
Run `coder --help` for a list of global options.

 

Log in to Coder using the coder login command

To create a new API token from the CLI will require that you perform an interactive authentication. The user you login with will be the 

$ coder login
Attempting to authenticate with config URL: 'http://127.0.0.1:3000'
Your browser has been opened to visit:

http://127.0.0.1:3000/cli-auth

> Paste your token here: 
  Welcome to Coder, angrycub! You're authenticated.

 

Create a long-lived API token

Use the coder tokens create command to generate an API key from the command line.  These should be stored and transmitted securely; for example, using Kubernetes secrets or other credential sharing configurations.

 

$ coder token create --name cli-token --lifetime 24h0m0s
qJn8Ep3FGq-XtCSWWFAIhVlWzdWQ63hzQ

 

Log out of the interactive session

For the purposes of showing this process, you can use the coder logout command to destroy the session token created from the last interactive login. This leaves the current shell in an unauthenticated state. 

$ coder logout --yes
You are no longer logged in. You can log in using 'coder login '.

 

Configure the credentials in the environment

Set the CODER_SESSION_TOKEN to the API token you just generated and CODER_URL environment variable with the URL of the Coder environment.

$ export CODER_SESSION_TOKEN=qJn8Ep3FGq-XtCSWWFAIhVlWzdWQ63hzQ
$ export CODER_URL=http://127.0.0.1:3000

 

Run a command that requires authentication

To validate that the token and configuration works as expected, you can run the coder ls command to verify that the authentication from the environment variables is being picked up by Coder.

 

$ coder ls
WORKSPACE                TEMPLATE             STATUS   HEALTHY  LAST BUILT  CURRENT VERSION  OUTDATED  STARTS AT  STOPS AFTER
angrycub/pink-orca-42  coder-azure-windows  Started  false    5d19h       stoic_hertz4     true