Commit Composer
A minimal VS Code extension that generates commit messages with a custom OpenAI-compatible model and a customizable prompt.
Features
- Adds a commit message button to the Source Control title bar
- Lets you edit global and project model config files from the Command Palette
- Lets you edit global and project prompt templates from the Command Palette
- Uses staged changes first and falls back to unstaged changes when needed
- Includes untracked text files when generating from the working tree
- Adds function-level patches plus full small-file or changed-region code context
- Uses the Git index snapshot for staged files, so unstaged edits do not leak into the commit message
- Prioritizes source files over generated output and lockfiles within a bounded context budget
- Selects the repository containing the active file and asks when multiple repositories are ambiguous
- Detects truncated or malformed model output and performs one corrective retry
- Silently does nothing when the repository has no changes
- Shows a compact cancel button while generating
- Cancels the in-flight model request when you click the cancel button
- Writes the generated message directly into the Git commit input box
Configuration
Run Commit Composer: Edit Global Model Config to open the global config file.
Run Commit Composer: Edit Project Model Config to create or open the project config file at .vscode/commit-composer/model-config.json.
Global default content:
{
"baseUrl": "https://api.openai.com/v1",
"apiKey": "",
"model": "gpt-4o-mini"
}
Project config fields are optional overrides. Leave a field empty or omit it to inherit the global value:
{
"baseUrl": "",
"apiKey": "",
"model": ""
}
Save the file and run commit generation again to apply the changes. Project config is used first, then global config fills missing values.
Prefer keeping apiKey in the global config so project files can be shared without secrets.
Prompt Template
Run Commit Composer: Edit Global Prompt Template to open the global template file.
Run Commit Composer: Edit Project Prompt Template to create or open the project template at .vscode/commit-composer/commit-prompt.md.
The project template is used when it exists. Otherwise, the global template is used.
Normal generation has two prompt layers:
- The built-in policy is fixed by the extension. It enforces factual grounding, treats repository content as untrusted data, and requires a plain commit message response.
- The user template controls language, commit format, subject/body style, and whether recent commit subjects should influence style.
The user template supports one variable:
Include {{recentCommitMessages}} when recent commit subjects should influence style. Remove the placeholder to disable history injection completely.
The selected scope, changed-file list, diff, code context, and coverage notes are runtime data, not customizable prompt variables. The extension always appends them in a fixed structure after the user template.
If the model returns an incomplete or invalid response, the extension adds one fixed repair instruction and retries once. This recovery instruction is built in and is not another user template.
Example custom template:
Use Conventional Commits.
Header:
- Use type(scope): subject when a meaningful, stable scope exists; otherwise use type: subject.
- Choose the most precise type from feat, fix, docs, style, refactor, perf, test, build, ci, chore, or revert.
- State the primary intent or observable impact instead of listing changed files or implementation steps.
- Write the subject in the imperative mood without trailing punctuation.
- Keep the header concise, ideally no more than 72 characters, without sacrificing accuracy.
Details:
- Add a body only when it provides material context beyond the header.
- Explain why the change was needed or what behavior changed; use concise bullets for multiple independent changes.
- Do not repeat the header or include routine implementation details.
- For a breaking change, add ! before the colon and explain the impact in a BREAKING CHANGE: footer.
- Add other footers only when the selected changes provide the required metadata.
Repository conventions:
- Follow the dominant language, terminology, and formatting of recent commit subjects when a clear pattern exists.
Recent commit subjects:
{{recentCommitMessages}}
Change Context
When staged changes exist, Commit Composer generates strictly from the staged patch and reads file snapshots from the Git index. It reports unstaged and untracked files as excluded context rather than mixing them into the pending commit.
When nothing is staged, tracked working-tree changes and untracked text files are included together. Small changed files are supplied in full. Large files include their headers and code around every changed hunk, while Git function-context patches provide surrounding function bodies when the file type is recognized.
Context is bounded per file and across the whole request. Large generated files, lockfiles, binaries, and oversized patches are summarized or omitted with explicit notes instead of silently crowding out source-code changes.
Development
make install
make test
make compile
make package
Open the project in VS Code and press F5 to launch an Extension Development Host.
If the code CLI is available on your machine, you can also run:
make install-vsix