harnext Python SDK
Run the harnext coding agent from Python. The SDK subprocesses
the harnext CLI (harnext -p --output-format stream-json) and yields parsed
messages, with an API that mirrors the
Claude Agent SDK for the
supported surface.
Install
pip install harnext # from PyPI
# or, from a checkout of this repo:
pip install -e sdk/python
# the harnext CLI must be installed too:
npm install -g harnext # or set HARNEXT_CLI_PATH to the CLI entry
The SDK locates the CLI via, in order: the cli_path option, the
HARNEXT_CLI_PATH env var, or harnext on PATH. A .js path is run with
node.
Quickstart
import asyncio
from harnext_sdk import query, HarnextAgentOptions, ResultMessage
async def main():
async for message in query(
prompt="What files are in this directory?",
options=HarnextAgentOptions(allowed_tools=["Read", "Bash"]),
):
if isinstance(message, ResultMessage):
print(message.result)
asyncio.run(main())
Options (HarnextAgentOptions)
Field names match claude_agent_sdk.ClaudeAgentOptions; ClaudeAgentOptions is
exported as an alias so ported code runs unchanged.
| Option | CLI flag | Notes |
|---|---|---|
model |
--model |
|
system_prompt |
--system-prompt |
|
append_system_prompt |
--append-system-prompt |
|
cwd |
--cwd |
|
allowed_tools |
--allowed-tools |
auto-approve list |
disallowed_tools |
--disallowed-tools |
blocked + hidden |
permission_mode |
--permission-mode |
default/acceptEdits/plan/dontAsk/bypassPermissions |
max_turns |
--max-turns |
|
setting_sources |
--setting-sources |
user/project/local → loads CLAUDE.md |
add_dirs |
--add-dir |
accepted; not yet enforced |
fallback_model |
--fallback-model |
accepted; reserved |
sandbox |
--sandbox |
accepted; currently a no-op in harnext |
provider |
--provider |
harnext extra |
thinking |
--thinking |
harnext extra |
env |
(process env) | merged over os.environ |
cli_path |
— | path to the CLI entry point |
extra_args |
passthrough | {"flag": "value"} → --flag value |
auto_update_cli |
— | default True; auto-upgrade the global CLI when it's behind the SDK |
CLI version sync
The SDK and CLI are released in lockstep (same version). On the first query()
call, if the globally-installed harnext CLI is older than the SDK, the SDK
runs npm install -g harnext@<sdk_version> once per process so the new flags it
emits are understood. It's best-effort: failures (no npm, offline, permissions)
emit a warning and the existing CLI is used.
It's skipped when cli_path or HARNEXT_CLI_PATH is set (custom/dev builds),
when auto_update_cli=False, or when HARNEXT_NO_CLI_AUTOUPDATE is set.
Tool names
Use the Claude names (Read, Write, Edit, Bash); they are matched
case-insensitively against harnext's native tools and echoed back in PascalCase.
Messages
query() yields SystemMessage (init), AssistantMessage, UserMessage
(tool results), then a terminal ResultMessage with subtype
(success / error_max_turns / error_during_execution), result,
num_turns, duration_ms, total_cost_usd, and usage.
Tests
cd sdk/python
pip install -e ".[dev]"
pytest # unit + stub-subprocess e2e
HARNEXT_LIVE_E2E=1 pytest -k live # live run against the real CLI (needs a provider key)
Publishing to PyPI
The package name on PyPI is harnext (import name harnext_sdk).
CI (recommended): unified release
Releases are unified in .github/workflows/release.yml: pushing a v<version>
tag publishes the CLI to npm and the Python SDK to PyPI in one run. The SDK
version is derived from the tag, so the CLI and SDK stay in lockstep
(v1.3.3 → npm 1.3.3 + harnext==1.3.3). PyPI uses
trusted publishing (OIDC — no token
stored in the repo).
- One-time: on PyPI add a trusted publisher for project
harnext, ownerQualityUnit, repoharnext, workflowrelease.yml, environment blank. - Dry run: trigger
release.ymlviaworkflow_dispatch(defaultdry_run=true) — builds and validates npm + PyPI without uploading. - Release: push a
v<version>tag (e.g.git tag v1.3.3 && git push origin v1.3.3).
version in pyproject.toml / __version__ in harnext_sdk/__init__.py are the
local defaults; CI overwrites them with the tag version at build time.
Manual
cd sdk/python
python -m build # -> dist/*.whl, dist/*.tar.gz
python -m twine check dist/*
python -m twine upload dist/* # needs a PyPI API token (TWINE_USERNAME=__token__)
Metadata
Release files for harnext 1.15.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| harnext-1.15.0.tar.gz | 16.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| harnext-1.15.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.9 kB
Release files / harnext-1.15.0.tar.gz
| Download URL | harnext-1.15.0.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d0524752591e3391dda08c320ec918808ac070e6a63bf9e22ba96d1a807cb74
|
|
BLAKE2b-256 checksum How to use checksums |
683352eb45507ae506eab595124cf771d523a597e98e45ec1d055255abe627bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 19, 2026.
Transparency logRelease files / harnext-1.15.0-py3-none-any.whl
| Download URL | harnext-1.15.0-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
761ecedc3a53f34a1227d5b7a9bd7d6f52fccf0bd40d6c9e2e5772ae12da4f38
|
|
BLAKE2b-256 checksum How to use checksums |
9dd0aea1e17e2baf4107fdab1d1c0961502c81297c2b50c07156f5dd3aa820b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Jun 19, 2026.
Transparency log