Files
coder/docs/reference/cli/tokens/create.md
T
Nick Vigilante 32e1f2502f feat: add JSON output to coder tokens create (#30135)
Uses the `cliui` output helpers from #30508.

`coder tokens create` printed only the new token's secret, so scripts
had to call `tokens view` afterwards to get the token's ID, expiry, and
scopes.

This adds `-o/--output` with `text` (default) and `json`.
The JSON document contains the token's metadata from `APIKeyByID` plus
the one-time `key`.

**Behavior change:** Additive.
The default output is still just the secret, so `$(coder tokens create
...)` keeps working.
The command now makes one extra API call after creating the token; if it
fails, the command prints a warning to stderr and still outputs the
secret rather than exiting with an error.

<details>
<summary>Decisions</summary>

- The metadata lookup uses the key ID parsed from the `<id>-<secret>`
token, the same convention `tokens view` and `tokens remove` use.
- A failed metadata lookup never fails the command, because the token
already exists and the secret can't be shown again.

</details>

Closes [CLI-14](https://linear.app/codercom/issue/CLI-14)

_This PR was generated by Coder Agents on behalf of @nickvigilante._
2026-11-13 12:45:32 -05:00

1.7 KiB
Generated

title, description
title description
`coder tokens create` Create a token.

Create a token

Usage

coder tokens create [flags]

Options

--lifetime

Property Value
Type string
Environment $CODER_TOKEN_LIFETIME

Duration for the token lifetime. Supports standard Go duration units (ns, us, ms, s, m, h) plus d (days) and y (years). Examples: 8h, 30d, 1y, 1d12h30m.

-n, --name

Property Value
Type string
Environment $CODER_TOKEN_NAME

Specify a human-readable name.

-u, --user

Property Value
Type string
Environment $CODER_TOKEN_USER

Specify the user to create the token for (Only works if logged in user is admin).

--scope

Property Value
Type string-array

Repeatable scope to attach to the token (e.g. workspace:read).

--allow

Property Value
Type allow-list

Repeatable allow-list entry (<type>:<uuid>, e.g. workspace:1234-...).

-o, --output

Property Value
Type text|json
Default text

Output format.