codebaton 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. codebaton-0.1.0/LICENSE +21 -0
  2. codebaton-0.1.0/PKG-INFO +305 -0
  3. codebaton-0.1.0/README.md +276 -0
  4. codebaton-0.1.0/pyproject.toml +108 -0
  5. codebaton-0.1.0/pyproject.toml.orig +81 -0
  6. codebaton-0.1.0/src/codebaton/__init__.py +8 -0
  7. codebaton-0.1.0/src/codebaton/cli.py +918 -0
  8. codebaton-0.1.0/src/codebaton/config.py +316 -0
  9. codebaton-0.1.0/src/codebaton/core/__init__.py +0 -0
  10. codebaton-0.1.0/src/codebaton/core/audit.py +42 -0
  11. codebaton-0.1.0/src/codebaton/core/budget.py +117 -0
  12. codebaton-0.1.0/src/codebaton/core/handoff.py +251 -0
  13. codebaton-0.1.0/src/codebaton/core/model_routing.py +205 -0
  14. codebaton-0.1.0/src/codebaton/core/policy.py +98 -0
  15. codebaton-0.1.0/src/codebaton/core/router.py +279 -0
  16. codebaton-0.1.0/src/codebaton/core/usage_cache.py +102 -0
  17. codebaton-0.1.0/src/codebaton/discovery.py +79 -0
  18. codebaton-0.1.0/src/codebaton/hooks.py +275 -0
  19. codebaton-0.1.0/src/codebaton/launcher.py +236 -0
  20. codebaton-0.1.0/src/codebaton/local_models.py +476 -0
  21. codebaton-0.1.0/src/codebaton/mcp/__init__.py +0 -0
  22. codebaton-0.1.0/src/codebaton/mcp/server.py +14 -0
  23. codebaton-0.1.0/src/codebaton/monitor.py +137 -0
  24. codebaton-0.1.0/src/codebaton/plugins/__init__.py +0 -0
  25. codebaton-0.1.0/src/codebaton/plugins/base.py +112 -0
  26. codebaton-0.1.0/src/codebaton/plugins/executors/__init__.py +0 -0
  27. codebaton-0.1.0/src/codebaton/plugins/executors/local.py +99 -0
  28. codebaton-0.1.0/src/codebaton/plugins/providers/__init__.py +0 -0
  29. codebaton-0.1.0/src/codebaton/plugins/providers/_common.py +29 -0
  30. codebaton-0.1.0/src/codebaton/plugins/providers/claude_code.py +135 -0
  31. codebaton-0.1.0/src/codebaton/plugins/providers/codex.py +101 -0
  32. codebaton-0.1.0/src/codebaton/plugins/registry.py +77 -0
  33. codebaton-0.1.0/src/codebaton/plugins/usage/__init__.py +0 -0
  34. codebaton-0.1.0/src/codebaton/plugins/usage/cached.py +52 -0
  35. codebaton-0.1.0/src/codebaton/plugins/usage/codex_logs.py +120 -0
  36. codebaton-0.1.0/src/codebaton/plugins/usage/manual.py +49 -0
  37. codebaton-0.1.0/src/codebaton/py.typed +0 -0
  38. codebaton-0.1.0/src/codebaton/report.py +130 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 codebaton contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,305 @@
1
+ Metadata-Version: 2.4
2
+ Name: codebaton
3
+ Version: 0.1.0
4
+ Summary: Keep coding when an AI agent hits its usage limit: opens the real Claude Code, Codex or a local Ollama model, shows usage against your threshold, and hands work over with shared notes and git checkpoints.
5
+ Keywords: claude-code,codex,ollama,ai-agents,coding-agent,cli,rate-limit,failover
6
+ Author: aaajjjj
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Operating System :: MacOS
13
+ Classifier: Operating System :: POSIX :: Linux
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: typer>=0.12
21
+ Requires-Dist: pydantic>=2.6
22
+ Requires-Dist: pyyaml>=6.0
23
+ Requires-Python: >=3.11
24
+ Project-URL: Homepage, https://github.com/aaajjjj/codebaton
25
+ Project-URL: Documentation, https://github.com/aaajjjj/codebaton#readme
26
+ Project-URL: Changelog, https://github.com/aaajjjj/codebaton/blob/main/CHANGELOG.md
27
+ Project-URL: Issues, https://github.com/aaajjjj/codebaton/issues
28
+ Description-Content-Type: text/markdown
29
+
30
+ # codebaton
31
+
32
+ **See your Claude Code and Codex limits live, and never lose your thread when one runs out.
33
+ No proxy, no API keys: your own subscriptions, the official CLIs.**
34
+
35
+ [![CI](https://github.com/aaajjjj/codebaton/actions/workflows/ci.yml/badge.svg)](https://github.com/aaajjjj/codebaton/actions/workflows/ci.yml)
36
+ [![PyPI](https://img.shields.io/pypi/v/codebaton)](https://pypi.org/project/codebaton/)
37
+ [![Python](https://img.shields.io/pypi/pyversions/codebaton)](https://pypi.org/project/codebaton/)
38
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/aaajjjj/codebaton/blob/main/LICENSE)
39
+
40
+ You're deep in a task with Claude Code and it says you've used most of your 5-hour limit.
41
+ codebaton sees that coming. It shows each agent's usage against a threshold you choose,
42
+ opens the agent that still has room, and passes the baton: the next agent picks up where the
43
+ last one stopped, using shared notes and git checkpoints.
44
+
45
+ ```text
46
+ $ codebaton watch
47
+ agent window usage used status
48
+ claude_code 5h ██████████████│░░░░░ 71% over threshold (threshold 70%) resets in 1h 12m
49
+ claude_code week ████░░░░░░░░░░│░░░░░ 22% ok (threshold 70%) resets in 3d 2h
50
+ codex 5h █░░░░░░░░░│░░░░░░░░░ 6% ok (threshold 50%) resets in 4h 40m
51
+ codex week ░░░░░░░░░░│░░░░░░░░░ 2% ok (threshold 50%) resets in 5d 18h
52
+ ```
53
+
54
+ - **No proxy, no API keys.** Your traffic goes straight from the official `claude` and
55
+ `codex` CLIs to their providers, on the subscriptions you already pay for. Nothing sits in
56
+ between, and nothing breaks the providers' terms the way relay proxies can.
57
+ - **Native, not a wrapper.** You get the real CLI, with full speed and every feature.
58
+ codebaton adds a status line and hooks for that session only and never touches your own
59
+ settings.
60
+ - **Real usage numbers.** These are the same percentages `/usage` shows, not token guesses.
61
+ - **Hand-over without a lost thread.** `HANDOFF.md` and `AGENTS.md` carry the goal and
62
+ progress between agents. A git checkpoint is saved after every reply.
63
+ - **Local fallback.** An optional free [Ollama](https://ollama.com) model runs on your
64
+ machine, with a memory check before anything is installed or loaded.
65
+ - **Your logins stay yours.** codebaton never reads, stores or sends credentials. Each CLI
66
+ uses its own sign-in.
67
+ - **Ready for teams.** An organisation policy file locks permissions and approved agents on
68
+ every machine, and `codebaton report` exports usage and hand-overs as JSON or CSV.
69
+
70
+ > Status: **alpha** (0.x). Tested on macOS with Claude Code and Codex CLI. Linux should work;
71
+ > Windows is untested.
72
+
73
+ ## How it works
74
+
75
+ ![codebaton component diagram: the CLI reads usage, the launcher opens Claude Code,
76
+ Codex or Ollama, session hooks save checkpoints and handoff notes. Dashed boxes show the
77
+ next milestones: quality gates, style contract, MCP server, light local harness.](https://raw.githubusercontent.com/aaajjjj/codebaton/main/docs/assets/architecture.svg)
78
+
79
+ 1. You run `codebaton` in a project.
80
+ 2. It reads each agent's usage and recommends the first one under its threshold.
81
+ 3. It opens that agent's **real CLI** in your terminal, with session-only hooks attached.
82
+ 4. After every reply, a hook saves a git checkpoint and checks usage. Near the threshold the
83
+ agent is asked to update `HANDOFF.md`; over it, you're offered the next agent, which
84
+ starts by reading that file.
85
+
86
+ More detail: [docs/architecture.md](https://github.com/aaajjjj/codebaton/blob/main/docs/architecture.md). Design decisions:
87
+ [docs/decisions.md](https://github.com/aaajjjj/codebaton/blob/main/docs/decisions.md).
88
+
89
+ ## Requirements
90
+
91
+ - Python 3.11+
92
+ - At least one agent CLI, installed and signed in:
93
+ [Claude Code](https://code.claude.com/docs) (`claude`) and/or
94
+ [Codex CLI](https://github.com/openai/codex) (`codex`, then `codex login`)
95
+ - git (progress is saved as commits)
96
+ - Optional: [Ollama](https://ollama.com) for a free local model
97
+
98
+ ## Install
99
+
100
+ ```bash
101
+ pipx install codebaton # or: uv tool install codebaton
102
+ # or: pip install codebaton
103
+ codebaton --version
104
+ ```
105
+
106
+ ## Quick start
107
+
108
+ ```bash
109
+ cd your-project # any git repository
110
+ codebaton # first run offers to set the project up
111
+ ```
112
+
113
+ ```text
114
+ claude_code 27.0% used / 50% threshold ok [week 18%, 5h 27%]
115
+ codex 2.0% used / 50% threshold ok [5h 2%, week 0%]
116
+
117
+ Which agent?
118
+ 1) claude_code 27.0% used / 50% threshold, under threshold <- recommended
119
+ 2) codex 2.0% used / 50% threshold, under threshold
120
+ 3) ollama local model llama3.2:1b, chat (answers in seconds, no edits)
121
+ q) quit
122
+ Choose (Enter = recommended):
123
+ ```
124
+
125
+ Press Enter and you're in the real Claude Code. Work as usual. When you `/exit` above the
126
+ threshold, codebaton asks **"Continue in codex?"**, and Codex starts by reading
127
+ `HANDOFF.md`.
128
+
129
+ ## Everyday commands
130
+
131
+ | Command | What it does |
132
+ |---|---|
133
+ | `codebaton` | Show usage, then open the recommended agent |
134
+ | `codebaton use claude` / `codex` / `ollama` | Open a specific agent |
135
+ | `codebaton use claude "fix the login bug"` | Open it with a first message |
136
+ | `codebaton watch` | Live usage bars with reset countdowns for every agent (`--json` for scripts and menu-bar widgets) |
137
+ | `codebaton status [--refresh]` | Usage vs thresholds (`--refresh` makes one tiny Claude call for fresh numbers) |
138
+ | `codebaton report [--since 7d]` | Sessions, hours, checkpoints and hand-overs per agent (`--json`, `--csv`) |
139
+ | `codebaton install-model` | Pick and install a local model: shows its size and the memory it needs, then asks first |
140
+ | `codebaton use ollama --chat` | Local model as a plain chat: answers in seconds, can't edit files |
141
+ | `codebaton run "<task>"` | One task, unattended (scripts, overnight), with model tiers and automatic failover |
142
+ | `codebaton help` | Everyday commands with examples |
143
+
144
+ Options: `--model haiku|sonnet|opus` starts on a tier (Codex uses its matching model);
145
+ `--repo DIR` works on another folder. Inside a session, the agent's own `/model` works as
146
+ usual.
147
+
148
+ ## What codebaton adds to a session
149
+
150
+ | | Claude Code | Codex |
151
+ |---|---|---|
152
+ | Live usage | status line: `baton · Claude · 5h 31% · wk 18% / 50% · next: Codex` | Codex's own `/status` |
153
+ | After every reply | git checkpoint if files changed | git checkpoint if files changed |
154
+ | Near the threshold | Claude is asked once to update `HANDOFF.md` | desktop notification |
155
+ | Over the threshold | "Type /exit to continue in Codex" | desktop notification |
156
+
157
+ ## Configuration
158
+
159
+ The first run creates these files in your project:
160
+
161
+ | File | Purpose | Commit it? |
162
+ |---|---|---|
163
+ | `router.yaml` | agent order, thresholds, permissions | no (added to `.gitignore`) |
164
+ | `model_routing.yaml` | which tasks go to haiku / sonnet / opus tiers | yes |
165
+ | `AGENTS.md` | project goal and conventions for every agent | yes |
166
+ | `HANDOFF.md` | current state: goal, done, next, open questions | yes |
167
+ | `decisions.log` | one line per decision | yes |
168
+
169
+ ```yaml
170
+ # router.yaml
171
+ providers: # preference order: the first one under its threshold wins
172
+ - name: claude_code
173
+ cap_percent: 50 # above 50% used (as /usage shows it), move to the next agent
174
+ - name: codex
175
+ cap_percent: 50
176
+ profile: per_session # overnight | per_session | strict
177
+ warn_margin_percent: 5 # this close to a threshold, ask the agent for a full handoff
178
+ git_checkpoint: true # commit a checkpoint after every agent reply
179
+ allow_web: false # let agents browse / search the web
180
+ allow_push: false # let agents run `git push`
181
+ allow_all_commands: false
182
+ ollama:
183
+ enabled: true
184
+ mode: agent # agent (edits code via Codex) | chat (fast, no edits)
185
+ ```
186
+
187
+ The full reference is [examples/router.example.yaml](https://github.com/aaajjjj/codebaton/blob/main/examples/router.example.yaml).
188
+
189
+ **How usage is measured.** Claude reports its 5-hour and weekly usage with every reply.
190
+ Codex writes the same figures to its local session logs. The higher of the two windows
191
+ counts. A rate-limit error marks an agent as exhausted until its window resets.
192
+
193
+ ## For teams and organisations
194
+
195
+ **Organisation policy.** IT can deploy one file to every machine (for example with MDM).
196
+ Projects can't loosen it. codebaton reads `$CODEBATON_POLICY` if set, otherwise
197
+ `/etc/codebaton/policy.yaml`:
198
+
199
+ ```yaml
200
+ # /etc/codebaton/policy.yaml
201
+ minimum_profile: per_session # projects may be stricter, never looser
202
+ deny: [push, all_commands] # switches no project can turn on (also: web)
203
+ allowed_agents: [claude_code, codex] # e.g. no local models
204
+ require_checkpoints: true
205
+ max_cap_percent: 80 # keep headroom: hand over by 80% at the latest
206
+ ```
207
+
208
+ Whenever the policy changes a project's settings, codebaton says what it enforced.
209
+
210
+ **Reporting.** `codebaton report --since 30d --json` summarises each repository's audit log
211
+ (`.codebaton/audit.jsonl`): sessions, hours, checkpoints, hand-overs and rate limits per
212
+ agent. Collect the JSON or CSV from many repositories with no server involved.
213
+
214
+ **Why it suits companies:** no proxy and no extra credentials, so no new vendor sees your
215
+ code; the official CLIs keep their own permission prompts and sandboxes; and every routing
216
+ decision is logged locally.
217
+
218
+ ## Local models (Ollama)
219
+
220
+ ```bash
221
+ codebaton install-model # choose from models that suit your machine's memory
222
+ codebaton use ollama --chat # instant answers, no file edits
223
+ codebaton use ollama # coding agent via Codex's harness (can edit files)
224
+ ```
225
+
226
+ Be realistic about speed. Agent mode sends Codex's ~47K-token instructions to the model, so
227
+ on a laptop the **first** reply takes about a minute even with a 1B model. Replies after
228
+ that take seconds. Small models also make mistakes as agents. Chat mode is the quick way to
229
+ confirm local models work. Ollama is started only when you choose it and stopped when you
230
+ exit.
231
+
232
+ ## Safety and privacy
233
+
234
+ - **Credentials:** never read or stored. `router.yaml` refuses keys that look like secrets.
235
+ - **Commits:** a checkpoint commits only the files created or changed during the agent's
236
+ turn. Work you already had uncommitted, or staged, when the session opened is left alone,
237
+ unless the agent edits that same file. Checkpoint commits are named
238
+ `chore(codebaton): ...`, hooks such as pre-commit still run, and
239
+ `git_checkpoint: false` turns them off. Unattended `codebaton run` owns the repo and
240
+ commits everything.
241
+ - **Permissions:** in interactive sessions each CLI keeps its own permission prompts. The
242
+ `allow_*` switches mainly affect unattended `codebaton run`, and they're off by
243
+ default.
244
+ - **Outside git:** codebaton warns before setting up a folder that isn't a git repository.
245
+
246
+ Report vulnerabilities privately: see [SECURITY.md](https://github.com/aaajjjj/codebaton/blob/main/SECURITY.md).
247
+
248
+ ## Roadmap
249
+
250
+ - [x] **v0.1:** native Claude Code / Codex sessions with usage routing, handoff notes, git
251
+ checkpoints, local models with memory checks
252
+ - [ ] **Milestone 2:** quality gates (tests, lint and an LLM judge after each task; a low
253
+ score moves to a stronger model) and a shared style contract
254
+ - [ ] **Milestone 3:** MCP server, so any MCP client can ask for usage, handoffs and
255
+ checkpoints
256
+ - [ ] A lighter local harness, so small local models can edit code in seconds
257
+ - [x] Live usage monitor (`watch`), team report (`report`), organisation policy
258
+ - [ ] More agents (e.g. Gemini CLI) through the provider plug-in interface
259
+ - [ ] Menu-bar widget and Linux desktop notifications
260
+
261
+ Ideas and votes are welcome in [Issues](https://github.com/aaajjjj/codebaton/issues).
262
+
263
+ ## FAQ
264
+
265
+ **Is this a proxy? Does it see my prompts?**
266
+ No. Your terminal talks directly to the agent CLI. codebaton only launches it, reads usage
267
+ numbers and saves checkpoints.
268
+
269
+ **Why not an MCP server?**
270
+ An MCP server runs inside one agent, so it can't switch you to a different agent. The CLI
271
+ does the switching. An MCP server for usage and handoff tools is on the roadmap.
272
+
273
+ **How is this different from claude-code-router or other model proxies?**
274
+ Those send your requests through a proxy to other models or API keys. codebaton never
275
+ touches the traffic: it runs the official CLIs on your own subscriptions, watches the usage
276
+ they report, and hands the work over with shared notes and git checkpoints.
277
+
278
+ **Do I need both Claude Code and Codex?**
279
+ No. With one agent you still get the status line, checkpoints and handoff notes. With Ollama
280
+ you also get a free local fallback.
281
+
282
+ ## Contributing
283
+
284
+ Contributions are welcome. Start with [CONTRIBUTING.md](https://github.com/aaajjjj/codebaton/blob/main/CONTRIBUTING.md).
285
+
286
+ ```bash
287
+ git clone https://github.com/aaajjjj/codebaton.git
288
+ cd codebaton
289
+ uv sync
290
+ scripts/check.sh # format, lint, type-check and tests, as CI runs them
291
+ ```
292
+
293
+ Commit messages follow [Conventional Commits](https://www.conventionalcommits.org)
294
+ (`feat:`, `fix:`, `docs:`, ...). Releases and the changelog are generated from them: see
295
+ [docs/releasing.md](https://github.com/aaajjjj/codebaton/blob/main/docs/releasing.md).
296
+
297
+ ## Disclaimer
298
+
299
+ codebaton is an independent project. It isn't affiliated with or endorsed by Anthropic,
300
+ OpenAI or Ollama. Claude, Claude Code, Codex and Ollama are trademarks of their respective
301
+ owners. You're responsible for following each provider's terms of use.
302
+
303
+ ## License
304
+
305
+ [MIT](https://github.com/aaajjjj/codebaton/blob/main/LICENSE)
@@ -0,0 +1,276 @@
1
+ # codebaton
2
+
3
+ **See your Claude Code and Codex limits live, and never lose your thread when one runs out.
4
+ No proxy, no API keys: your own subscriptions, the official CLIs.**
5
+
6
+ [![CI](https://github.com/aaajjjj/codebaton/actions/workflows/ci.yml/badge.svg)](https://github.com/aaajjjj/codebaton/actions/workflows/ci.yml)
7
+ [![PyPI](https://img.shields.io/pypi/v/codebaton)](https://pypi.org/project/codebaton/)
8
+ [![Python](https://img.shields.io/pypi/pyversions/codebaton)](https://pypi.org/project/codebaton/)
9
+ [![License: MIT](https://img.shields.io/badge/license-MIT-blue)](https://github.com/aaajjjj/codebaton/blob/main/LICENSE)
10
+
11
+ You're deep in a task with Claude Code and it says you've used most of your 5-hour limit.
12
+ codebaton sees that coming. It shows each agent's usage against a threshold you choose,
13
+ opens the agent that still has room, and passes the baton: the next agent picks up where the
14
+ last one stopped, using shared notes and git checkpoints.
15
+
16
+ ```text
17
+ $ codebaton watch
18
+ agent window usage used status
19
+ claude_code 5h ██████████████│░░░░░ 71% over threshold (threshold 70%) resets in 1h 12m
20
+ claude_code week ████░░░░░░░░░░│░░░░░ 22% ok (threshold 70%) resets in 3d 2h
21
+ codex 5h █░░░░░░░░░│░░░░░░░░░ 6% ok (threshold 50%) resets in 4h 40m
22
+ codex week ░░░░░░░░░░│░░░░░░░░░ 2% ok (threshold 50%) resets in 5d 18h
23
+ ```
24
+
25
+ - **No proxy, no API keys.** Your traffic goes straight from the official `claude` and
26
+ `codex` CLIs to their providers, on the subscriptions you already pay for. Nothing sits in
27
+ between, and nothing breaks the providers' terms the way relay proxies can.
28
+ - **Native, not a wrapper.** You get the real CLI, with full speed and every feature.
29
+ codebaton adds a status line and hooks for that session only and never touches your own
30
+ settings.
31
+ - **Real usage numbers.** These are the same percentages `/usage` shows, not token guesses.
32
+ - **Hand-over without a lost thread.** `HANDOFF.md` and `AGENTS.md` carry the goal and
33
+ progress between agents. A git checkpoint is saved after every reply.
34
+ - **Local fallback.** An optional free [Ollama](https://ollama.com) model runs on your
35
+ machine, with a memory check before anything is installed or loaded.
36
+ - **Your logins stay yours.** codebaton never reads, stores or sends credentials. Each CLI
37
+ uses its own sign-in.
38
+ - **Ready for teams.** An organisation policy file locks permissions and approved agents on
39
+ every machine, and `codebaton report` exports usage and hand-overs as JSON or CSV.
40
+
41
+ > Status: **alpha** (0.x). Tested on macOS with Claude Code and Codex CLI. Linux should work;
42
+ > Windows is untested.
43
+
44
+ ## How it works
45
+
46
+ ![codebaton component diagram: the CLI reads usage, the launcher opens Claude Code,
47
+ Codex or Ollama, session hooks save checkpoints and handoff notes. Dashed boxes show the
48
+ next milestones: quality gates, style contract, MCP server, light local harness.](https://raw.githubusercontent.com/aaajjjj/codebaton/main/docs/assets/architecture.svg)
49
+
50
+ 1. You run `codebaton` in a project.
51
+ 2. It reads each agent's usage and recommends the first one under its threshold.
52
+ 3. It opens that agent's **real CLI** in your terminal, with session-only hooks attached.
53
+ 4. After every reply, a hook saves a git checkpoint and checks usage. Near the threshold the
54
+ agent is asked to update `HANDOFF.md`; over it, you're offered the next agent, which
55
+ starts by reading that file.
56
+
57
+ More detail: [docs/architecture.md](https://github.com/aaajjjj/codebaton/blob/main/docs/architecture.md). Design decisions:
58
+ [docs/decisions.md](https://github.com/aaajjjj/codebaton/blob/main/docs/decisions.md).
59
+
60
+ ## Requirements
61
+
62
+ - Python 3.11+
63
+ - At least one agent CLI, installed and signed in:
64
+ [Claude Code](https://code.claude.com/docs) (`claude`) and/or
65
+ [Codex CLI](https://github.com/openai/codex) (`codex`, then `codex login`)
66
+ - git (progress is saved as commits)
67
+ - Optional: [Ollama](https://ollama.com) for a free local model
68
+
69
+ ## Install
70
+
71
+ ```bash
72
+ pipx install codebaton # or: uv tool install codebaton
73
+ # or: pip install codebaton
74
+ codebaton --version
75
+ ```
76
+
77
+ ## Quick start
78
+
79
+ ```bash
80
+ cd your-project # any git repository
81
+ codebaton # first run offers to set the project up
82
+ ```
83
+
84
+ ```text
85
+ claude_code 27.0% used / 50% threshold ok [week 18%, 5h 27%]
86
+ codex 2.0% used / 50% threshold ok [5h 2%, week 0%]
87
+
88
+ Which agent?
89
+ 1) claude_code 27.0% used / 50% threshold, under threshold <- recommended
90
+ 2) codex 2.0% used / 50% threshold, under threshold
91
+ 3) ollama local model llama3.2:1b, chat (answers in seconds, no edits)
92
+ q) quit
93
+ Choose (Enter = recommended):
94
+ ```
95
+
96
+ Press Enter and you're in the real Claude Code. Work as usual. When you `/exit` above the
97
+ threshold, codebaton asks **"Continue in codex?"**, and Codex starts by reading
98
+ `HANDOFF.md`.
99
+
100
+ ## Everyday commands
101
+
102
+ | Command | What it does |
103
+ |---|---|
104
+ | `codebaton` | Show usage, then open the recommended agent |
105
+ | `codebaton use claude` / `codex` / `ollama` | Open a specific agent |
106
+ | `codebaton use claude "fix the login bug"` | Open it with a first message |
107
+ | `codebaton watch` | Live usage bars with reset countdowns for every agent (`--json` for scripts and menu-bar widgets) |
108
+ | `codebaton status [--refresh]` | Usage vs thresholds (`--refresh` makes one tiny Claude call for fresh numbers) |
109
+ | `codebaton report [--since 7d]` | Sessions, hours, checkpoints and hand-overs per agent (`--json`, `--csv`) |
110
+ | `codebaton install-model` | Pick and install a local model: shows its size and the memory it needs, then asks first |
111
+ | `codebaton use ollama --chat` | Local model as a plain chat: answers in seconds, can't edit files |
112
+ | `codebaton run "<task>"` | One task, unattended (scripts, overnight), with model tiers and automatic failover |
113
+ | `codebaton help` | Everyday commands with examples |
114
+
115
+ Options: `--model haiku|sonnet|opus` starts on a tier (Codex uses its matching model);
116
+ `--repo DIR` works on another folder. Inside a session, the agent's own `/model` works as
117
+ usual.
118
+
119
+ ## What codebaton adds to a session
120
+
121
+ | | Claude Code | Codex |
122
+ |---|---|---|
123
+ | Live usage | status line: `baton · Claude · 5h 31% · wk 18% / 50% · next: Codex` | Codex's own `/status` |
124
+ | After every reply | git checkpoint if files changed | git checkpoint if files changed |
125
+ | Near the threshold | Claude is asked once to update `HANDOFF.md` | desktop notification |
126
+ | Over the threshold | "Type /exit to continue in Codex" | desktop notification |
127
+
128
+ ## Configuration
129
+
130
+ The first run creates these files in your project:
131
+
132
+ | File | Purpose | Commit it? |
133
+ |---|---|---|
134
+ | `router.yaml` | agent order, thresholds, permissions | no (added to `.gitignore`) |
135
+ | `model_routing.yaml` | which tasks go to haiku / sonnet / opus tiers | yes |
136
+ | `AGENTS.md` | project goal and conventions for every agent | yes |
137
+ | `HANDOFF.md` | current state: goal, done, next, open questions | yes |
138
+ | `decisions.log` | one line per decision | yes |
139
+
140
+ ```yaml
141
+ # router.yaml
142
+ providers: # preference order: the first one under its threshold wins
143
+ - name: claude_code
144
+ cap_percent: 50 # above 50% used (as /usage shows it), move to the next agent
145
+ - name: codex
146
+ cap_percent: 50
147
+ profile: per_session # overnight | per_session | strict
148
+ warn_margin_percent: 5 # this close to a threshold, ask the agent for a full handoff
149
+ git_checkpoint: true # commit a checkpoint after every agent reply
150
+ allow_web: false # let agents browse / search the web
151
+ allow_push: false # let agents run `git push`
152
+ allow_all_commands: false
153
+ ollama:
154
+ enabled: true
155
+ mode: agent # agent (edits code via Codex) | chat (fast, no edits)
156
+ ```
157
+
158
+ The full reference is [examples/router.example.yaml](https://github.com/aaajjjj/codebaton/blob/main/examples/router.example.yaml).
159
+
160
+ **How usage is measured.** Claude reports its 5-hour and weekly usage with every reply.
161
+ Codex writes the same figures to its local session logs. The higher of the two windows
162
+ counts. A rate-limit error marks an agent as exhausted until its window resets.
163
+
164
+ ## For teams and organisations
165
+
166
+ **Organisation policy.** IT can deploy one file to every machine (for example with MDM).
167
+ Projects can't loosen it. codebaton reads `$CODEBATON_POLICY` if set, otherwise
168
+ `/etc/codebaton/policy.yaml`:
169
+
170
+ ```yaml
171
+ # /etc/codebaton/policy.yaml
172
+ minimum_profile: per_session # projects may be stricter, never looser
173
+ deny: [push, all_commands] # switches no project can turn on (also: web)
174
+ allowed_agents: [claude_code, codex] # e.g. no local models
175
+ require_checkpoints: true
176
+ max_cap_percent: 80 # keep headroom: hand over by 80% at the latest
177
+ ```
178
+
179
+ Whenever the policy changes a project's settings, codebaton says what it enforced.
180
+
181
+ **Reporting.** `codebaton report --since 30d --json` summarises each repository's audit log
182
+ (`.codebaton/audit.jsonl`): sessions, hours, checkpoints, hand-overs and rate limits per
183
+ agent. Collect the JSON or CSV from many repositories with no server involved.
184
+
185
+ **Why it suits companies:** no proxy and no extra credentials, so no new vendor sees your
186
+ code; the official CLIs keep their own permission prompts and sandboxes; and every routing
187
+ decision is logged locally.
188
+
189
+ ## Local models (Ollama)
190
+
191
+ ```bash
192
+ codebaton install-model # choose from models that suit your machine's memory
193
+ codebaton use ollama --chat # instant answers, no file edits
194
+ codebaton use ollama # coding agent via Codex's harness (can edit files)
195
+ ```
196
+
197
+ Be realistic about speed. Agent mode sends Codex's ~47K-token instructions to the model, so
198
+ on a laptop the **first** reply takes about a minute even with a 1B model. Replies after
199
+ that take seconds. Small models also make mistakes as agents. Chat mode is the quick way to
200
+ confirm local models work. Ollama is started only when you choose it and stopped when you
201
+ exit.
202
+
203
+ ## Safety and privacy
204
+
205
+ - **Credentials:** never read or stored. `router.yaml` refuses keys that look like secrets.
206
+ - **Commits:** a checkpoint commits only the files created or changed during the agent's
207
+ turn. Work you already had uncommitted, or staged, when the session opened is left alone,
208
+ unless the agent edits that same file. Checkpoint commits are named
209
+ `chore(codebaton): ...`, hooks such as pre-commit still run, and
210
+ `git_checkpoint: false` turns them off. Unattended `codebaton run` owns the repo and
211
+ commits everything.
212
+ - **Permissions:** in interactive sessions each CLI keeps its own permission prompts. The
213
+ `allow_*` switches mainly affect unattended `codebaton run`, and they're off by
214
+ default.
215
+ - **Outside git:** codebaton warns before setting up a folder that isn't a git repository.
216
+
217
+ Report vulnerabilities privately: see [SECURITY.md](https://github.com/aaajjjj/codebaton/blob/main/SECURITY.md).
218
+
219
+ ## Roadmap
220
+
221
+ - [x] **v0.1:** native Claude Code / Codex sessions with usage routing, handoff notes, git
222
+ checkpoints, local models with memory checks
223
+ - [ ] **Milestone 2:** quality gates (tests, lint and an LLM judge after each task; a low
224
+ score moves to a stronger model) and a shared style contract
225
+ - [ ] **Milestone 3:** MCP server, so any MCP client can ask for usage, handoffs and
226
+ checkpoints
227
+ - [ ] A lighter local harness, so small local models can edit code in seconds
228
+ - [x] Live usage monitor (`watch`), team report (`report`), organisation policy
229
+ - [ ] More agents (e.g. Gemini CLI) through the provider plug-in interface
230
+ - [ ] Menu-bar widget and Linux desktop notifications
231
+
232
+ Ideas and votes are welcome in [Issues](https://github.com/aaajjjj/codebaton/issues).
233
+
234
+ ## FAQ
235
+
236
+ **Is this a proxy? Does it see my prompts?**
237
+ No. Your terminal talks directly to the agent CLI. codebaton only launches it, reads usage
238
+ numbers and saves checkpoints.
239
+
240
+ **Why not an MCP server?**
241
+ An MCP server runs inside one agent, so it can't switch you to a different agent. The CLI
242
+ does the switching. An MCP server for usage and handoff tools is on the roadmap.
243
+
244
+ **How is this different from claude-code-router or other model proxies?**
245
+ Those send your requests through a proxy to other models or API keys. codebaton never
246
+ touches the traffic: it runs the official CLIs on your own subscriptions, watches the usage
247
+ they report, and hands the work over with shared notes and git checkpoints.
248
+
249
+ **Do I need both Claude Code and Codex?**
250
+ No. With one agent you still get the status line, checkpoints and handoff notes. With Ollama
251
+ you also get a free local fallback.
252
+
253
+ ## Contributing
254
+
255
+ Contributions are welcome. Start with [CONTRIBUTING.md](https://github.com/aaajjjj/codebaton/blob/main/CONTRIBUTING.md).
256
+
257
+ ```bash
258
+ git clone https://github.com/aaajjjj/codebaton.git
259
+ cd codebaton
260
+ uv sync
261
+ scripts/check.sh # format, lint, type-check and tests, as CI runs them
262
+ ```
263
+
264
+ Commit messages follow [Conventional Commits](https://www.conventionalcommits.org)
265
+ (`feat:`, `fix:`, `docs:`, ...). Releases and the changelog are generated from them: see
266
+ [docs/releasing.md](https://github.com/aaajjjj/codebaton/blob/main/docs/releasing.md).
267
+
268
+ ## Disclaimer
269
+
270
+ codebaton is an independent project. It isn't affiliated with or endorsed by Anthropic,
271
+ OpenAI or Ollama. Claude, Claude Code, Codex and Ollama are trademarks of their respective
272
+ owners. You're responsible for following each provider's terms of use.
273
+
274
+ ## License
275
+
276
+ [MIT](https://github.com/aaajjjj/codebaton/blob/main/LICENSE)