Sockpuppet for Claude Code — drive the TUI programmatically, stream JSONL like claude -p
Project description
claude-sock: Use your Claude subscription with your Claw
CLI that wraps the Claude Code CLI to use Claude models just with a subscription, thus without paying through API or extra tokens.
Why
Anthropic recently limited support for third-party harnesses through subscription. It used to be possible to use Claude subscription to use a third-party harness such as Open Claw.
Getting started
Just
How it works
Quick start
Python API
import asyncio
from claude_sock.orchestrator import ClaudeREPL
async def main():
async with ClaudeREPL(timeout=60) as repl:
messages = await repl.query("What files are in this directory?")
for msg in messages:
print(msg)
asyncio.run(main())
Streaming
async with ClaudeREPL() as repl:
async for msg in repl.query_stream("Refactor main.py"):
print(msg)
Resume a session
async with ClaudeREPL(resume="ef4f97fd-d265-474e-9544-3f228e9654c0") as repl:
messages = await repl.query("Continue where we left off")
Load skills
async with ClaudeREPL() as repl:
await repl.send_skill("commit")
messages = await repl.query("Fix the login bug and commit")
MCP servers
# Pick servers by name from your .mcp.json
async with ClaudeREPL(server_names=["my-server"]) as repl:
messages = await repl.query("Use the my-server tool")
CLI (drop-in claude -p replacement)
echo "Explain this repo" | claude-sock -p
claude-sock "What does main.py do?" --timeout 60
claude-sock "Continue" --resume ef4f97fd-d265-474e-9544-3f228e9654c0
Output is JSONL, compatible with anything that reads claude -p format.
How it works
Your code
│
▼ keystrokes
┌─────────┐ ┌──────────────┐
│ pty │───────▶│ Claude Code │
│ (write) │ │ TUI │
└─────────┘ └──────┬───────┘
│ writes
▼
┌──────────────┐
│ session.jsonl │
└──────┬───────┘
│ reads
▼
┌──────────────┐
│ Your code │
│ (parsed) │
└──────────────┘
- Write channel: pty file descriptor — fire keystrokes and forget
- Read channel:
~/.claude/projects/…/{session_id}.jsonl— poll for new lines by byte offset
API reference
ClaudeREPL(timeout, session_id, workdir, env, server_names, resume)
| Param | Type | Default | Description |
|---|---|---|---|
timeout |
float |
120 |
Seconds to wait for activity before timing out |
session_id |
str | None |
auto-generated | Force a specific session ID |
workdir |
Path | None |
cwd |
Working directory for Claude |
env |
dict | None |
None |
Extra environment variables |
server_names |
list[str] | None |
None |
MCP server names from .mcp.json |
resume |
str | None |
None |
Session ID to resume |
Methods
| Method | Returns | Description |
|---|---|---|
query(text) |
list[Message] |
Send a message, wait for completion |
query_stream(text) |
AsyncIterator[Message] |
Send a message, yield parsed messages |
query_stream_raw(text) |
AsyncIterator[dict] |
Send a message, yield raw JSONL dicts |
send_skill(name) |
list[Message] |
Load a slash command (e.g. "commit") |
Message types
AssistantMessage— containsTextBlockandToolUseBlockToolResultMessage— containsToolResultBlockResultMessage— turn summary (duration, cost, session ID)
License
MIT
Project details
Release history Release notifications | RSS feed
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_sock-0.1.1.tar.gz.
File metadata
- Download URL: claude_sock-0.1.1.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df4e0aa5aa745420d72e67c473a3cb3799f5a9e3d0e1f35eafac4571793ce875
|
|
| MD5 |
86acaefd1b71f31ed12ef9edfe885261
|
|
| BLAKE2b-256 |
7dc7ee78162102fe3fba52c6c4b2a415bbd5b94f4553005a422748489d925b9d
|
File details
Details for the file claude_sock-0.1.1-py3-none-any.whl.
File metadata
- Download URL: claude_sock-0.1.1-py3-none-any.whl
- Upload date:
- Size: 9.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfed50c88bb06362550a7a1032e0bbb212c8c1873c5b20629cad684bcf57a2d1
|
|
| MD5 |
54b69482796cd010bebb6c69543c458f
|
|
| BLAKE2b-256 |
a163cb6bedd8ffb3011714160bec1cb68195211db3e36cb5f921ede1019ef837
|