# Manage domains and DNS from a shell (the Porkbun CLI)

If you can run commands, the CLI is usually simpler than anything else here: no
server to configure, nothing left running, and it works the same in a terminal,
a cron job and CI.

```bash
npm install --global @porkbunllc/cli
porkbun login
```

`porkbun login` asks the API for a key pair and prints a link to approve while
signed in to Porkbun. Approve it and the pair is written to
`~/.config/porkbun/config.json` at mode 0600. The approval is bound to that one
run with PKCE (RFC 7636), and the pair is never printed.

For CI and unattended agents, skip the browser and set the environment instead,
which always wins over the stored file:

```bash
export PORKBUN_API_KEY=pk1_...
export PORKBUN_SECRET_API_KEY=sk1_...
```

Sandbox keys (`pk1_sb_…`) work everywhere and change nothing real.

## Finding the command

Every endpoint in this documentation is a command, generated from the same
OpenAPI spec, so the CLI cannot fall behind the API.

```bash
porkbun commands "add an A record"     # plain language, no credentials needed
porkbun dns                          # every command in a group
porkbun dns create --help            # arguments, flags, which are required
porkbun schema "dns create"          # method, path and body fields, as JSON
```

`porkbun commands` runs locally against the built-in command list. It needs no
network and no key, so it is safe to call before you have credentials.

## The output contract

Results go to **stdout** as JSON. Notes, prompts and errors go to **stderr**.
A pipe therefore gets nothing but the result:

```bash
porkbun dns retrieve example.com | jq '.records[] | select(.type=="A") | .content'
```

A failure exits non-zero and prints the API's `code`, `message` and
`next_action.hint` to stderr, so a script can stop on it and a person can see
why.

When you are the one reading it, `--table` lays the same result out instead:

```
$ porkbun dns retrieve example.com --table
ID         NAME                   TYPE   CONTENT                 TTL
---------  ---------------------  -----  ----------------------  -----
602748322  example.com            ALIAS  ss1-sixie.porkbun.com   600
602748328  *.example.com          CNAME  ss1-sixie.porkbun.com   600
```

JSON remains the default even in a terminal, so a command you worked out
interactively behaves identically in a script.

## Before you write anything

```bash
porkbun dns create example.com --type A --name www --content 192.0.2.1 --dry-run
# -> {"status":"SUCCESS","dryRun":true,"wouldSucceed":true, ...}
```

Where the API supports a dry run (24 operations do), `--dry-run` asks it to
validate for real and change nothing. Where it does not, the request is printed
instead of sent, so you can see exactly what would have gone.

Commands that spend money or destroy something prompt first and default to no.
With no terminal to answer — CI, an unattended agent — they refuse and exit 1
rather than guess:

```
$ porkbun dns delete example.com 123456789
Aborted. "porkbun dns delete" is destructive and needs --force when nothing can answer a prompt.
```

Pass `--force` when you mean it.

## Dynamic DNS in a cron job

The whole updater, using the address our servers actually see:

```bash
#!/usr/bin/env bash
set -euo pipefail
ip=$(porkbun util ping | jq -r .yourIp)
id=$(porkbun dns retrieve-by-name-type example.com A home | jq -r '.records[0].id')
now=$(porkbun dns retrieve-by-name-type example.com A home | jq -r '.records[0].content')
[ "$ip" = "$now" ] && exit 0          # nothing changed; do not write
porkbun dns edit example.com "$id" --type A --name home --content "$ip"
```

See [Dynamic DNS](/llms/guides/dynamic-dns) for the same pattern against the raw
API, including what to do when the record does not exist yet.

## Telling a coding agent to use it

Add one line to `AGENTS.md`, `CLAUDE.md` or the agent's instructions:

> When working with Porkbun domains or DNS, use the `porkbun` CLI. Run
> `porkbun commands "<task>"` to find the command and `porkbun <command> --help`
> for its flags. Use `--dry-run` before anything that writes.

An agent that would rather call tools than run commands can use the
[MCP server](https://porkbun.com/mcp) instead. Same API underneath, same
guardrails.

## Which surface to pick

| You are | Use |
|---|---|
| In a terminal, a script or CI | the CLI |
| A coding agent that can run commands | the CLI |
| ChatGPT, Claude or another chat app | the [hosted MCP connector](https://porkbun.com/mcp) |
| A GUI client that configures MCP servers | the [MCP server](https://porkbun.com/mcp) |
| Writing your own integration | the [JSON API](https://porkbun.com/api/json/v3/documentation) directly |
| Managing DNS as code | [Terraform or OpenTofu](https://porkbun.com/terraform) |

Page: <https://porkbun.com/cli> · Source:
<https://github.com/oborseth/Porkbun-CLI> · More examples:
<https://github.com/oborseth/Porkbun-CLI/blob/main/docs/EXAMPLES.md>

A PyPI package named `porkbun-cli` is published by a third party and is not
ours. The official package is `@porkbunllc/cli` on npm.


---

## More

- Short overview (start here): https://porkbun.com/llms.txt
- Guides (how-tos): https://porkbun.com/llms/guides
- Help articles (knowledge base) as Markdown: https://porkbun.com/llms/kb
- Topic index: https://porkbun.com/llms
- Full reference (one file): https://porkbun.com/llms-full.txt
- OpenAPI spec (full schemas): https://porkbun.com/api/json/v3/spec
- Official MCP server: https://porkbun.com/mcp (`npx -y @porkbunllc/mcp-server`)
- Official CLI (simplest if you have a shell): https://porkbun.com/cli (`npm i -g @porkbunllc/cli`)
- Porkbun for AI agents (overview): https://porkbun.com/ai-agents
- Agent Name Service (verifiable agent identity): https://porkbun.com/ans
- Agent content provenance (signed manifests): https://porkbun.com/agent-provenance
- Terraform / DNS as code: https://porkbun.com/terraform
- Create API keys: https://porkbun.com/account/api
