git-janitor 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jay Qi
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,378 @@
1
+ Metadata-Version: 2.4
2
+ Name: git-janitor
3
+ Version: 0.1.0
4
+ Summary: Gather evidence on whether local git branches and worktrees are merged on GitHub, and clean up the ones that are
5
+ Author: Jay Qi
6
+ Author-email: Jay Qi <jayqi@users.noreply.github.com>
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Requires-Dist: rich>=15.0.0
10
+ Requires-Dist: typer
11
+ Requires-Python: >=3.14
12
+ Description-Content-Type: text/markdown
13
+
14
+ # git-janitor
15
+
16
+ [![tests](https://github.com/jayqi/git-janitor/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/jayqi/git-janitor/actions/workflows/tests.yml?query=branch%3Amain)
17
+ [![coverage](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jayqi/git-janitor/badges/coverage.json)](https://github.com/jayqi/git-janitor/actions/workflows/tests.yml?query=branch%3Amain)
18
+
19
+ **Gather evidence on whether local git branches and worktrees are merged on GitHub, and clean up the ones that are.**
20
+
21
+ git-janitor gives every local branch and worktree a verdict, and deletes only the ones it can verify are merged and safe to remove. It's designed to be used by coding agents first, with JSON output, and by people second.
22
+
23
+ ```console
24
+ $ git janitor report
25
+ ┏━━━━━━━━━━━━━┳━━━━━━━━━┳━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━┓
26
+ ┃ Candidate ┃ Verdict ┃ Status ┃ Worktree ┃ Blockers ┃ Pull request ┃
27
+ ┡━━━━━━━━━━━━━╇━━━━━━━━━╇━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━┩
28
+ │ add-retries │ delete │ merged │ │ │ #1 │
29
+ │ fix-timeout │ review │ merged │ ../wt-fix-timeout │ dirty │ #2 │
30
+ │ main │ keep │ default_branch │ . │ │ │
31
+ │ new-parser │ keep │ pr_open │ │ │ #3 │
32
+ │ spike │ review │ no_pr │ │ │ │
33
+ └─────────────┴─────────┴────────────────┴───────────────────┴──────────┴──────────────┘
34
+
35
+ $ git janitor clean --all
36
+ add-retries: deleted
37
+ to recover: git branch add-retries efbdaba1a8908b6ddc54a44f1e9b87f3d1d1eb7b
38
+ ```
39
+
40
+ ## Why git-janitor
41
+
42
+ Common ways to clean up merged branches each miss something:
43
+
44
+ - **`git branch -d` and `git branch --merged`** can't tell a branch was merged with a squash or rebase merge, because its commits land as new commits.
45
+ - **Deleting branches whose upstream is gone** (`git fetch --prune`, then deleting `[gone]` branches) also deletes branches whose pull request was closed without merging, and loses work that was never pushed.
46
+ - **Matching merged pull requests by branch name** treats a new branch that reuses an old name as merged.
47
+ - **`git worktree remove --force`** deletes untracked and ignored files, like notes or plans you kept in the worktree.
48
+
49
+ git-janitor checks that a merged pull request contains each branch's exact tip, or that a merge commit in the default branch has the tip's exact contents, and that each worktree holds nothing that would be lost, before deleting anything. When it does delete:
50
+
51
+ - It never forces a deletion, and has no option to.
52
+ - It never modifies anything on GitHub or origin.
53
+ - It prints a command to recreate each deleted branch.
54
+
55
+ git-janitor only deletes what you could get back from GitHub. A branch can be deleted when its tip, the files as you last left them, is in the default branch or a merged pull request. A worktree can be removed when it holds nothing beyond its branch's tip. How a branch got to its tip, such as its commit messages and intermediate commits, isn't protected.
56
+
57
+ ## Installation
58
+
59
+ You'll need:
60
+
61
+ - Python 3.14 or newer
62
+ - `git` 2.36 or newer
63
+ - GitHub's [`gh` CLI](https://cli.github.com/), installed and logged in
64
+ - A repository whose `origin` remote is on GitHub
65
+
66
+ git-janitor is available on [PyPI](https://pypi.org/project/git-janitor/). You can use any package manager that installs from PyPI, but we recommend one made for installing command-line tools, like [uv](https://docs.astral.sh/uv/) or [pipx](https://pipx.pypa.io/):
67
+
68
+ ```sh
69
+ uv tool install git-janitor
70
+ # or
71
+ pipx install git-janitor
72
+ ```
73
+
74
+ Because the executable is named `git-janitor`, git runs it as a subcommand: `git janitor ...`.
75
+
76
+ ## Usage
77
+
78
+ ```sh
79
+ git janitor report # report on every local branch and worktree
80
+ git janitor report feat-x ../wt # report on specific branches or worktree paths
81
+ git janitor report --json # machine-readable output
82
+
83
+ git janitor clean feat-x # delete specific candidates, if their verdict is `delete`
84
+ git janitor clean --all # delete every candidate whose verdict is `delete`
85
+ git janitor clean --all --dry-run # show what would be deleted
86
+ git janitor clean feat-x --accept precious_files # delete despite reviewed precious files
87
+ ```
88
+
89
+ To run against a repository other than the current directory, use `git -C <path> janitor ...`.
90
+
91
+ For help, run `git janitor -h` or `git janitor <command> -h`. `git janitor --help` doesn't work, because git turns it into `git help janitor`, which looks for a man page that isn't installed.
92
+
93
+ > [!NOTE]
94
+ > Both commands run `git fetch origin --prune` first. Pass `--no-fetch` to skip it. Even with `--no-fetch`, git-janitor may fetch a pull request's head commit (`refs/pull/<N>/head`) when it's missing locally. If that fetch fails, the pull request is treated as not matching.
95
+
96
+ ## How git-janitor decides
97
+
98
+ The report has one row, a **candidate**, per thing that could be cleaned up:
99
+
100
+ - a branch with no worktree,
101
+ - a branch and the worktree it's checked out in, or
102
+ - a worktree with a detached HEAD, or whose branch doesn't exist (`branch_missing`).
103
+
104
+ Each candidate gets a verdict:
105
+
106
+ | Verdict | Meaning |
107
+ |---|---|
108
+ | `delete` | Status is `merged`, `merged_same_tree`, or `no_unique_commits`, and there are no blockers. `clean` will delete it. |
109
+ | `keep` | The work is active (`pr_open`), or it's the default branch. |
110
+ | `review` | Everything else. A person, or an agent investigating the evidence, needs to decide. |
111
+
112
+ The verdict comes from the candidate's **status** and its **blockers**.
113
+
114
+ ### Statuses
115
+
116
+ | Status | Meaning | Verdict |
117
+ |---|---|---|
118
+ | `merged` | A matching pull request was merged, and the merge reached the default branch (see below). | `delete`, unless blocked |
119
+ | `merged_same_tree` | A pull request was merged, its merge commit is in the default branch, and it has exactly the same contents as the local tip, as when the pull request was rebased before merging. It takes precedence over `pr_closed`, `merged_into_other_base`, `merged_plus_local`, and `no_pr` (see [Rebased pull requests](#rebased-pull-requests)). | `delete`, unless blocked |
120
+ | `no_unique_commits` | No matching pull request, and the tip is already in the default branch, so deleting it loses no commits. This includes branches created but not yet committed to, and branches fast-forwarded to the default branch. | `delete`, unless blocked |
121
+ | `merged_plus_local` | A pull request was merged, and the merge reached the default branch, but the local tip has commits beyond its head. | `review` |
122
+ | `pr_open` | A matching pull request is open, or an open pull request's head is behind the local tip. Any open matching pull request takes precedence over closed or merged ones. | `keep` |
123
+ | `pr_closed` | A matching pull request was closed without merging. | `review` |
124
+ | `merged_into_other_base` | A matching pull request was merged into a branch other than the default branch, and its merge commit isn't in the default branch. | `review` |
125
+ | `no_pr` | No matching pull request, and the tip has commits that aren't in the default branch. | `review` |
126
+ | `default_branch` | This is the default branch. It is never deleted. | `keep` |
127
+ | `branch_missing` | A worktree whose branch has no commits yet or no longer exists as a local branch. | `review` |
128
+
129
+ ### What counts as merged
130
+
131
+ For each branch, git-janitor looks up pull requests on origin whose head branch has the same name as the local branch or its upstream on origin. A branch is `merged` when both of these are true:
132
+
133
+ 1. **A pull request contains the branch's local tip.** The tip is the pull request's head commit, or an ancestor of the head that isn't already in the default branch.
134
+ 2. **That pull request's merge reached the default branch.** Its base is the default branch, or its merge commit is in the default branch.
135
+
136
+ With squash and rebase merges, the branch's own commits never appear in the default branch. What's checked is that the pull request containing them was merged.
137
+
138
+ > [!IMPORTANT]
139
+ > A merged pull request with the same branch name isn't enough. Requiring that the tip isn't already in the default branch stops a branch created from older history, such as a new branch reusing a merged pull request's name, from matching. Pull requests that share the name but don't match are reported as evidence. They can still count by having an identical tree (see [Rebased pull requests](#rebased-pull-requests)), so a reused branch name only matches when the branch's contents are identical to that pull request's merge commit, which is already in the default branch.
140
+
141
+ Only pull requests into origin itself count, not ones into other repositories in its fork network. The default branch comes from GitHub.
142
+
143
+ #### Stacked pull requests
144
+
145
+ When GitHub merges a stack of pull requests, each one keeps the branch below it as its base, but its merge commit is created on the default branch. Rule 2 counts these as merged.
146
+
147
+ It also counts a pull request merged into a branch whose history, including that merge commit, was later merged into the default branch. If that branch was squash- or rebase-merged instead, the merge commit isn't in the default branch, and the pull request is `merged_into_other_base`.
148
+
149
+ #### Rebased pull requests
150
+
151
+ When GitHub or a tool like `gh stack` rebases a pull request before merging it, for example after the pull request below it in a stack was merged, it force-pushes a new head. The local branch still points at the old head, which is neither the new head nor an ancestor of it, so the pull request doesn't match.
152
+
153
+ git-janitor then compares contents instead. A tip is `merged_same_tree` when, among the merged pull requests found for it, one has a merge commit that:
154
+
155
+ 1. is present locally. With `--no-fetch`, it may be missing.
156
+ 2. is in the default branch.
157
+ 3. has the same tree as the local tip: the same tree object ID, so the same files with the same contents and modes, and the same submodule commits.
158
+
159
+ If several match, the highest-numbered one is reported. This check only replaces statuses whose verdict would otherwise be `review`: `pr_closed`, `merged_into_other_base`, `merged_plus_local`, and `no_pr`. It never overrides `pr_open`, `merged`, or `no_unique_commits`.
160
+
161
+ `merged_same_tree` guarantees that the tip's contents are in the default branch's history, not that its commits are. Their messages and intermediate commits aren't protected.
162
+
163
+ The trees must be identical, so the default branch can't have any changes the local tip lacks. Merges of the pull requests below it in a stack are fine, since the tip already has their changes. A pull request that was rebased because the default branch moved never matches, and its branch stays at `review`. The same check covers a branch that merged the default branch after its pull request was merged, as long as the default branch was still at the merge commit when the branch merged it.
164
+
165
+ #### Detached worktrees
166
+
167
+ A worktree with a detached HEAD is judged by its HEAD commit, against the pull requests GitHub associates with that commit: a pull request's own commits and its merge commit. An example is a worktree checked out at a pull request's head for review.
168
+
169
+ A worktree in the middle of a rebase or bisect is detached too, but git-janitor reports it with the branch the rebase or bisect started from.
170
+
171
+ ### Blockers
172
+
173
+ Blockers are reasons a worktree shouldn't be removed yet. Any blocker downgrades a `merged`, `merged_same_tree`, or `no_unique_commits` candidate to `review`.
174
+
175
+ | Blocker | Meaning |
176
+ |---|---|
177
+ | `dirty` | The worktree has modified or staged tracked files. This includes edited files marked `--skip-worktree` or `--assume-unchanged`, which `git status` doesn't show, and marked files that can't be compared with the index, such as symlinks. |
178
+ | `untracked` | The worktree has untracked files that aren't ignored. A directory with nothing tracked in it is listed once, ending in `/`. |
179
+ | `precious_files` | The worktree has ignored files that look like personal work (see [Precious ignored files](#precious-ignored-files)). |
180
+ | `locked` | The worktree is locked with `git worktree lock`. A worktree whose directory is missing can only get this blocker and `submodules`. |
181
+ | `in_progress_op` | A rebase, merge, cherry-pick, revert, or bisect is in progress in the worktree. |
182
+ | `is_current` | The directory git-janitor runs in is inside the worktree. With `git -C <path>`, that's `<path>`, not your shell's current directory. |
183
+ | `is_main` | The branch is checked out in the main worktree, which is never removed. |
184
+ | `submodules` | The worktree has or previously had checked-out submodules, whose repositories are still in its git directory. `paths` lists the ones checked out now. See [Worktrees with submodules](#worktrees-with-submodules). |
185
+ | `nested_repository` | A git repository is inside a precious ignored directory. |
186
+ | `unreadable` | Some ignored paths couldn't be read, so git-janitor can't tell whether they're precious. |
187
+ | `recent_activity` | A `no_unique_commits` worktree, which an agent may have just created, was active within `janitor.minAge` (see [Activity](#activity)), or has no recorded activity. |
188
+ | `error` | Checking the worktree failed. `detail` has the error. |
189
+
190
+ #### Activity
191
+
192
+ Each candidate's `last_activity` is the latest of:
193
+
194
+ - its branch's reflog,
195
+ - its linked worktree's HEAD reflog, and
196
+ - when its linked worktree was created.
197
+
198
+ These are read from git's records for the worktree, so they work when the worktree's directory is missing, and ordinary commands like `git status` don't change them. Activity in the main worktree isn't included.
199
+
200
+ `no_unique_commits` worktrees only get the `delete` verdict once they've been inactive for `janitor.minAge`, 7 days by default. See [Configuration](#configuration).
201
+
202
+ #### Precious ignored files
203
+
204
+ `git worktree remove` deletes ignored files without warning, so git-janitor checks them first. An ignored file is classified as follows:
205
+
206
+ - Matched by a `.gitignore` file committed to the repository: **disposable**. These are things the project generates, like `.venv/` or `build/`, and git-janitor doesn't look inside them. A `.gitignore` that isn't committed, such as `notes/.gitignore` containing `*`, doesn't count.
207
+ - Matched by your global excludes file (`core.excludesFile`) or `.git/info/exclude`: **precious**. These are things you set aside personally, like `.plans/`.
208
+ - Inside a cache directory, marked by a [`CACHEDIR.TAG`](https://bford.info/cachedir/) file: **disposable**. Tools like uv, ruff, and pytest create these, along with an uncommitted `.gitignore` that ignores their contents.
209
+ - Common operating-system, editor, and virtual environment files: always **disposable**, even when matched by your global excludes. These are `.DS_Store`, `Thumbs.db`, `desktop.ini`, `.idea/`, `.vscode/`, `.venv/`, and `*~`. Editor swap files like `*.swp` are not, since they may hold unsaved changes.
210
+ - Anything git-janitor can't attribute to an ignore rule: **precious**.
211
+
212
+ Precious files are reported per ignored path, as `git status --ignored` lists it. A directory like `.plans/` is one entry with its number of precious files, their total size, and the latest modification time. Git repositories and other worktrees inside precious directories are reported as `nested_repository` instead.
213
+
214
+ To mark more patterns as disposable, use `janitor.disposable`. See [Configuration](#configuration).
215
+
216
+ ## Cleaning up
217
+
218
+ `git janitor clean` takes candidate ids, or `--all` for every candidate whose verdict is `delete`. Running it with neither, or with both, is an error.
219
+
220
+ - It always re-runs the analysis and refuses any target whose verdict isn't `delete`. There is no option to force it.
221
+ - Right before removing a worktree, it checks again that the worktree has no blockers other than accepted ones. It deletes a branch only if the branch still points at the analyzed tip and isn't checked out anywhere. Otherwise the target is `failed`.
222
+ - It removes the worktree with `git worktree remove` (without `--force`), then deletes the branch and its `branch.<name>` config.
223
+ - It only touches local branches and worktrees. It never deletes anything on GitHub.
224
+ - It prints the tip commit of each deleted branch and a command to recreate it, such as `git branch feat-x 4f1c0de`. This works until git garbage-collects the commit.
225
+
226
+ ### Accepting blockers
227
+
228
+ `--accept <codes>` ignores the listed blockers for explicitly named targets, after you or an agent have reviewed them.
229
+
230
+ - Only two blockers can be accepted: `precious_files`, whose contents git-janitor lists, and `recent_activity`, which only protects worktrees that may be in use.
231
+ - For other blockers, such as `dirty`, `untracked`, or `nested_repository`, move, commit, or delete what they report first. For `submodules`, see [Worktrees with submodules](#worktrees-with-submodules).
232
+ - `--accept` can't be combined with `--all`.
233
+ - Outcomes list the accepted blockers in full in `accepted`, with the same fields as in the report, and keep the candidate's own `verdict`.
234
+
235
+ > [!WARNING]
236
+ > Accepting `precious_files` covers whatever precious files exist when `clean` runs, including ones added since the report you reviewed.
237
+
238
+ ### Worktrees with submodules
239
+
240
+ git-janitor can't remove a worktree that has or previously had checked-out submodules, because `git worktree remove` refuses it without `--force`. A submodule's repository stays in the worktree's git directory even after the submodule is deinitialized. Removing the worktree deletes those repositories, and git-janitor doesn't check inside them.
241
+
242
+ If you only update the submodules to upstream commits, there's nothing in them to lose. If you committed, stashed, or changed files inside a submodule in this worktree, push or move that work first.
243
+
244
+ To remove the worktree, run these from its top-level directory, then run `git janitor clean <target>` from outside it:
245
+
246
+ ```sh
247
+ rm -rf <path> && mkdir <path> # for each of the blocker's paths
248
+ rm -rf "$(git rev-parse --absolute-git-dir)/modules"
249
+ ```
250
+
251
+ If the worktree's directory is missing, delete `worktrees/<id>/modules` in the repository's git directory instead, where `<id>` is usually the name of the worktree's directory.
252
+
253
+ Don't use `git submodule deinit` in place of the first command. In a linked worktree, it also removes the submodule's settings from the repository's shared config, which unregisters the submodule for every worktree.
254
+
255
+ ## Configuration
256
+
257
+ git-janitor reads these git config keys:
258
+
259
+ | Key | Meaning |
260
+ |---|---|
261
+ | `janitor.minAge` | How long a `no_unique_commits` worktree must be inactive before it can be deleted. A duration like `3d`, `12h`, `30m`, or `0`. Default: `7d`. |
262
+ | `janitor.disposable` | Extra file or directory name patterns for ignored files that are always disposable. Can be set multiple times. Each pattern is matched against single file and directory names, so a pattern containing `/` never matches. |
263
+
264
+ ```sh
265
+ git config --global janitor.minAge 3d
266
+ git config --global --add janitor.disposable '.envrc'
267
+ ```
268
+
269
+ ## JSON output
270
+
271
+ ### `report --json`
272
+
273
+ `git janitor report --json` prints an object like this:
274
+
275
+ ```json
276
+ {
277
+ "schema_version": 1,
278
+ "repo": "/Users/me/repos/project",
279
+ "github_repo": "owner/project",
280
+ "default_branch": "main",
281
+ "fetched": true,
282
+ "candidates": [
283
+ {
284
+ "id": "feat-x",
285
+ "verdict": "delete",
286
+ "status": "merged",
287
+ "branch": {
288
+ "name": "feat-x",
289
+ "tip": "4f1c0de...",
290
+ "upstream": "origin/feat-x",
291
+ "upstream_gone": true
292
+ },
293
+ "worktree": {
294
+ "path": "/Users/me/repos/project-feat-x",
295
+ "head": "4f1c0de...",
296
+ "detached": false,
297
+ "is_main": false,
298
+ "locked": false,
299
+ "prunable": false
300
+ },
301
+ "blockers": [],
302
+ "evidence": [
303
+ {
304
+ "kind": "pull_request",
305
+ "number": 42,
306
+ "url": "https://github.com/owner/project/pull/42",
307
+ "state": "MERGED",
308
+ "base": "main",
309
+ "head_oid": "4f1c0de...",
310
+ "merge_oid": "9a2b7e1...",
311
+ "matched": true
312
+ }
313
+ ],
314
+ "actions": [
315
+ {"kind": "remove_worktree", "path": "/Users/me/repos/project-feat-x"},
316
+ {"kind": "delete_branch", "name": "feat-x", "tip": "4f1c0de..."}
317
+ ],
318
+ "last_activity": "2026-10-20T14:03:12+00:00"
319
+ }
320
+ ]
321
+ }
322
+ ```
323
+
324
+ - `repo` is the path of the main worktree, wherever the command was run from.
325
+ - `id` is the branch name, or the worktree path for a detached worktree. Pass it to `report` or `clean` as a target.
326
+ - `branch` or `worktree` is `null` when the candidate doesn't have one.
327
+ - `blockers` are objects with a `code` from the [blockers table](#blockers) and a human-readable `detail`. Some have more fields:
328
+ - `paths`, relative to the worktree: `dirty`, `untracked`, `submodules`, `nested_repository`, and `unreadable`.
329
+ - `entries`: `precious_files`. Each entry has a `path`, ending in `/` for a directory, its `files` count, total `size` in bytes, and latest `modified` time.
330
+ - `operation`: `in_progress_op`. One of `merge`, `rebase`, `cherry-pick`, `revert`, or `bisect`.
331
+ - `min_age`: `recent_activity`, like `7d`.
332
+ - `evidence` holds the pull requests found for the branch name, or for a detached worktree, associated with its HEAD commit. They're newest first, whether or not they matched. `matched` means the pull request contains the local tip, as described in [What counts as merged](#what-counts-as-merged).
333
+ - `merge_oid` is the pull request's merge commit, or `null` if it isn't merged.
334
+ - When the local tip is beyond a pull request's head (`merged_plus_local`, or `pr_open` with unpushed commits), `evidence` also holds an `extra_commits` entry. It has that `pull_request` number and a `commits` list with the `sha` and `subject` of each commit beyond the head that isn't in the default branch, oldest first.
335
+ - When the status is `merged_same_tree`, `evidence` ends with a `same_tree` entry: `{"kind": "same_tree", "pull_request": 42, "merge_oid": "9a2b7e1..."}`. It has the number of the pull request whose merge commit has the local tip's tree, and that merge commit. That pull request decides the status, whatever its `matched` value.
336
+ - `actions` lists, in order, what `clean` would do.
337
+ - `last_activity` is an ISO 8601 time, or `null` if git has no record of activity.
338
+
339
+ ### `clean --json`
340
+
341
+ `git janitor clean --json` prints the outcome for each target:
342
+
343
+ ```json
344
+ {
345
+ "schema_version": 1,
346
+ "dry_run": false,
347
+ "outcomes": [
348
+ {
349
+ "id": "feat-x",
350
+ "outcome": "deleted",
351
+ "verdict": "delete",
352
+ "detail": "",
353
+ "actions": [{"kind": "delete_branch", "name": "feat-x", "tip": "4f1c0de..."}],
354
+ "recovery": ["git branch feat-x 4f1c0de..."],
355
+ "accepted": []
356
+ }
357
+ ]
358
+ }
359
+ ```
360
+
361
+ `outcome` is one of:
362
+
363
+ - `deleted`
364
+ - `would_delete`, with `--dry-run`
365
+ - `refused`: the verdict isn't `delete`
366
+ - `not_found`, with `verdict: null`
367
+ - `failed`: an action failed or its target changed since the analysis. `detail` says why.
368
+
369
+ `actions` are the candidate's planned actions. `recovery` covers only the actions that were carried out, or would be with `--dry-run`.
370
+
371
+ `schema_version` increases whenever the shape of either output changes incompatibly. New `status` values, evidence kinds, and blocker codes don't count as incompatible, so accept ones you don't recognize.
372
+
373
+ ## Exit codes
374
+
375
+ | Code | Meaning |
376
+ |---|---|
377
+ | `0` | The command ran. For `report`, this is true whatever the verdicts are. |
378
+ | `1` | The tool couldn't run (not a git repository, `gh` missing or not logged in, fetch failed, origin's default branch not fetched), a target doesn't exist, or `clean` refused or failed to delete a target. |