Skip to main content

Async Python wrapper for the Claude Code CLI with session management

Project description

albeorla-claude-cli-bridge

Async Python wrapper for the Claude Code CLI with automatic session management.

Install

pip install albeorla-claude-cli-bridge

Requires the claude CLI to be installed and authenticated.

Usage

import asyncio
from claude_cli_bridge import ClaudeBridge

async def main():
    bridge = ClaudeBridge(work_dir="~/my-project")

    # First call creates a new session
    resp = await bridge.query(key="chat-1", message="explain this codebase")
    print(resp.text)

    # Follow-up resumes the same session automatically
    resp = await bridge.query(key="chat-1", message="now refactor the main module")
    print(resp.text)

    # One-shot (no session tracking)
    resp = await bridge.ask("what is 2 + 2?")
    print(resp.text)

asyncio.run(main())

API

ClaudeBridge

ClaudeBridge(
    claude_binary="claude",       # path to claude CLI
    work_dir=".",                 # working directory for subprocess
    system_prompt=None,           # appended on first turn
    permission_mode="bypassPermissions",
    model=None,                   # e.g., "haiku", "sonnet"
    allowed_tools=None,           # e.g., ["Read", "WebSearch"]
)

Methods

Method Description
await bridge.query(key, message) Send a message to a session. Creates one if needed, resumes on follow-up.
await bridge.ask(message) One-shot query, no session reuse.
bridge.get_session(key) Get session by key, or None.
bridge.create_session(key) Explicitly create a session.
bridge.remove_session(key) Remove a session.
bridge.active_sessions Dict of all active sessions.

Response

Field Type Description
text str The assistant's reply
session_id str Claude session ID
cost_usd float Cost of the query
duration_ms int Wall-clock time
num_turns int Number of agent turns
is_error bool Whether the query failed
raw dict Full JSON response from the CLI

Session

Field Type Description
session_id str UUID for the Claude CLI session
key Any Application-defined identifier
turn_count int Messages sent in this session
busy bool Whether a query is in progress

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

albeorla_claude_cli_bridge-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

albeorla_claude_cli_bridge-0.2.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file albeorla_claude_cli_bridge-0.2.1.tar.gz.

File metadata

File hashes

Hashes for albeorla_claude_cli_bridge-0.2.1.tar.gz
Algorithm Hash digest
SHA256 0119978d8e802bd4a0667020e9ec389fc515ad5a3bb0bab94cfb5a904114fc5f
MD5 91b94058174e8508eb2a383fd21751d3
BLAKE2b-256 a070768e27f102bd703a4ade78eb56eb6df1532dbcba381a44ee4cd559c444d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for albeorla_claude_cli_bridge-0.2.1.tar.gz:

Publisher: publish-bridge.yml on albeorla/albeorla-python

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

File details

Details for the file albeorla_claude_cli_bridge-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for albeorla_claude_cli_bridge-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e466ed6601dfa39cd49feeca4dc2d6dcf067426180d9b103122a30b197bedb7e
MD5 a7f7de0d7b13829d40d640343d066070
BLAKE2b-256 06235dd6efbbbe0a817632cd48306ce845a6f169ca860c6513b1aa23c56c2ed4

See more details on using hashes here.

Provenance

The following attestation bundles were made for albeorla_claude_cli_bridge-0.2.1-py3-none-any.whl:

Publisher: publish-bridge.yml on albeorla/albeorla-python

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