Skip to content

harn fetch

harn fetch [options] <url>

An HTTP request that writes the response body to stdout and speaks to the shared cookie jar. By default it attaches any matching cookies from ~/.cache/harnery/cookies.json to the request and persists Set-Cookie responses back (the same jar harn browse and harn cookies use). So cookies established during a harn browse --login session flow naturally into later harn fetch calls, and vice versa. Hosts that compose Harnery can also inject cookies through HarneryProgramContext.extraCookies (applied before the Cookie header is built; skipped with --no-cookies). Pipe it into harn read for the canonical scrape-to-markdown flow: harn fetch <url> | harn read -.

Flag Description
-X, --method <method> HTTP method. Default GET.
-H, --header <header...> Extra request header, format Name: value. Repeatable.
-d, --data <body> Request body.
-o, --output <file> Write the response body to a file instead of stdout.
--store <path> Cookie store path. Default ~/.cache/harnery/cookies.json.
--no-cookies Skip cookie-jar attach and persist (clean session). Also skips a host extraCookies hook.
--redirect <mode> Redirect handling: follow | error | manual. Default follow.
--timeout <ms> Request timeout in milliseconds. Default 30000.
--status Print the status line to stderr.
--headers Print response headers to stderr.
--json Output the full FetchResult (status, headers, body) as JSON.

The body goes to stdout by default. With --output, Harnery writes the HTTP representation bytes exactly as received, before content decoding, regardless of the file extension or Content-Type. Byte-mode requests ask the server for identity encoding and do not automatically decompress a response that still carries Content-Encoding, so --headers continues to describe the saved file. The Bun runtime supports this directly. The Node fallback fails instead of saving altered bytes if a server ignores the identity request and returns content-encoded data. Stdout and --json decode the body as UTF-8 text, so use --output for binary files and text in another encoding. --json emits the whole FetchResult ({ status, statusText, url, headers, body, cookiesSaved }) as a single JSON object. When cookies are saved back to the jar, a note is logged to stderr.

Terminal window
# GET a page (cookies auto-attached and persisted)
harn fetch https://example.com
# The canonical scrape-to-markdown pipeline
harn fetch https://example.com | harn read -
# POST JSON with explicit headers
harn fetch https://example.com/api -X POST -H 'Content-Type: application/json' -d '{"k":"v"}'
# Capture cookies set on intermediate redirects (follow swallows them)
harn fetch https://example.com/login --redirect manual --headers
# Clean session, full result as JSON
harn fetch https://example.com --no-cookies --json
# Save a binary response to a file
harn fetch https://example.com/image.png -o /path/to/image.png