Provider-agnostic coding-agent CLI shims
Project description
agentshim
agentshim wraps coding-agent CLIs behind one small Python interface.
It is useful when you want to drive tools like Claude Code, Codex, Gemini, or Opencode from Python without writing provider-specific subprocess plumbing for prompting, session resumption, event parsing, or MCP configuration.
What It Includes
- a shared CLI agent abstraction with a provider registry
- adapters for Claude Code, Codex, Gemini, and Opencode
- stateful chat sessions that automatically resume provider-native threads
- MCP server config models for providers that support MCP
- sandbox settings helpers for Claude Code
- a lightweight LiteLLM client and subagent helper
- trajectory/usage helpers used by higher-level runtimes
Install
uv add agentshim
agentshim does not bundle the underlying agent CLIs. You still need the
provider tool you want to use installed and authenticated on your machine, for
example claude, codex, gemini, or opencode.
Getting Started
1. Use the Generic Agent Interface for Chat and Resume
If you want to choose a provider at runtime, instantiate CodingAgent
directly with a provider name.
from agentshim import CodingAgent
agent = CodingAgent(provider="claude", model="sonnet")
chat = agent.start_session(cwd=".")
first_reply = chat.generate("Summarize this repository.")
follow_up = chat.generate("Now list the three highest-risk modules.")
print(first_reply)
print(follow_up)
print(chat.session_id)
start_session() returns a stateful chat object. On the first generate(...)
call, agentshim starts a fresh provider conversation. On later calls, it
automatically resumes the same underlying provider session using the session id
captured from the first run.
That corresponds roughly to these native CLI flows:
- Claude Code: first call is like
claude -p ..., later calls addclaude --resume <session_id> ... - Codex: first call is like
codex exec ..., later calls addcodex exec resume <thread_id> ... - Gemini: first call is like
gemini ..., later calls addgemini --resume <session_id> ... - Opencode: first call is like
opencode run ..., later calls addopencode run --session <session_id> ...
If you only want a one-shot request, use generate(...) directly instead of
opening a session:
from agentshim import CodexCodingAgent
agent = CodexCodingAgent(model="gpt-5")
reply = agent.generate("Write a short summary of this codebase.", cwd=".")
print(reply)
2. Instantiate a Specific Provider Directly
If you already know which backend you want, construct the provider class yourself.
from agentshim import ClaudeCodeCodingAgent
agent = ClaudeCodeCodingAgent(model="sonnet")
chat = agent.start_session(cwd=".")
print(chat.generate("What does this project do?"))
print(chat.generate("Which files should I read first?"))
The bundled provider classes are:
ClaudeCodeCodingAgentCodexCodingAgentGeminiCodingAgentOpencodeCodingAgent
3. Configure MCP Servers
Claude Code and Codex can be configured with MCP servers by passing
HttpMcpServer and StdioMcpServer objects at construction time.
from agentshim import ClaudeCodeCodingAgent, HttpMcpServer, StdioMcpServer
agent = ClaudeCodeCodingAgent(
model="sonnet",
mcp_servers=[
HttpMcpServer(
name="docs",
url="http://localhost:9000/sse",
headers={"Authorization": "Bearer dev-token"},
),
StdioMcpServer(
name="github",
command="npx",
args=["-y", "@modelcontextprotocol/server-github"],
env={"GITHUB_TOKEN": "ghp_example"},
),
],
)
chat = agent.start_session(cwd=".")
print(chat.generate("Use the MCP tools to inspect the repo."))
Notes:
HttpMcpServeris for HTTP/SSE-backed MCP servers.StdioMcpServeris for subprocess-backed MCP servers.- Gemini and Opencode currently reject
mcp_servers; use Claude Code or Codex if you need MCP.
Extending agentshim
Advanced users can register their own providers. CodingAgent(...) keeps its
main constructor portable; provider-specific constructor extras should go
through backend_kwargs.
from agentshim import BaseCodingAgent, CodingAgent, register_provider
@register_provider("my-agent", aliases=("my-agent-dev",))
class MyAgent(BaseCodingAgent):
def __init__(
self,
model: str | None = None,
region: str | None = None,
recorder=None,
event_handler=None,
mcp_servers=None,
sandbox=False,
):
self.model = model
self.region = region
self.recorder = recorder
self.event_handler = event_handler
def generate(self, prompt: str, cwd=None, timeout=300, silent=False) -> str:
return f"handled: {prompt}"
agent = CodingAgent(
provider="my-agent-dev",
model="demo",
backend_kwargs={"region": "us-west1"},
)
print(agent.generate("hello"))
Notes:
- Registration is import-driven. Your provider is available only after the module defining it has been imported in the current Python process.
list_providers()returns canonical provider names only. Aliases resolve viaget_provider_class(...)andCodingAgent(provider=...).register_provider(...)rejects invalid names, abstract classes, and accidental name collisions unless you passoverwrite=True.- If you want
CodingAgent(...)to instantiate your provider, its constructor should accept the shared kwargsmodel,recorder,event_handler,mcp_servers, andsandboxas needed. - If your provider needs extra constructor arguments beyond the shared portable set, pass them via
backend_kwargs={...}when constructingCodingAgent(...).
Development
uv sync --dev
uv run pytest
Publishing
Build locally with:
uv build
Publish with:
uv publish
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 agentshim-0.3.0.tar.gz.
File metadata
- Download URL: agentshim-0.3.0.tar.gz
- Upload date:
- Size: 214.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b14b5e2d52412541854621d3b599f9d0ce54b6d568330c2b4c98ea2c1d52deac
|
|
| MD5 |
1341be55480a236ca3e7b48983df3a07
|
|
| BLAKE2b-256 |
0b8be372102aaaaa03cecfb63801d4aa79cc2dfb53d01ab294604baa6f22b344
|
Provenance
The following attestation bundles were made for agentshim-0.3.0.tar.gz:
Publisher:
publish.yml on vic-lsh/agentshim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentshim-0.3.0.tar.gz -
Subject digest:
b14b5e2d52412541854621d3b599f9d0ce54b6d568330c2b4c98ea2c1d52deac - Sigstore transparency entry: 1361443100
- Sigstore integration time:
-
Permalink:
vic-lsh/agentshim@9737126fac9701f9034dfc0eead77522f60dc1c7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vic-lsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9737126fac9701f9034dfc0eead77522f60dc1c7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file agentshim-0.3.0-py3-none-any.whl.
File metadata
- Download URL: agentshim-0.3.0-py3-none-any.whl
- Upload date:
- Size: 47.4 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 |
e843372dc8316de08c89717a66307edf934cf667d3bed5dd6df51d779ea492f4
|
|
| MD5 |
7e170c39386fdbc9a92146ccae3c99a3
|
|
| BLAKE2b-256 |
1bca7c60a2725288bbe8879358a11772c3d170b8536d89cd58b019441a279fa6
|
Provenance
The following attestation bundles were made for agentshim-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on vic-lsh/agentshim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agentshim-0.3.0-py3-none-any.whl -
Subject digest:
e843372dc8316de08c89717a66307edf934cf667d3bed5dd6df51d779ea492f4 - Sigstore transparency entry: 1361443103
- Sigstore integration time:
-
Permalink:
vic-lsh/agentshim@9737126fac9701f9034dfc0eead77522f60dc1c7 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/vic-lsh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9737126fac9701f9034dfc0eead77522f60dc1c7 -
Trigger Event:
workflow_dispatch
-
Statement type: