Claude -p compatible wrapper backed by interactive Claude Code subscription sessions
Project description
claude-p
claude-p is a claude -p compatible Python CLI and SDK backed by the
interactive Claude Code TUI.
Use it when claude -p is unavailable in an environment, but interactive
claude works with the local Claude Code subscription login state.
Install
pip install claude-p
CLI
Default output matches claude -p: plain text.
claude-p.py "Respond exactly: hello"
Structured outputs:
claude-p.py "Respond exactly: hello" --output-format json
claude-p.py "Respond exactly: hello" --output-format stream-json --include-partial-messages
The CLI accepts a broad subset of claude -p flags, including:
-p,--print--model--tools--permission-mode--output-format text|json|stream-json--include-partial-messages--session-id--cwd- common Claude Code context/config flags such as
--system-prompt,--append-system-prompt,--mcp-config,--settings,--plugin-dir,--allowedTools,--disallowedTools,--resume, and--continue
Known limits:
- Token usage, cost, and exact rate-limit fields are best-effort placeholders.
- Hook lifecycle events from
claude -p --include-hook-eventsare not replayed yet. --input-format stream-jsonis accepted but not implemented.--bareconflicts with the subscription-login goal because Claude bare mode bypasses OAuth/keychain auth.
Python SDK
The API is intentionally shaped like the official Claude Agent SDK:
import asyncio
from claude_p import ClaudePOptions, query
async def main():
options = ClaudePOptions(
model="sonnet",
tools="default",
permission_mode="default",
)
async for message in query("这个目录里有多少个文件", options=options):
print(message)
asyncio.run(main())
For a single final result:
import asyncio
from claude_p import ClaudePClient, ClaudePOptions
async def main():
async with ClaudePClient(ClaudePOptions(model="sonnet")) as client:
result = await client.run("Respond exactly: SDK_OK")
print(result.result)
asyncio.run(main())
How it works
The wrapper does not call claude -p.
It:
- starts interactive
claudein a pseudo-TTY; - passes a deterministic
--session-id; - waits for the TUI response to complete;
- reads Claude Code's canonical session JSONL from
~/.claude/projects/**/<session-id>.jsonl; - emits text/json/stream-json output compatible with
claude -p.
The session JSONL is required because terminal rendering is lossy and can drop characters during redraws.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file claude_p-0.1.0.tar.gz.
File metadata
- Download URL: claude_p-0.1.0.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3fd92089b1063d09e6275f311b4939c243ef42b312204212516d2c66bb22b7ad
|
|
| MD5 |
66001130186d2248af32e3645a5a4fb6
|
|
| BLAKE2b-256 |
c530174073d833c460b45681397810ea716c90ce130d314dcaa50f76a4f7f76e
|
Provenance
The following attestation bundles were made for claude_p-0.1.0.tar.gz:
Publisher:
publish.yml on Equality-Machine/claude-p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_p-0.1.0.tar.gz -
Subject digest:
3fd92089b1063d09e6275f311b4939c243ef42b312204212516d2c66bb22b7ad - Sigstore transparency entry: 1531308800
- Sigstore integration time:
-
Permalink:
Equality-Machine/claude-p@cee52b8656a0131bd66aea73881a5bdcd333f8d4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Equality-Machine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cee52b8656a0131bd66aea73881a5bdcd333f8d4 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file claude_p-0.1.0-py3-none-any.whl.
File metadata
- Download URL: claude_p-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
569c33a2c329b52c53d863a78c5b569a9fa465167bacf3d64f6f85baba1a052a
|
|
| MD5 |
497445b845b3785d226f077e64b8450d
|
|
| BLAKE2b-256 |
fc2873ab3a9ad91294a2962cbcf7bf0fc8b8fa04f46db0e648662165f1e35038
|
Provenance
The following attestation bundles were made for claude_p-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on Equality-Machine/claude-p
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
claude_p-0.1.0-py3-none-any.whl -
Subject digest:
569c33a2c329b52c53d863a78c5b569a9fa465167bacf3d64f6f85baba1a052a - Sigstore transparency entry: 1531308856
- Sigstore integration time:
-
Permalink:
Equality-Machine/claude-p@cee52b8656a0131bd66aea73881a5bdcd333f8d4 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Equality-Machine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cee52b8656a0131bd66aea73881a5bdcd333f8d4 -
Trigger Event:
workflow_dispatch
-
Statement type: