A lightweight abstraction for executing CLI coding agents headlessly
Project description
Agent Shell
Agent Shell is a light weight abstraction for executing a cli coding agent headlessly and returning the output that can be used programatically as a unified contract
Installation
uv add agent-shell-py
or with pip:
pip install agent-shell-py
Examples
Execute
from agent_shell.shell import AgentShell
from agent_shell.models.agent import AgentType
shell = AgentShell(agent_type=AgentType.CLAUDE_CODE)
response = await shell.execute(
cwd="/path/to/project",
prompt="Can you tell me about this project?",
allowed_tools=["Read", "Glob", "Grep"],
model="sonnet",
)
print(response.response)
print(f"Cost: ${response.cost:.4f}")
print(f"Session: {response.session_id}")
# Resume the conversation using the session_id
follow_up = await shell.execute(
cwd="/path/to/project",
prompt="Now refactor the auth module based on your findings",
allowed_tools=["Read", "Edit", "Bash"],
model="sonnet",
session_id=response.session_id,
)
Stream
from agent_shell.shell import AgentShell
from agent_shell.models.agent import AgentType
shell = AgentShell(agent_type=AgentType.CLAUDE_CODE)
async for event in shell.stream(
cwd="/path/to/project",
prompt="Refactor the auth module",
allowed_tools=["Read", "Edit", "Bash"],
model="sonnet",
effort="high",
include_thinking=True,
):
if event.type == "system":
print(f"Session: {event.session_id}")
else:
print(f"[{event.type}] {event.content}")
OpenCode
from agent_shell.shell import AgentShell
from agent_shell.models.agent import AgentType
shell = AgentShell(agent_type=AgentType.OPENCODE)
response = await shell.execute(
cwd="/path/to/project",
prompt="Can you tell me about this project?",
model="anthropic/claude-sonnet-4-5",
)
print(response.response)
print(f"Session: {response.session_id}")
# Resume the conversation using the session_id
follow_up = await shell.execute(
cwd="/path/to/project",
prompt="Now refactor the auth module based on your findings",
model="anthropic/claude-sonnet-4-5",
session_id=response.session_id,
)
Note: OpenCode's
runmode auto-approves all tools. Theallowed_toolsandeffortparameters are configured viaopencode.json, not CLI flags.
Logging
Agent Shell uses Python's standard logging module. Configure the agent_shell logger to capture tool calls, session IDs, costs, and errors:
import logging
logging.getLogger("agent_shell").setLevel(logging.INFO)
logging.getLogger("agent_shell").addHandler(logging.StreamHandler())
Set to DEBUG for raw JSON events and full command arguments.
Copilot CLI
from agent_shell.shell import AgentShell
from agent_shell.models.agent import AgentType
shell = AgentShell(agent_type=AgentType.COPILOT_CLI)
response = await shell.execute(
cwd="/path/to/project",
prompt="Can you tell me about this project?",
model="gpt-4o",
)
print(response.response)
print(f"Session: {response.session_id}")
# Resume the conversation using the session_id
follow_up = await shell.execute(
cwd="/path/to/project",
prompt="Now refactor the auth module based on your findings",
session_id=response.session_id,
)
Note: Copilot CLI doesn't expose pricing data. The
costfield onAgentResponsewill always be0.0. Thedurationfield is populated fromusage.totalApiDurationMs.
Supported CLI Agents:
- Claude Code
- OpenCode
- Copilot CLI
- Gemini CLI
- Codex
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 agent_shell_py-0.1.8.tar.gz.
File metadata
- Download URL: agent_shell_py-0.1.8.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e4a1b9bc338d9606b794684921c3e807ffb4c44614d17b5c8e0dac8f75dc01f3
|
|
| MD5 |
3beae27bb656136d3ec6d8df6bcc39d0
|
|
| BLAKE2b-256 |
6f3a1cd90adf15e2e1588e451726498402c19da83caabb55a4169c417ba5e62a
|
Provenance
The following attestation bundles were made for agent_shell_py-0.1.8.tar.gz:
Publisher:
publish.yml on ScottRBK/agent-shell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_shell_py-0.1.8.tar.gz -
Subject digest:
e4a1b9bc338d9606b794684921c3e807ffb4c44614d17b5c8e0dac8f75dc01f3 - Sigstore transparency entry: 1343693205
- Sigstore integration time:
-
Permalink:
ScottRBK/agent-shell@8ea00c1b103d20042d6f1825ee4801e53d7c28f6 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/ScottRBK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ea00c1b103d20042d6f1825ee4801e53d7c28f6 -
Trigger Event:
release
-
Statement type:
File details
Details for the file agent_shell_py-0.1.8-py3-none-any.whl.
File metadata
- Download URL: agent_shell_py-0.1.8-py3-none-any.whl
- Upload date:
- Size: 12.0 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 |
2d1a0264c0bb91031449dea40489e83316af48a517f1c40056d90ef29c575bbe
|
|
| MD5 |
a09e3590d173eb61714538536c9c3048
|
|
| BLAKE2b-256 |
299b3ad6b710c4da34b38763156fe4e1ce9e62aed607ffffa9544bcaeecb6964
|
Provenance
The following attestation bundles were made for agent_shell_py-0.1.8-py3-none-any.whl:
Publisher:
publish.yml on ScottRBK/agent-shell
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_shell_py-0.1.8-py3-none-any.whl -
Subject digest:
2d1a0264c0bb91031449dea40489e83316af48a517f1c40056d90ef29c575bbe - Sigstore transparency entry: 1343693267
- Sigstore integration time:
-
Permalink:
ScottRBK/agent-shell@8ea00c1b103d20042d6f1825ee4801e53d7c28f6 -
Branch / Tag:
refs/tags/v0.1.8 - Owner: https://github.com/ScottRBK
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8ea00c1b103d20042d6f1825ee4801e53d7c28f6 -
Trigger Event:
release
-
Statement type: