knok is an HTTP command-line client that selects authentication by hostname from a YAML configuration file. It supports API keys in HTTP headers, Bearer tokens, HTTP Basic authentication, and OAuth 2.0 client credentials and browser login. OAuth access tokens are refreshed automatically. Supply credentials through standard input and save them in encrypted sessions, or use them for a single request. Configuration files contain no secrets.
Status: v0 development. The configuration and command interface may change.
Download the archive matching your operating system and CPU from the latest release. Releases include macOS, Linux, and Windows binaries for amd64 (Intel/AMD) and arm64 (including Apple Silicon).
On macOS or Linux, extract the .tar.gz archive, then run these commands from the
extracted directory:
mkdir -p "$HOME/.local/bin"
install -m 0755 knok "$HOME/.local/bin/knok"
export PATH="$HOME/.local/bin:$PATH"
knok --versionAdd that export PATH line to your shell startup file to keep it available in new
terminals. On Windows, extract the .zip and add the folder containing
knok.exe to your user Path.
See the installation guide for platform selection, download commands, checksum verification, and Windows setup.
Requires Go 1.27.4 or newer:
go install github.com/stuft2/knok/cmd/knok@latest
knok_bin="$(go env GOBIN)"
export PATH="${knok_bin:-$(go env GOPATH)/bin}:$PATH"
knok --helpGo installs to GOBIN when configured, otherwise to the bin directory under
GOPATH; make sure that directory is on your PATH. Use @main instead of
@latest to install the current development branch.
knok https://api.example.com/users
knok -X POST -H 'Content-Type: application/json' -d '{"name":"Sam"}' https://api.example.com/users
knok --location --include https://example.com
knok -d @payload.json --output response.json https://api.example.com/usersCompleted HTTP responses exit 0 by default, including 4xx and 5xx responses.
Use --fail (-f) to exit 22 when the final HTTP status is 400 or higher and
suppress the response body. Use --fail-with-body to exit 22 and keep the body
on stdout or in the file selected by --output. Choose one mode per request.
Both modes preserve --include status and headers and report failures on stderr.
Put authentication settings in ~/.config/knok/config.yaml (or
$XDG_CONFIG_HOME/knok/config.yaml):
version: 2
hosts:
api.example.com:
auth:
type: bearerPipe a token from your password manager to save an encrypted session:
op read 'op://Work/Example/token' |
knok auth login --host api.example.com --token-stdin
knok https://api.example.com/users
knok auth status --host api.example.com
knok auth logout --host api.example.comUse --secret-stdin for HTTP Basic passwords, API keys, and OAuth client secrets.
For a single request, combine --token-stdin or --secret-stdin with
--ephemeral. This mode uses credentials in memory without accessing saved
sessions or the OS keyring. Saved sessions require access to the OS keyring.
See configuration and authentication for browser login,
headless operation, and migration from configuration version 1. The
example configuration includes all authentication methods.
Use knok --help to list options and knok cache clear to remove legacy
plaintext token caches. Response bodies go to standard output, and diagnostics
go to standard error. A completed HTTP response returns exit status 0, including
4xx and 5xx responses. Runtime failures return 1; invalid arguments or
configuration return 2.
Use type: api-key and header: X-API-Key, then pipe a key into
knok auth login --host HOST --secret-stdin. See the
API-key configuration guide for examples.
Requires Go 1.27.4 or newer.
git clone git@github.com:stuft2/knok.git
cd knok
go build -o knok ./cmd/knok
./knok --helpRelease Please opens a version/changelog PR from Conventional Commits on main.
Merging that PR creates a GitHub release with binaries and checksums for macOS,
Linux, and Windows (amd64 and arm64). See release instructions.
The CLI uses Go's net/http client, parses configuration without secret values,
and stores encrypted sessions with keys in the OS keyring. It handles OAuth
authorization and token refresh. Runtime dependencies provide YAML parsing and
OS keyring integration.
Configured authentication requires HTTPS. Redirects must be enabled explicitly and are restricted to the original origin. The CLI does not use curl or libcurl, match wildcard hosts, or retry requests at the application level.
go test -race ./...
go vet ./...CI runs formatting checks, go vet, race-enabled tests, and a build on pull
requests and on main before release processing. Tests use temporary directories
and local HTTP/TLS servers; no external API credentials are required. See
development notes for the vulnerability check and dependency
review.
See the security policy for supported versions and private vulnerability reporting.
MIT © 2026 Spencer Tuft.