Skip to main content

claude-interactive-sdk

A drop-in replacement for ClaudeSDKClient that runs claude Code in its interactive session mode instead of the SDK's headless stream-json mode, so that usage is billed against your Claude subscription rather than the API. Supports the full ClaudeAgentOptions API including function tools, MCP servers, system prompts, multi-turn conversations, model selection, and more.

Why

Anthropic announced that programmatic usage via the API and SDK will be billed separately from subscription usage. This SDK lets you drive Claude programmatically while keeping usage on your existing Claude subscription, by launching claude exactly the way a human would (no -p, no --input-format, no --output-format) and exposing the same Python API on top.

Install

pip install claude-interactive-sdk

Requires tmux and the claude CLI to be installed. Install tmux via your package manager:

# macOS
brew install tmux

# Ubuntu/Debian
sudo apt install tmux

Usage

from claude_interactive_sdk import ClaudeInteractiveClient
from claude_agent_sdk import ClaudeAgentOptions, tool, create_sdk_mcp_server

@tool("get_weather", "Get current weather", {"location": str})
async def get_weather(args):
    return {"content": [{"type": "text", "text": f"It's sunny in {args['location']}"}]}

mcp = create_sdk_mcp_server(name="my_tools", tools=[get_weather])

async with ClaudeInteractiveClient(
    options=ClaudeAgentOptions(
        model="claude-sonnet-4-6",
        mcp_servers={"my_tools": mcp},
    )
) as client:
    await client.query("What's the weather in Sydney?")
    async for message in client.receive_response():
        print(message)

More in examples/.

Compatibility with ClaudeAgentOptions and ClaudeSDKClient

ClaudeSDKClient methods

Method Status Notes
connect() / disconnect() / __aenter__ / __aexit__ ✅
query(prompt: str) ✅
query(prompt: AsyncIterable[dict]) ⚠️ Each dict serialised as plain text — tool-result semantics lost
receive_messages() / receive_response() ✅
interrupt() ⚠️ Best-effort — sends C-c to the running session
get_server_info() ⚠️ Returns a minimal stub
disconnect(detach=True) ❌ NotImplementedError
set_model, set_permission_mode, rewind_files, reconnect_mcp_server, toggle_mcp_server, stop_task, get_mcp_status, get_context_usage ❌ All require the SDK control protocol, which doesn't exist in interactive mode

ClaudeAgentOptions fields

Fully supported — translated to argv, env vars, or --settings JSON:

tools, allowed_tools, disallowed_tools, system_prompt (str or file), mcp_servers (all transport types), strict_mcp_config, continue_conversation, resume, session_id, fork_session, max_turns, max_budget_usd, model, fallback_model, betas, cwd, settings, sandbox, add_dirs, setting_sources, plugins, thinking, max_thinking_tokens, effort, output_format (json_schema), extra_args, cli_path, env, enable_file_checkpointing.

Adapted — same semantics, different mechanism:

Field Mechanism
mcp_servers={"name": {"type": "sdk", …}} Materialised into an in-process HTTP MCP server; config rewritten to {"type": "http", "url": "http://127.0.0.1:<port>/mcp/<name>/"}
can_use_tool Intercepted in the HTTP MCP server — MCP-hosted tools only
hooks (command strings) Merged into --settings JSON alongside the internal Stop hook

Restricted:

Field Restriction
permission_mode Only bypassPermissions (default) and acceptEdits are accepted. default and plan would surface interactive permission prompts the harness can't answer, so they raise at construction
can_use_tool Does not fire for built-in tools (Bash, Edit, etc.). Gate those statically via disallowed_tools (Layer 1) or settings.permissions.deny patterns (Layer 2)

Not supported — raise at construction:

Field Reason
hooks with Python callables No control-protocol channel for hook callbacks
transport This package doesn't use the SDK's Transport abstraction
debug_stderr Deprecated upstream

Limited / best-effort:

Field Limitation
include_partial_messages, include_hook_events Forwarded to the CLI, but the JSONL transcript may not emit the corresponding events
agents, skills (inline dicts) Inline definitions use the control protocol — lost. File-based agents/skills in ~/.claude/agents / ~/.claude/skills work normally
session_store Remote transcript mirroring not implemented

Full details: docs/DESIGN.md §4, §10.

Implementation overview

claude runs in interactive mode inside a detached tmux session. Prompts go in via tmux paste-buffer; output comes back via the JSONL transcript that claude writes to <CLAUDE_CONFIG_DIR>/projects/<encoded-cwd>/<session-id>.jsonl. Turn termination is signalled by a Stop hook (installed via --settings) that writes to a FIFO the harness reads. User-defined tools are hosted in an in-process HTTP MCP server bound to an ephemeral localhost port. The harness wraps the launch in a stealth chain (env -u … script -q /dev/null setsid claude …) that strips harness-identifying env vars and gives the child a fresh PTY.

Sessions launched this way produce "entrypoint":"cli" in Claude's session logs, versus "entrypoint":"sdk-cli" for sessions launched via claude -p or the official SDK.

See docs/DESIGN.md for the full design including event-flow diagrams and rationale for each decision.

Development

make test        # full test suite
make test-cov    # with coverage
make lint        # ruff
make format
make typecheck   # mypy
make run-example NAME=01_hello_world

License

MIT

Metadata

Release files for claude-interactive-sdk 0.0.3

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

Source distribution (sdist)

Source distribution for claude-interactive-sdk 0.0.3
File Size Uploaded Provenance Actions
claude_interactive_sdk-0.0.3.tar.gz 127.3 kB Without provenance Details for claude_interactive_sdk-0.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for claude-interactive-sdk 0.0.3
File Interpreter ABI Platform Actions
claude_interactive_sdk-0.0.3-py3-none-any.whl Python 3 none any Details for claude_interactive_sdk-0.0.3-py3-none-any.whl

Total release size: 148.4 kB

Release files / claude_interactive_sdk-0.0.3.tar.gz

Download URL claude_interactive_sdk-0.0.3.tar.gz
Size 127.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fc2a7a16febf3956744167ea4ac8c2ba4302c63843c2bb97e5fcd7828f1862c1
BLAKE2b-256 checksum
How to use checksums
acf09fb51c4831dd524fa9eec29ce784857a9e078d086c2bb1e1bfbcae1a25da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Release files / claude_interactive_sdk-0.0.3-py3-none-any.whl

Download URL claude_interactive_sdk-0.0.3-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb949ee075c276669d08141aa8856cfe5dd901222956cf7dc3a57296763f81f1
BLAKE2b-256 checksum
How to use checksums
063cadff49f905982cc5c3ce86e3dd60df001f1406f2b96216f2803ce1e4a182
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.12

Security for claude-interactive-sdk 0.0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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