Metadata-Version: 2.5
Name: batonai
Version: 0.3.0
Summary: Local-first AI coding orchestrator: a deterministic planner → coder → reviewer pipeline over Claude Code, Codex and other AI coding CLIs
Project-URL: Homepage, https://github.com/ozanorfa/baton
Project-URL: Repository, https://github.com/ozanorfa/baton
Project-URL: Issues, https://github.com/ozanorfa/baton/issues
Project-URL: Changelog, https://github.com/ozanorfa/baton/blob/main/CHANGELOG.md
Project-URL: Documentation, https://github.com/ozanorfa/baton/blob/main/docs/HOW_TO_USE.md
Author: Ozan Orfa
License-Expression: MIT
License-File: LICENSE
Keywords: ai,claude-code,cli,codex,coding-assistant,orchestrator,pipeline
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Build Tools
Requires-Python: >=3.12
Requires-Dist: pydantic>=2.7
Requires-Dist: pyyaml>=6.0
Requires-Dist: rich>=13.7
Requires-Dist: typer>=0.12
Description-Content-Type: text/markdown

<div align="center">

<img src="docs/assets/logo.svg" width="96" alt="batonai logo">

# batonai

**One AI writes the code. Another one checks it.**

A local-first CLI that hands your request from model to model — **Codex plans, Claude Code builds, your tests run, Codex reviews** — with zero tokens spent on coordination and no commit made without you.

[![CI](https://github.com/ozanorfa/baton/actions/workflows/ci.yml/badge.svg)](https://github.com/ozanorfa/baton/actions/workflows/ci.yml)
[![Release](https://img.shields.io/github/v/release/ozanorfa/baton?color=6366f1)](https://github.com/ozanorfa/baton/releases)
[![Python](https://img.shields.io/badge/python-3.12%2B-0ea5a4)](pyproject.toml)
[![Platforms](https://img.shields.io/badge/macOS%20%C2%B7%20Linux%20%C2%B7%20Windows-tested%20in%20CI-555)](.github/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-555)](LICENSE)

[Quick start](#quick-start) · [Guard mode](#guard-mode-a-second-opinion-on-every-claude-code-turn) · [How it works](#how-it-works) · [Is it worth it?](#is-it-worth-it-measure-it) · [User guide](docs/HOW_TO_USE.md) · [Türkçe](docs/HOW_TO_USE.tr.md)

<img src="docs/assets/demo.svg" width="860" alt="A batonai run: planner on Codex, tests before, coder on Claude Code, tests after, reviewer on Codex — verdict APPROVE WITH NOTES">

</div>

## Why

A model reviewing its own code shares its own blind spots. A **different** model, reading the actual diff against the plan, catches what the first one missed — in one of this project's early real runs, Codex caught a genuine bug in the code Claude had just written ([ADR-015](docs/DECISIONS.md)).

batonai makes that the default, without turning your workflow into an agent framework:

- 🧭 **Deterministic.** Routing is plain Python from YAML. No supervisor LLM, no agents chatting — every token goes into the work.
- 🔀 **Different models for different jobs.** Planning and review on Codex, implementation on Claude Code, tests on your own runner — three quota pools instead of one.
- 🧪 **Grounded in your tests.** Tests run *before* and *after* the change, so a suite that was already red is never blamed on the coder.
- 🔒 **You stay in charge of git.** No stage ever commits or pushes. Every artifact — plan, prompts, diff, review, costs — stays on disk to inspect.

## Quick start

```bash
uv tool install git+https://github.com/ozanorfa/baton   # or: pipx install git+https://github.com/ozanorfa/baton
cd your-project                                          # a git repo with a clean tree
batonai                                                  # scans, sets up, asks what you want
```

You need [Claude Code](https://docs.anthropic.com/en/docs/claude-code) (`claude`) and [Codex CLI](https://github.com/openai/codex) (`codex`) installed and logged in; `batonai doctor` checks. Python ≥ 3.12. Optional, only for stages that are off by default: `agy` (Designer), `opencode` (Publisher), `repowise` (`--health`). Then, any time:

```bash
batonai "Add Face ID unlock to the settings screen"        # the full pipeline
batonai --with-tester --fix-loop "…"                       # + your tests, + one automatic fix pass
batonai --preset tdd "add a slugify() helper"              # test-first: Codex writes failing tests, Claude makes them pass
batonai --pause-after planner "…"                          # read/edit the plan before any code is written
batonai review                                             # just a second opinion on your own uncommitted diff
```

## Guard mode: a second opinion on every Claude Code turn

Already living in Claude Code? Keep doing that. One command makes the Reviewer a [Stop hook](https://docs.anthropic.com/en/docs/claude-code/hooks):

```bash
batonai guard install
```

Every time Claude finishes a turn with uncommitted changes, Codex reviews the diff. **NEEDS WORK** → Claude gets the findings and keeps going (or argues back, by finding ID). Anything else → Claude stops with a one-line note. Bounded to one automatic round per request by default, never reviews the same diff twice, and never traps your session if something on baton's side fails. `batonai guard uninstall` removes it.

## How it works

```mermaid
flowchart LR
    R([your request]) --> P[Planner<br/>Codex · read-only]
    P -->|plan.md| B[Baseline<br/>your tests · 0 tokens]
    B --> C[Coder<br/>Claude Code · edits files]
    C -->|diff + changes.md| T[Tester<br/>your tests · 0 tokens]
    T --> V{Reviewer<br/>Codex · read-only}
    V -->|APPROVE| D([you: review the diff, commit])
    V -.->|NEEDS WORK · fix-loop| C
```

Each stage hands the next one an **artifact** (a plan, a change summary, the real diff, a test report) — not a transcript. The Reviewer also gets a mechanical *plan ↔ diff drift* report and, on a re-review, its own previous findings to rule on one by one. Same-provider stages resume each other's session, so Codex reviews with the planner's understanding of your repo already loaded.

| | One coding agent | Supervisor-LLM frameworks | **batonai** |
|---|:-:|:-:|:-:|
| A *different* model reviews the code | only if you ask | depends on the setup | **✓ every run** |
| Tokens spent on coordination | none | the supervisor's | **none** |
| Your tests before *and* after the change | if you ask | depends on the setup | **✓ `--with-tester`** |
| Plan, prompts, diff and review saved per run | a transcript | varies | **✓ `.ai/runs/`** |
| Resume a failed run without re-paying earlier stages | — | varies | **✓** |
| May commit or push | with your permission | depends on the tool | **never** — only `batonai publish`, typed by you |

## Everything it can do

| | |
|---|---|
| **Pipeline** | `batonai "<request>"` · `--with-tester` · `--with-designer` · `--with-publisher` (drafts a commit message) · `--fix-loop` · `--health` (code-health hotspots via repowise) |
| **Shape a run** | `--preset quick` (no planning) · `--preset tdd` (tests first) · your own presets · `--pause-after <stage>` · `batonai presets` |
| **Iterate** | `batonai revise "<correction>"` (the coder resumes its own session) · `batonai resume <id>` (continue a failed run; remembers its preset and stages) |
| **Review only** | `batonai review` (your diff, second model) · `batonai guard install` (every Claude Code turn) |
| **Learn** | numbered findings the coder may dispute · `batonai runs judge` (which findings were real?) · `batonai learn` (keep a rule every stage reads) |
| **Quota** | `fallback: [codex]` per role — a stage survives its provider's usage limit · `batonai usage` (spend per pool, last 5 h / 24 h / 7 d) |
| **Measure** | `batonai eval run "<task>"` — single session vs pipeline, blind · `batonai runs export` · `batonai runs show <id> --html` |
| **Integrate** | `batonai mcp` — call baton from Claude Code or Codex as MCP tools: `claude mcp add baton -- batonai mcp` |
| **Setup** | `batonai init` · `batonai setup` (which AI does which job, which model) · `batonai doctor` · `batonai config show` |

Full reference: [the user guide](docs/HOW_TO_USE.md) ([Türkçe](docs/HOW_TO_USE.tr.md)).

## Is it worth it? Measure it

The premise — two models in a pipeline beat one model in one session — is a claim until it is measured on real work, so baton ships the instrument:

```bash
batonai eval run --setup "npm ci" --review-single "add a dark-mode toggle that persists"
```

Your last commit is cloned twice (your working tree is never touched). One clone gets a single Claude session, the other the baton pipeline; your tests run in both; you judge the two diffs as **X** and **Y** without knowing which is which. `--review-single` also asks the Reviewer about the single session's diff — *would a second model have caught something it shipped?* The protocol and the results so far live in [docs/EVALUATION.md](docs/EVALUATION.md). **Honest status: no results recorded yet** — if you run it, an issue with your `batonai eval list` output is the most useful contribution there is.

## What the cost number means

The `$` after a run is the provider-reported **API-equivalent** value. On subscription plans (Claude Pro/Max, ChatGPT) you are **not charged per run** — the run uses your plan's quota. A typical pipeline run is $0.50–1.50 of quota, mostly fixed per-stage overhead, so it barely grows with task size. For small changes use `--preset quick`, `batonai ask`, or a lighter model (`providers: {claude: {model: haiku}}`).

## ⚠ Trust model

The Coder stage **edits your repository unattended** (scoped to the project directory). The safety net: start from a clean git tree (you are warned otherwise), every change is diffable, the Reviewer reads the actual diff, and **no pipeline stage ever runs `git commit`, `git push` or anything touching a remote** — for any role, with any flag. The one command that runs git is `batonai publish --commit/--push`, which you type yourself and confirm. With `providers: {claude: {allow_commands: true}}` the Coder may run your tests, while git history and remote commands stay mechanically blocked. Details: [ADR-007](docs/DECISIONS.md), [ADR-014](docs/DECISIONS.md), [ADR-034](docs/DECISIONS.md).

## Status

**v0.3.0** (2026-12-01; [releases](https://github.com/ozanorfa/baton/releases) carry the wheel — not on PyPI yet) — see [CHANGELOG.md](CHANGELOG.md). Verified live on macOS with the real CLIs (a real Flutter app end to end); the 440+ test suite needs no AI access and runs on macOS, Linux and Windows in CI. Every 0.3 feature was exercised live on 2026-12-01 with the real CLIs — the guard (headless and in an interactive Claude Code session), test-first runs with a paused and edited plan, the quota fallback, the findings ledger through a full open → fixed cycle, `eval`, and both MCP tools from Claude Code. In the first guard run, Codex caught a real input-validation bug in the function Claude had just written, and Claude fixed it before stopping. The suite also passes in a Linux container. Not yet verified: a live run with the real CLIs on Linux or Windows. Every design choice is written down in [47 ADRs](docs/DECISIONS.md).

## Documentation

| Doc | What's in it |
|---|---|
| [HOW_TO_USE.md](docs/HOW_TO_USE.md) · [HOW_TO_USE.tr.md](docs/HOW_TO_USE.tr.md) | **Start here** — the plain-language user guide |
| [EVALUATION.md](docs/EVALUATION.md) | Does the pipeline beat a single session? The protocol, and results as they come |
| [ARCHITECTURE.md](docs/ARCHITECTURE.md) | Layers, adapter contract, context system, verified CLI behaviour |
| [DECISIONS.md](docs/DECISIONS.md) | Why everything is the way it is |
| [MANUAL_TESTING.md](docs/MANUAL_TESTING.md) | Every feature, hands-on, with token-cost notes |
| [CHANGELOG.md](CHANGELOG.md) · [WORKLOG.md](docs/WORKLOG.md) | Releases · session-by-session history |
| [PROJECT_STRUCTURE.md](docs/PROJECT_STRUCTURE.md) · [IDEAS.md](docs/IDEAS.md) | Repo layout · evaluated ideas |

## Contributing

Pull requests against a protected `main` (green CI on all three platforms required) — see [CONTRIBUTING.md](CONTRIBUTING.md). Third-party providers plug in through the `ai_orchestrator.providers` entry-point group.

```bash
git clone https://github.com/ozanorfa/baton && cd baton
uv sync
uv run pytest          # unit + contract (recorded real CLI fixtures) + integration (fake provider)
uv run ruff check .
```

**Releasing** (maintainers): bump `version` in `pyproject.toml`, move *Unreleased* in `CHANGELOG.md` to the new version, merge, then `git tag v<version> && git push origin v<version>`. The `release` workflow checks the tag against the version, runs the suite, builds, and creates the GitHub release with the wheel (PyPI publishing is switched on by the `PYPI_PUBLISH` repository variable).

If you move the checkout, the old `.venv` keeps absolute paths (`uv run pytest` then fails to import `ai_orchestrator`): `rm -rf .venv && uv sync`, and `unset VIRTUAL_ENV` if your shell still exports the old one.

Exit codes for scripts: `0` success (or paused on purpose) · `1` a stage failed · `2` config/usage error · `130` cancelled.

<div align="center"><sub>MIT licensed · made for people who would rather read a diff than trust one</sub></div>
