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.
Log in by approving in a browser
Section titled “Log in by approving in a browser”On a computer you use every day, log in this way.
-
In a terminal, run the following command. Replace
<hostname>with the hostname of your environment.ターミナルウィンドウ hakocms-cli auth login --host https://<hostname>.hakocms.netThe terminal shows a confirmation code (8 characters, such as
BCDF-GHJK) and a URL, and a browser opens. -
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.
-
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 loginagain - 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
”
Log in with a token created in the admin
Section titled “Log in with a token created in the admin”To use a token with an expiration and allowed actions you chose, log in with a token you created in the admin.
-
In the admin, click your name in the upper right, then click [アクセストークン](Access tokens).
-
Under [新しいトークン](New token), choose [名前](Name) (such as “仕事の Mac”), [できること](Allowed actions), and [期限](Expiration), then press [作る](Create). The token is shown only at this time.
-
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 -
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.
Use from CI
Section titled “Use from CI”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.netexport HAKOCMS_TOKEN=<access token>hakocms-cli spaces listFor <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.
Switch between several environments
Section titled “Switch between several environments”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 prodhakocms-cli auth login --host https://my-site-test.hakocms.net --name testChoose one with --host for each command. You can use the name or the URL.
hakocms-cli --host test entries list -t postsSet the destination used when --host is omitted with auth switch.
hakocms-cli auth switch prodCheck where you are logged in and which one is selected with auth status.
hakocms-cli auth statusprod (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)Order in which the destination is chosen
Section titled “Order in which the destination is chosen”Items higher in the list take priority.
--hoston the command- The environment variable
HAKOCMS_HOST hakocms-cli.tomlin your working folder- 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.
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.
Set a default space
Section titled “Set a default space”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.
- The environment variable
HAKOCMS_SPACE spaceinhakocms-cli.toml- The one set with
hakocms-cli spaces use <slug>(per destination)
Where the token is stored
Section titled “Where the token is stored”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.
Token expiration
Section titled “Token expiration”- 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 AT9cel006spn30 hakocms-cli on my-macbook all hako_pat_0JRFN 2026-10-23T04:18:41.856Z 2027-01-21T04:17:32.543ZRevoke tokens you no longer use.
hakocms-cli auth tokens revoke <token ID>Log out
Section titled “Log out”hakocms-cli auth logoutauth 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.