Skip to main content

Typed Python interface for the Headless CLI

Project description

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",
    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.

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

headless_cli-0.5.0.tar.gz (28.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

headless_cli-0.5.0-py3-none-any.whl (30.7 kB view details)

Uploaded Python 3

File details

Details for the file headless_cli-0.5.0.tar.gz.

File metadata

  • Download URL: headless_cli-0.5.0.tar.gz
  • Upload date:
  • Size: 28.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for headless_cli-0.5.0.tar.gz
Algorithm Hash digest
SHA256 a645eb4b72b374622162d1a8aed36b1489558f3ffdc9cc6f147b41d7f8d39e31
MD5 ad724db8b74c266dcb5975816e6351a5
BLAKE2b-256 f64c0122c137bb318a9cc61d439dccc8f8c41b0338a6556539dbfd82c733ad45

See more details on using hashes here.

Provenance

The following attestation bundles were made for headless_cli-0.5.0.tar.gz:

Publisher: release.yml on RobertTLange/headless-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file headless_cli-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: headless_cli-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 30.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for headless_cli-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7d8a7db20e33dc83a5da835c5ebcb404d61c3eee3527532f9341e55c9cfe2f3
MD5 36d2dffefacc509bb60ffe18865e6518
BLAKE2b-256 681278a137eaf0079797f92bd693addef526328db4136e2a3ea818148b494438

See more details on using hashes here.

Provenance

The following attestation bundles were made for headless_cli-0.5.0-py3-none-any.whl:

Publisher: release.yml on RobertTLange/headless-cli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page