Postkub CLI
Schedule posts, manage accounts, and read results from your terminal with structured JSON output.
Updated
On this page
- Install
- Quick start
- Use with AI agents
- Core commands
- Accounts, brands, and capabilities
- Posts: drafts, publishing, and scheduling
- Inbox, comments, and replies
- Insights and activity
- Request receipts
- Dry run
- Field selection
- Schema introspection
- Agent context topics
- Global flags
- Exit codes
- Configuration
- Config files and resolution order
- Environment variables
- Shell completion
- Troubleshooting
The Postkub CLI is a thin command-line client of the same REST API that every external AI agent uses. It prints structured JSON for scripts and concise summaries for humans, validates input before sending, and exits with predictable codes, so the same commands work in a terminal, in CI, and inside an AI agent.
Warning
The Postkub CLI is in preview and is not yet installable from npm. This page describes the planned public interface of the postkub command; commands and flags may still change before the first release.
Install
The CLI runs on Node.js 22.18 or newer and needs nothing else — no database, no background process. It talks to your Postkub API base URL over HTTPS with a scoped API key.
When the release passes testing and is published, the versioned install command for the verified package name will be added in this paragraph. Until then the CLI cannot be installed from npm — do not install any unverified registry package that claims to be Postkub.
Quick start
Configure once, verify, then inspect what your key is allowed to do:
postkub init
postkub doctor
postkub whoami --output json
postkub brands list
postkub accounts list
postkub init asks for your API URL and API key in an interactive terminal. The key prompt is masked, the key is verified against the API before anything is saved, and the configuration is written to your user directory (mode 600, outside any repository). Create or reuse a key in the dashboard under Settings → API keys; keys look like pk_<env>_<secret>. Never pass a key as a command argument.
postkub doctor checks your Node version, configuration, key format, API connectivity, and granted scope. It prints failing checks by default and everything with --verbose. It never creates test posts.
postkub whoami shows the authenticated principal, workspace, Brand IDs, account IDs, and granted actions. It works even for action-only keys that cannot list Brands or accounts — use the target IDs you already know.
Use with AI agents
The CLI carries an agent-readable context bundle and can install a short guide into coding agents:
postkub context
postkub context --list
postkub context idempotency-and-recovery
postkub install claude
postkub install codex --global --dry-run
postkub uninstall codex
postkub contextprints all guidance topics as markdown;--listprints the catalog;context TOPICprints one topic. With--output jsonthe same content is returned as JSON for an agent to ingest.postkub install claude|codexwrites a project-local guide by default (.claude/skills/postkub/SKILL.mdfor Claude, a managed block in the projectAGENTS.mdfor Codex). Add--globalto target the user-level file instead.--dry-runpreviews the change without writing.postkub uninstall claude|codexremoves only the Postkub-managed content and leaves the rest of the file untouched.- Guides contain no API key, require no authentication, and never register or host an agent.
Core commands
Accounts, brands, and capabilities
postkub brands list --output json
postkub accounts list --brand-id BRAND_ID
postkub capabilities get --account-id ACCOUNT_ID
postkub accounts schedule get --account-id ACCOUNT_ID
postkub accounts schedule update --account-id ACCOUNT_ID --expected-revision 3 --slot mon:09:00 --slot thu:18:00
postkub accounts schedule update --account-id ACCOUNT_ID --expected-revision 4 --timezone Asia/Bangkok
capabilities get shows which actions Postkub will accept for that account right now, with reasons for anything unavailable. accounts schedule update accepts repeatable --slot WEEKDAY:HH:MM flags (weekday as 1–7 or mon–sun) or --clear-slots, plus --timezone with an IANA name. Both schedule-settings commands are revision-guarded with --expected-revision.
Posts: drafts, publishing, and scheduling
Create a draft with flags or a JSON document, then publish or schedule it as a separate step:
postkub posts create --brand-id BRAND_ID --account-id ACCOUNT_ID --text "Hello world" --output json
postkub posts create --brand-id BRAND_ID --account-id ACCOUNT_ID --text "Launch day" \
--media-url https://cdn.example.com/hero.jpg --output json
cat post.json | postkub posts create --input - --output json
postkub posts get --id POST_ID --fields id,status
postkub posts list --status scheduled --from 2026-12-01T00:00:00Z --to 2026-12-31T23:59:59Z
postkub posts update --id POST_ID --expected-revision 2 --text "Updated copy"
postkub posts publish --id POST_ID --expected-revision 2 --wait
postkub posts schedule --id POST_ID --expected-revision 2 --next-slot
postkub posts cancel --id POST_ID --expected-revision 2 --account-id ACCOUNT_ID
postkub posts delete --id POST_ID --expected-revision 2
Structured mutations accept --input FILE, --input - (stdin), or inline --json '{...}' — exactly one of the three. Per-field flags such as --text, repeatable --account-id, and repeatable --media-url can complete a document but never silently override a field the document already supplies. --media-kind must be image or video; a video post requires exactly one media item and is never inferred from a file extension. Media is attached as hosted HTTPS URLs — the CLI never uploads local files.
posts publish, posts cancel, posts retry, and posts cover-retry take the post --id, an --expected-revision, and an optional subset of targets via repeatable --account-id. posts publish also accepts --replace-existing to replace known-unstarted work for the selected accounts.
posts schedule --next-slot reserves the earliest unoccupied weekly queue slot for each selected account; the response records the actual fireAtUtc per target. For explicit times, pass a document with per-target localTime, timezone, and fireAtUtc:
{
"expectedRevision": 2,
"targets": [
{
"socialAccountId": "acc_2gf8xh",
"localTime": "09:00",
"timezone": "Asia/Bangkok",
"fireAtUtc": "2026-12-10T02:00:00Z"
}
]
}
A 202 response means Postkub accepted the intent — not that a social network finished the work. Add --wait to keep the process attached and poll until the work settles (default deadline 120 seconds, exit code 6 if the deadline passes). Details: scheduling, idempotency.
Inbox, comments, and replies
postkub inbox list --account-id ACCOUNT_ID --post-target-id none
postkub threads get --id THREAD_ID
postkub threads update --id THREAD_ID --expected-revision 1 --unread false
postkub threads resolve --id THREAD_ID --expected-revision 1
postkub comments list --thread-id THREAD_ID --unread true
postkub comments reply --id COMMENT_ID --text "Thanks for the feedback!" --wait
postkub replies get --id REPLY_ID
inbox list is an alias for threads list; --post-target-id none selects threads not linked to any of your posts. threads update changes --handled and/or --unread; threads resolve is the alias that marks a thread handled. Replies are durable operations: the accepted response carries a reply ID and request ID, and replies get shows execution status and attempt history.
Insights and activity
postkub insights account --account-id ACCOUNT_ID
postkub insights account --account-id ACCOUNT_ID \
--range-start-utc 2026-11-01T00:00:00Z --range-end-utc 2026-11-30T00:00:00Z
postkub insights post --id POST_ID
postkub activity list --brand-id BRAND_ID --from 2026-11-01T00:00:00Z --to 2026-11-30T00:00:00Z
Insights return saved snapshots with freshness and explicit per-metric unavailable reasons; the optional range spans at most 90 days, and account insights default to the last 30 days. insights posts is an alias for insights post. Activity shows who did what across your scoped targets, with sanitized failures. Both require insight:read / activity:read on the key.
Request receipts
postkub requests get --id 6aab001e-680c-4b73-8a71-e6a6756d7125
Every mutation sends an Idempotency-Key UUID. The CLI announces it on stderr before sending and records the last one locally, so an interrupted run can be recovered. After any uncertain response, look the request up before acting again — reuse the same key and identical intent, never a new key. Details: idempotency, errors.
Dry run
Every mutation (and the insights reads) accepts --dry-run: the CLI validates the payload locally against the accepted request schema and prints the request it would send. Nothing is transmitted, nothing is persisted, and no media is fetched.
postkub posts create --brand-id BRAND_ID --account-id ACCOUNT_ID --text "Hello" --dry-run
{
"dryRun": true,
"note": "local validation and preview only — nothing was sent, no request was persisted",
"operation": "posts create",
"request": {
"method": "POST",
"path": "/v1/posts",
"body": {
"brandId": "brd_9x2k",
"text": "Hello",
"socialAccountIds": ["acc_2gf8xh"]
}
}
}
A successful dry run is not a server-side authorization or provider-acceptance guarantee; it only proves the payload shape.
Field selection
Read commands project their JSON response with --fields, keeping agent context small. Paths are comma-separated dot paths; braces expand into multiple paths; all returns the full payload. Unknown paths are a usage error (exit code 2).
postkub posts list --fields 'items.{id,status}'
postkub posts get --id POST_ID --fields id,status
postkub brands list --fields all
Schema introspection
postkub schema list
postkub schema describe posts create
schema list prints every accepted operation with its HTTP method, path, required action, idempotency flag, and CLI flags — locally, with no API call. schema describe OPERATION fetches that operation's request and response schema from the server's OpenAPI document, so the CLI never shows a hand-maintained copy. It needs a configured API.
Agent context topics
postkub context --list catalogs the built-in guidance topics; each is also a valid postkub context TOPIC argument:
| Topic | Summary |
|---|---|
| auth-and-scope | Configure scoped keys and inspect the principal's granted targets and actions. |
| media-upload | Attach public HTTPS media URLs to drafts; human uploads stay in the web UI. |
| publish-and-schedule | Create or edit drafts first, then publish or schedule with an explicit revision. |
| queue-slots | Reserve the earliest unoccupied weekly schedule slot per target account. |
| timezones | Send timestamps with explicit timezone context; Postkub stores UTC and honors DST. |
| idempotency-and-recovery | Keep each mutation request ID and reuse it to recover uncertain outcomes safely. |
| errors-and-exits | Use normalized errors and exit codes to distinguish usage, authorization, rejection, and uncertainty. |
| rate-limits | Honor Postkub admission headroom and provider retry instructions. |
| comments | Read inbox threads and comments, then reply through durable, authorized operations. |
| insights | Read saved account and post metrics with freshness and explicit unavailable reasons. |
| activity | Read scoped social activity and sanitized failures. |
Global flags
These flags work on every command:
| Flag | Type | Description |
|---|---|---|
--output | value | auto (default), pretty, human, or json. auto prints human-readable summaries on a terminal and JSON when piped. |
--timeout | value | Per-request deadline in seconds, 1–900. Default 30. |
--wait | optional value | After a 202 acceptance, poll until the work settles. Bare --wait means 120 seconds; exit code 6 when the deadline passes. |
--fields | value | Project a read response (see field selection); all for the full payload. |
--input | value | Read mutation input from a file, or - for stdin. |
--json | value | Inline structured mutation input as a JSON string. |
--idempotency-key | value | Supply the mutation's idempotency UUID explicitly; generated when omitted. |
--dry-run | boolean | Validate locally and preview the request; send nothing. |
--expected-revision | value | Optimistic-concurrency guard for updates, deletes, and lifecycle actions. |
--cursor | value | Pagination cursor from a previous page. |
--limit | value | Page size, 1–100. |
--quiet | boolean | Suppress informational stderr lines. |
--verbose | boolean | Print the rate-limit response headers on stderr. |
--no-color | boolean | Disable ANSI colors. |
Results go to stdout; every diagnostic (request IDs, pagination hints, progress, rate-limit notes) goes to stderr, so JSON stdout stays machine-pure. When stdout is closed early (for example | head), the CLI exits 0 without an error trace.
Exit codes
| Code | Meaning |
|---|---|
| 0 | Accepted or completed as labelled. |
| 1 | Unexpected client error (a defect or an environment failure, not a usage mistake). |
| 2 | Usage or schema error — bad flag, bad JSON, unknown field path. |
| 3 | Authentication or authorization — missing/invalid key or a scope the key lacks. |
| 4 | API rejection — the server refused the request (4xx other than auth). |
| 5 | Transport failure or uncertain response — the outcome is unknown; recover the request ID first. |
| 6 | --wait deadline exceeded — the operation remains accepted and pending. |
| 130 | Interrupted by SIGINT (Ctrl-C). |
| 143 | Terminated by SIGTERM. |
When a mutation was already sent, interruption on SIGINT/SIGTERM prints the request ID on stderr so the outcome stays recoverable. See errors for the JSON error envelope shared by API and CLI failures.
Configuration
Config files and resolution order
- Global config:
~/.postkub/cli.json(override the path withPOSTKUB_CONFIG_FILE). Written with restrictive permissions, and the only file that may holdapiUrlandapiKey.postkub initwrites it;postkub config set apiKeyis refused — keys enter throughinitor the environment only. - Repo config:
.postkub/config.json, found by walking up from the current directory. It may set only non-secret defaults:defaultBrandId,defaultAccountId,output,timeout. If someone commitsapiKeyorapiUrlto a repo config, the CLI strips the values with a warning, so a cloned repository cannot redirect your key to another server.
Resolution order: command flag → environment → repo config → global config → built-in default. Defaults fill read/list filters only (for example, accounts list uses defaultBrandId when --brand-id is omitted); mutations still require explicit target IDs.
Inspect and edit configuration with:
postkub config path
postkub config get --all
postkub config get apiKey
postkub config set output json
postkub config set defaultBrandId brd_9x2k --repo
postkub config unset defaultBrandId --repo
config get apiKey prints a masked value; the secret is never echoed.
Environment variables
| Variable | Purpose |
|---|---|
POSTKUB_API_URL | API base URL. Overrides the saved value. HTTPS is enforced for any non-loopback host; plain HTTP is allowed only for local development such as http://localhost:4000. |
POSTKUB_API_KEY | Scoped API key. Overrides the saved value. |
POSTKUB_CONFIG_FILE | Alternative global config path. |
POSTKUB_CLI_PACKAGE | Opts in to the CLI update check that doctor performs; without it the check degrades to a warning. |
Shell completion
postkub completion bash
postkub completion zsh --install
postkub completion fish --install
Without --install the script prints to stdout. With --install the CLI writes an idempotent managed block into ~/.bashrc or ~/.zshrc, or the completions file ~/.config/fish/completions/postkub.fish, and reports the path. Re-run any time to update the block.
Troubleshooting
Run postkub doctor first — it names the failing check. Common patterns:
- No API URL/key configured (exit 3). Set
POSTKUB_API_URLandPOSTKUB_API_KEY, or runpostkub init. - Key rejected (exit 3). The key must match
pk_<env>_<secret>and hold the scope the command needs.postkub whoami --output jsonlists the granted actions. - Usage error (exit 2). The stderr line names the bad flag, value, or field path.
postkub schema describe OPERATIONshows the accepted request schema. - API rejection (exit 4). The server returned a normalized error; see errors for the envelope and code catalog. Rate-limit headers appear with
--verbose; see rate limits. - Uncertain response (exit 5). The outcome is unknown. Look the request up with
postkub requests get --id REQUEST_IDand replay only with the same idempotency key and identical intent. - Wait deadline (exit 6). The operation is still accepted and pending. Poll
posts getorreplies get, or check the activity feed, before deciding anything. - Interrupted after sending. The CLI prints the request ID on exit and keeps the last one in
~/.postkub/last-request.json, so a killed process still leaves a recovery trail.
