claudecodestreaming
Stream text from the Claude Code CLI. This library is a text-completion alternative to agentmake: you pass chat messages, and it yields response text as the CLI produces it.
Authentication is the subscription session from claude auth login, or a subscription token from claude setup-token exported as ANTHROPIC_AUTH_TOKEN. The child process does not receive ANTHROPIC_API_KEY. No API key is read or sent.
Install
pip install claudecodestreaming
Requires the claude executable on PATH, at ~/.claude/local/claude, or at ~/.local/bin/claude, and a completed claude auth login.
Stream
import asyncio
from claudecodestreaming import stream_text
async def main():
messages = [
{"role": "system", "content": "You are a concise Bible study assistant."},
{"role": "user", "content": "What is John 3:16 about?"},
{"role": "assistant", "content": "It states God's love for the world."},
]
async for chunk in stream_text(messages, follow_up="Quote it briefly."):
print(chunk, end="", flush=True)
asyncio.run(main())
messages use role and content, the same shape agentmake accepts. follow_up is the newest user turn. An explicit system argument is sent with --system-prompt. System messages already in messages stay in the user prompt, so a generic identity does not outrank that task. Each call is a new headless process: the library does not resume a previous Claude Code session.
The process is text-only. Every built-in tool is removed (--tools ""), MCP servers are not loaded (--strict-mcp-config), session persistence is off, and it runs in a temporary working directory; with no tools there is exactly one turn. The prompt travels on stdin, so it never appears in ps output. Cancel an in-flight stream by setting the asyncio.Event passed as cancel_event.
model defaults to the CLI's configured model, so the library follows whatever claude is signed in and set up to run. Pass model="sonnet" or a full model name to pin one.
collect_text returns the whole reply:
from claudecodestreaming import collect_text
text = await collect_text(follow_up="Reply with exactly: pong")
Metadata
Release files for claudecodestreaming 0.1.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 | |
|---|---|---|---|
| claudecodestreaming-0.1.0.tar.gz | 8.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| claudecodestreaming-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.5 kB
Release files / claudecodestreaming-0.1.0.tar.gz
| Download URL | claudecodestreaming-0.1.0.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ee0a7d1d136dd0cb3ed10c024f8bcb24e4cf6e6ad44f3eff664f71cbb6eee1e3
|
|
BLAKE2b-256 checksum How to use checksums |
ed0c9a2746764f6e7eecc4af0441f4fdc82a960415af9f12aaf35071f2ab07d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / claudecodestreaming-0.1.0-py3-none-any.whl
| Download URL | claudecodestreaming-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b12dd1fcb3b3ed18c02342b6aefe4bbad222fd8045d996af1c6273fbbdd38421
|
|
BLAKE2b-256 checksum How to use checksums |
641e0ff56965954b60b6edf453cec333dd4f57b52972592c11ea45b80c8e6ad8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|