Skip to main content

Headless Python SDK

Typed sync and async interfaces for the headless command-line tool. The CLI remains the execution engine and the authority for option validation.

Requirements

  • Python 3.10 or newer
  • Node.js 22 or newer
  • A headless executable on PATH

You can select a different executable with binary=..., HEADLESS_CLI_BIN, or HEADLESS_BIN, in that order.

Usage

from headless_cli import Headless

headless = Headless()
result = headless.run(
    "codex",
    prompt="Review this repository",
    model="gpt-5",
    fast=True,
    reasoning_effort="high",
    allow="read-only",
)
print(result.final_message)

headless.sessions.send("bughunt", prompt="Continue the fix")
headless.sessions.launch("review", "codex", prompt="Review the repository")
headless.runs.message("auth", "worker-1", prompt="Fix tests", background=True)
headless.cron.pause("inbox-triage")
headless.docker.doctor()

The high-level read and run methods use Headless' versioned SDK protocol. stream() yields parsed SdkTrace, SdkResult, and SdkError envelopes. Prompts use stdin wherever the CLI permits, keeping them out of process argument lists.

Protocol compatibility is checked on the first structured operation and cached for the client lifetime. If the installed CLI is too old, the SDK raises HeadlessVersionError with an upgrade command. Constructing a client never starts a subprocess.

run(..., fast=False) and cron.add(..., fast=False) default to standard mode. Pass fast=True to forward Headless' --fast flag for Codex or Claude; the CLI rejects it for other agents.

Structured methods raise on SDK error envelopes by default. Pass check=False to receive a typed SdkError value instead.

for event in headless.stream(["codex"], input="Review this diff"):
    print(event)

Use invoke() as the raw escape hatch for new or uncommon CLI features:

command = headless.invoke(["--help"])
print(command.stdout)

Runs using legacy raw-output or interactive flags (json, debug, tmux, or print_command) return sdk=None. Read their raw output through stdout; final_message is intentionally empty because those modes do not provide a normalized final-message result.

Interactive attach inherits the current terminal:

headless.sessions.attach("bughunt")

sessions.launch(name, ...) creates a managed tmux session using --tmux --name. Native durable agent sessions remain available through run(..., session=name).

Async methods have the same shape:

from headless_cli import AsyncHeadless

headless = AsyncHeadless()
result = await headless.run("claude", prompt="Fix the failing tests")

The package has no runtime Python dependencies.

Release files for headless-cli 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for headless-cli 0.6.0
File Size Uploaded
headless_cli-0.6.0.tar.gz 28.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for headless-cli 0.6.0
File Interpreter ABI Platform
headless_cli-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 59.7 kB

Release files / headless_cli-0.6.0.tar.gz

Download URL headless_cli-0.6.0.tar.gz
Size 28.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4a0cc8ffbc0ceddd3c785afec730f4ce70916ff830d5742cbdf1c185b609eb2a
BLAKE2b-256 checksum
How to use checksums
afb2fae0fe9400ac1f3cabdfed324419b5126b5de96cda2850318b72f5a03b4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Release files / headless_cli-0.6.0-py3-none-any.whl

Download URL headless_cli-0.6.0-py3-none-any.whl
Size 30.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9eda45eeac66edc43b135b79fed12754951f3050b23bd4cbc2cdadb97cfddb1
BLAKE2b-256 checksum
How to use checksums
ee91d620a8da401afc57f4249cba56b55e693f807f7c1acbf6be3b80d1a09ce1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.1

2 release files

This release

0.6.0 This release

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page