You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Shared async Python package for calling AI CLI tools (Claude, Gemini, Cursor) via subprocess.
Usage
importasynciofrompathlibimportPathfromai_cli_runnerimportcall_ai_cli, check_ai_cli_available, run_parallel_with_limit, AIResult, AITokenUsageasyncdefmain() ->None:
# Check if AI CLI is availableavailable, msg=awaitcheck_ai_cli_available(
ai_provider="claude",
ai_model="claude-sonnet-4-6",
)
# Call Claudesuccess, output=awaitcall_ai_cli(
prompt="Analyze this code",
cwd=Path("/path/to/repo"),
ai_provider="claude",
ai_model="claude-sonnet-4-6",
cli_flags=["--dangerously-skip-permissions"],
)
# Call Geminisuccess, output=awaitcall_ai_cli(
prompt="Summarize this PR",
cwd=Path("/path/to/repo"),
ai_provider="gemini",
ai_model="gemini-2.5-flash",
cli_flags=["--yolo"],
)
# Call Cursorsuccess, output=awaitcall_ai_cli(
prompt="Fix the failing test",
cwd=Path("/path/to/repo"),
ai_provider="cursor",
ai_model="sonnet-4.6",
cli_flags=["--force"],
)
# Run multiple calls in parallel with bounded concurrencyprompts= ["Analyze module A", "Analyze module B", "Analyze module C"]
results=awaitrun_parallel_with_limit(
[
call_ai_cli(
prompt=p,
ai_provider="claude",
ai_model="claude-sonnet-4-6",
)
forpinprompts
],
max_concurrency=5,
)
if__name__=="__main__":
asyncio.run(main())
JSON Output / Token Usage
Pass output_format="json" to get structured token usage metadata from providers that support it. Parsing is best-effort — if the provider output can't be parsed, usage fields fall back to defaults.