kagura-brain
kagura-brain is the provider-neutral Python launcher for the CLI coding agents
used as brains by Kagura harnesses. It gives consumers one tested seam for
running Claude Code (claude -p) or Codex CLI (codex exec), keeping provider
credentials, subprocess behavior, MCP wiring, and verdict handling out of each
harness.
from kagura_brain import select
brain = select("claude") # or "codex"
result = brain.invoke("Reply with exactly: PONG")
if not result.ok:
raise RuntimeError(result.detail())
print(result.stdout)
What it provides
- Two CLI adapters: Claude Code and Codex share one subprocess, timeout, output, and result contract.
- Subscription-auth hygiene: inherited provider credentials and endpoint overrides are removed before launch so the CLI's own login wins.
- Explicit alternate backends: callers can opt into a compatible gateway; Codex can also select local Ollama or LM Studio backends.
- Provider-neutral selection:
select()keeps backend dispatch and MCP translation inside the library. - Safe gate semantics: the verdict module normalizes proceed/halt decisions; unknown or missing verdicts halt.
- Preflight primitives: lightweight checks cover binaries, auth commands, endpoints, and aggregate reports.
Backend summary
| Claude Code | Codex CLI | |
|---|---|---|
| Command | claude -p |
codex exec |
| Default auth | Claude subscription login | codex login / ChatGPT subscription |
| Scrubbed child environment | ANTHROPIC_*, CLAUDE_* |
OPENAI_*, CODEX_* |
| MCP | .mcp.json via per-call CLI flags |
.mcp.json translated to per-call mcp_servers.* overrides |
| Confinement | permission mode or explicit bypass | sandbox mode or explicit approval+sandbox bypass |
| Alternate backend | Anthropic-compatible gateway | Responses-compatible gateway, Ollama, or LM Studio |
Neither adapter loosens permissions by default. Full-bypass options are explicit, and the Codex bypass also disables its sandbox. See Provider configuration before using an unattended mode.
Install
pip install kagura-brain
# or
uv add kagura-brain
Requirements:
- Python 3.11+
claudeand/orcodexinstalled and available onPATH- the selected CLI signed in, unless an explicit alternate backend is used
The Python package is stdlib-only at runtime and deliberately has no dependency
on kagura-memory.
For setup, authentication, result handling, and first examples, read Getting started.
Architecture at a glance
Kagura's reusable harness support is split along two independent axes:
kagura-engineer kagura-planner kagura-code-reviewer
\ | /
+---- kagura-brain + kagura-memory ----+
brain axis memory axis
kagura-brain launches the coding agent. kagura-memory supplies durable
context. Keeping them independent avoids the inverted dependency "memory spawns
the agent". The full module and launch-flow description is in
Architecture.
Documentation
| Document | Purpose |
|---|---|
| Documentation index | Map of the available guides and references |
| Getting started | Installation, authentication, first invocation, and results |
| Provider configuration | Claude/Codex options, MCP behavior, gateways, and permission boundaries |
| Architecture | Package boundaries, launch pipeline, modules, and security invariants |
| Exit-code contract | Canonical gate vocabulary and reviewer seam |
| Contributing | Development workflow, quality gates, and release smoke tests |
| Changelog | Release history |
Current release
Version 0.6.1 supports Python 3.11-3.13. The Codex adapter's environment and
configuration assumptions were last audited against Codex CLI 0.145.0; the
subprocess suite remains mocked, so releases also require the documented real-CLI
smoke test.
Development
uv sync --extra dev
uv run ruff check src/ tests/
uv run ruff format --check src/ tests/
uv run mypy
uv run pytest tests/ -v
Coverage must remain at or above 90%. See CONTRIBUTING.md for the complete workflow.
License
Release files for kagura-brain 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| kagura_brain-0.6.1.tar.gz | 130.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| kagura_brain-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 165.8 kB
Release files / kagura_brain-0.6.1.tar.gz
| Download URL | kagura_brain-0.6.1.tar.gz |
|---|---|
| Size | 130.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9560ac231024757fd6cf721e3e26b763a2fd80ee6bbf82a81f18c10466199926
|
|
BLAKE2b-256 checksum How to use checksums |
bca53635009212e87ffb2b24149fea5df0e555de81f97278a03a4e2fafd97963
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency logRelease files / kagura_brain-0.6.1-py3-none-any.whl
| Download URL | kagura_brain-0.6.1-py3-none-any.whl |
|---|---|
| Size | 35.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d0f60703dad0e4f241354dea7112a5c316063db43957c99736aeb4764cba469b
|
|
BLAKE2b-256 checksum How to use checksums |
77dd054b23a1d147a6e81e4ce1da8ba04e5b26fbce7ef4b30fbb0e9b159e2f04
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 24, 2026.
Transparency log