Skip to content

Log in with the CLI

hakocms-cli calls the Hako CMS Admin API with your access token. When you log in, it creates an access token and saves it on your computer. The access token runs with the same permissions as you.

On a computer you use every day, log in this way.

  1. In a terminal, run the following command. Replace <hostname> with the hostname of your environment.

    ターミナルウィンドウ
    hakocms-cli auth login --host https://<hostname>.hakocms.net

    The terminal shows a confirmation code (8 characters, such as BCDF-GHJK) and a URL, and a browser opens.

  2. On the [CLI のログイン](CLI login) screen in the browser, check that the code matches the one in the terminal. If you are not logged in to the admin, log in first.

  3. Press [許可する](Allow).

If the terminal shows ✓ Logged in to …, you are logged in.

  • If a browser does not open (for example, on a machine you connect to over SSH), run the command with --no-browser, and open the URL it shows in a browser on your computer
  • The confirmation code expires in 10 minutes. After that, run auth login again
  • Press [許可する] only when you yourself just ran the CLI. Do not press it for a link someone else sent you. If you press it, that person can act as you
  • The access token that is created expires in 90 days. Its name is “hakocms-cli on ”

To use a token with an expiration and allowed actions you chose, log in with a token you created in the admin.

  1. In the admin, click your name in the upper right, then click [アクセストークン](Access tokens).

  2. Under [新しいトークン](New token), choose [名前](Name) (such as “仕事の Mac”), [できること](Allowed actions), and [期限](Expiration), then press [作る](Create). The token is shown only at this time.

  3. Save the token to a file (token.txt) and log in by passing it on standard input.

    ターミナルウィンドウ
    hakocms-cli auth login --host https://<hostname>.hakocms.net --with-token < token.txt
  4. After you log in, delete token.txt.

You cannot pass the token as a command argument. An argument would remain in the process list, which other people can see, and in your shell history.

With a token for which you chose [読み取りだけ](Read only) under [できること](Allowed actions), only commands that retrieve data (list, get, and so on) work.

In CI such as GitHub Actions, do not log in. Pass the destination and the token in environment variables instead. Environment variables take priority over saved logins.

Environment variable Contents
HAKOCMS_HOST URL of the destination (https://<hostname>.hakocms.net)
HAKOCMS_TOKEN Access token (starts with hako_pat_)
HAKOCMS_SPACE (Optional) Space used when --space is omitted
ターミナルウィンドウ
export HAKOCMS_HOST=https://<hostname>.hakocms.net
export HAKOCMS_TOKEN=<access token>
hakocms-cli spaces list

For <access token>, use a token you created in the admin for CI. Keep the token in CI secret variables (such as GitHub Actions secrets). Do not write it in files or workflows. Apply a schema from CI has a CI example.

If you keep CI tokens separate from tokens created for each person, you can revoke the CI token when you want to stop only CI.

You can stay logged in to several environments and switch between them. It helps to give each destination a short name with --name.

ターミナルウィンドウ
hakocms-cli auth login --host https://my-site.hakocms.net --name prod
hakocms-cli auth login --host https://my-site-test.hakocms.net --name test

Choose one with --host for each command. You can use the name or the URL.

ターミナルウィンドウ
hakocms-cli --host test entries list -t posts

Set the destination used when --host is omitted with auth switch.

ターミナルウィンドウ
hakocms-cli auth switch prod

Check where you are logged in and which one is selected with auth status.

ターミナルウィンドウ
hakocms-cli auth status
prod (https://my-site.hakocms.net) ← selected by auth switch
✓ logged in as you@example.com (token in the system keyring, expires at 2027-01-21T04:17:32.543075024Z)
test (https://my-site-test.hakocms.net)
✓ logged in as you@example.com (token in the system keyring, expires at 2027-01-21T04:20:11.208871150Z)

Items higher in the list take priority.

  1. --host on the command
  2. The environment variable HAKOCMS_HOST
  3. hakocms-cli.toml in your working folder
  4. The one set with auth switch

For hakocms-cli.toml, the CLI searches from the current folder up through its parent folders and uses the first one it finds. If you put it in your site’s repository, the destination and space written in the file are used inside that repository.

hakocms-cli.toml
host = "prod"
space = "blog"

Confirmation messages for deletions and similar operations include the destination name, so you can notice if you mix up the production environment and a test environment.

Specify the space with --space (short form -s) on each command. When you omit it, the space is chosen in the following order. If none applies, it is an error. The CLI does not pick a space on its own.

  1. The environment variable HAKOCMS_SPACE
  2. space in hakocms-cli.toml
  3. The one set with hakocms-cli spaces use <slug> (per destination)

The token from your login is stored in your OS credential store, one per destination.

OS Location
macOS Keychain
Windows Credential Manager
Linux Secret Service (such as GNOME Keyring)

When the credential store is not available (for example, on a Linux server without a desktop), the token is written to hosts.toml in the settings folder, with permissions that let only you read it. The settings folder is ~/.config/hakocms-cli/ (on Windows, %APPDATA%\hakocms-cli\). If you do not want to use the credential store, set the environment variable HAKOCMS_NO_KEYRING=1.

To pass the saved token to another tool, print it with hakocms-cli auth token.

  • When fewer than 7 days remain before expiration, every command shows a warning
  • When the token expires, commands end with exit code 4. Log in again with auth login

You can see a list of your tokens with hakocms-cli auth tokens list.

ID NAME SCOPE TOKEN PREFIX LAST USED AT EXPIRES AT
9cel006spn30 hakocms-cli on my-macbook all hako_pat_0JRFN 2026-10-23T04:18:41.856Z 2027-01-21T04:17:32.543Z

Revoke tokens you no longer use.

ターミナルウィンドウ
hakocms-cli auth tokens revoke <token ID>
ターミナルウィンドウ
hakocms-cli auth logout

auth logout revokes the token on the Hako CMS side, then deletes it from your computer as well. To log out of another destination, add --host.