1<!--
2SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
3
4SPDX-License-Identifier: CC0-1.0
5-->
6
7# formatted-commit
8
9<!--[](https://api.reuse.software/info/git.secluded.site/formatted-commit)-->
10
11[](https://goreportcard.com/report/git.secluded.site/formatted-commit)
12
13CLI tool that produces commits following the Conventional Commits specification
14through flags, made for LLMs and not really their operators (but I guess you can
15use this directly if you want). Operators would likely prefer, as the author
16does, [meteor](https://github.com/stefanlogue/meteor).
17
18I've found that LLMs consistently fail to
19
20- Format trailers correctly: they add too many newlines between trailers, which
21 breaks tools like `git interpret-trailers`
22- Include proper scope notation
23- Follow the loose 50/72 subject/body standard held by projects like the Linux
24 kernel. I try to stick to it, but LLMs writing badly-formatted commit messages
25 means rewording work for me once they're done.
26
27`formatted-commit` enforces all of this. Where possible, we "correct" the
28model's input. Where that's less possible, we error. For example, instead of
29requiring the model wrap body text at 72 columns, we let it write whatever body
30it wants and wrap it ourselves. We can't really fix the subject, so
31`formatted-commit` emits an error when the subject is too long with clear
32indication of where the 50-character cut-off is.
33
34## Installation
35
36As this is mostly meant for agentic coding tools, you'll need one. I like [Crush
37💘](https://github.com/charmbracelet/crush) (and maintain [a
38fork](https://git.secluded.site/crush)) or [OpenCode](https://opencode.ai/) as
39the best more-open options and [Amp](https://ampcode.com/) as the overall best
40option if you don't mind completely proprietary and paying for 100% of your API
41usage.
42
43You may install `formatted-commit` manually using the following command. You may
44also skip this and just add the prompt snippet; it tells the model about the
45command so it can try to run it on its own or ask you to run it.
46
47```bash
48go install git.secluded.site/formatted-commit@latest
49```
50
51Check for upgrades with `formatted-commit upgrade`, then apply with
52`formatted-commit upgrade -a`.
53
54Copy/paste this into wherever you tell your models how to write commits. For
55Crush, that might be `~/.config/crush/CRUSH.md` or `./CRUSH.md` in a repo. For
56[my Crush fork](https://git.secluded.site/crush) and Amp, that's
57`~/.config/AGENTS.md`. Look up where your tool checks for rules files and put
58this in a section like `## Creating git commits` or something.
59
60```markdown
61Create/amend commits exclusively using `formatted-commit`. Try to use it normally, but if it's not in my PATH, ask me to `go install git.secluded.site/formatted-commit@latest`. It has no sub-commands and the following options:
62<formatted-commit_flags>
63-t --type Commit type (required)
64-s --scope Commit scope (optional)
65-B --breaking Mark as breaking change (optional)
66-m --message Commit message (required)
67-b --body Commit body (optional)
68-T --trailer Trailer in 'Sentence-case-key: value' format (optional, repeatable)
69-a --amend Amend the previous commit (optional)
70-h --help
71</formatted-commit_flags>
72<formatted-commit_example>
73formatted-commit -t feat -s "web/git-bug" -m "do a fancy new thing" -T "Crush <crush@charm.land>" -b "$(cat <<'EOF'
74Multi-line
75
76- Body
77- Here
78
79EOF
80)"
81</formatted-commit_example>
82```
83
84## Contributions
85
86Patch requests are in [amolith/llm-projects] on [pr.pico.sh]. You don't need a
87new account to contribute, you don't need to fork this repo, you don't need to
88fiddle with `git send-email`, you don't need to faff with your email client to
89get `git request-pull` working...
90
91You just need:
92
93- Git
94- SSH
95- An SSH key
96
97```sh
98# Clone this repo, make your changes, and commit them
99# Create a new patch request with
100git format-patch origin/main --stdout | ssh pr.pico.sh pr create amolith/llm-projects
101# After potential feedback, submit a revision to an existing patch request with
102git format-patch origin/main --stdout | ssh pr.pico.sh pr add {prID}
103# List patch requests
104ssh pr.pico.sh pr ls amolith/llm-projects
105```
106
107See "How do Patch Requests work?" on [pr.pico.sh]'s home page for a more
108complete example workflow.
109
110[amolith/llm-projects]: https://pr.pico.sh/r/amolith/llm-projects
111[pr.pico.sh]: https://pr.pico.sh
112
113## Usage
114
115```text
116$ formatted-commit -h
117
118 formatted-commit helps you create well-formatted Git commits that follow
119 the Conventional Commits specification with proper subject length validation,
120 body wrapping, and trailer formatting.
121
122 USAGE
123
124 formatted-commit [command] [--flags]
125
126 EXAMPLES
127
128 # With co-author
129 formatted-commit -t feat -m "do a thing" -T "Crush <crush@charm.land>"
130
131 # Breaking change with longer body
132 formatted-commit -t feat -m "do a thing that borks a thing" -B -b "$(cat <<'EOF'
133 Multi-line
134 - Body
135 - Here
136
137 This is what borked because of new shiny, this is how migrate
138 EOF
139 )"
140
141 # Including scope for more precise changes
142 formatted-commit -t refactor -s "web/git-bug" -m "fancy shmancy" \
143 -b "Had to do a weird thing because..."
144
145 # Check for upgrades
146 formatted-commit upgrade
147
148 # Then apply
149 formatted-commit upgrade -a
150
151 COMMANDS
152
153 help [command] Help about any command
154 upgrade [--flags] Check for and apply updates
155
156 FLAGS
157
158 -a --amend Amend the previous commit (optional)
159 -b --body Commit body (optional)
160 -B --breaking Mark as breaking change (optional)
161 -h --help Help for formatted-commit
162 -m --message Commit message (required)
163 -s --scope Commit scope (optional)
164 -T --trailer Trailer in 'Sentence-case-key: value' format (optional, repeatable)
165 -t --type Commit type (required)
166 -v --version Version for formatted-commit
167```