Skip to content

vitormcampos/vscode-opencode-generate-commit-message

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenCode Commit Message

Generate Conventional Commit messages using OpenCode CLI. Adds a button to the Source Control panel that instructs OpenCode to analyze your Git repository and auto-fills the commit message input box.

How It Works

  1. You click Generate Commit Message in the Source Control panel
  2. The extension detects whether you have staged or unstaged changes
  3. OpenCode CLI runs inside your project directory with a prompt instructing it to analyze the repository
  4. OpenCode (an AI agent) inspects the Git diff, staged files, and changes on its own
  5. The generated Conventional Commit message is inserted into the SCM input box
  6. You review, edit, and commit as usual

No diff content is ever passed as a CLI argument — OpenCode runs directly in your repo and has full access to analyze it.

Features

  • One-click commit message generation — Button in the Source Control panel
  • Conventional Commits — Messages follow the feat:, fix:, chore:, etc. format
  • Smart change detection — Uses staged changes when available; falls back to unstaged
  • Customizable prompt — Configure the instruction sent to OpenCode ({changes} placeholder for "staged" or "unstaged")
  • Configurable timeout — Set max wait time for message generation (default 60s)
  • Non-blocking — Async with progress indicator and cancellation support
  • Safe — Never overwrites existing messages without confirmation; never commits automatically
  • No external API calls — Everything runs through your local OpenCode CLI
  • Works offline — Zero network dependencies

Requirements

  • VS Code 1.85+ or VS Codium
  • OpenCode CLI installed and available in your PATH (or configured via settings)
  • Git repository open in VS Code

Installation

From VS Code Marketplace

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "OpenCode Commit Message"
  4. Click Install

From VSIX

  1. Download the .vsix file from the releases page
  2. In VS Code, go to Extensions > ... > Install from VSIX...
  3. Select the downloaded file

From Source

git clone https://github.com/vitormcampos/vscode-opencode-generate-commit-message.git
cd vscode-opencode-generate-commit-message
npm install
npm run compile
code --extensionDevelopmentPath=.

Configuration

Access settings via Ctrl+, (or Cmd+, on macOS) and search for "OpenCode Commit".

Setting Type Default Description
opencodeCommit.opencode.path string "opencode" Path or command name for the OpenCode CLI executable. If OpenCode is in your PATH, the default works. Otherwise, set the full path (e.g., /usr/local/bin/opencode).
opencodeCommit.opencode.prompt string (see below) Prompt template sent to OpenCode. Use {changes} for "staged"/"unstaged". {diff} is also supported for backward compatibility.
opencodeCommit.opencode.timeout number 60000 Maximum time (ms) to wait for OpenCode CLI to respond. Range: 5000–300000.

Default Prompt

Analyze the {changes} changes in this Git repository and generate a concise commit
message. Use the Conventional Commits format (e.g., feat:, fix:, chore:, docs:,
refactor:, style:, test:, perf:). Write the message in English. Keep the subject
line under 72 characters. Return ONLY the commit message, no explanations, no
markdown formatting.

The {changes} placeholder is replaced with "staged" or "unstaged" depending on what the extension detected. OpenCode runs inside the project directory and analyzes the repository directly — it does not need the diff to be passed to it.

Usage

  1. Open the Source Control panel (Ctrl+Shift+G / Cmd+Shift+G)
  2. Make changes to your repository (and optionally stage them with git add)
  3. Click the Generate Commit Message button (sparkle icon) in the Source Control view header or repository header
  4. OpenCode analyzes the repository and generates a message
  5. The generated message is inserted into the commit message input box
  6. Review, edit if needed, and commit as usual

Behavior Details

  • Staged changes take priority. If you have staged files, the prompt says "staged" and OpenCode looks at staged changes
  • No staged changes? The prompt says "unstaged" and OpenCode analyzes the working tree
  • No changes at all? You'll see a notification — nothing to generate
  • Existing message? You'll be prompted before overwriting (with "Yes" / "No" buttons)

Error Scenarios

Issue What happens
OpenCode CLI not found Error message with instructions to configure opencodeCommit.opencode.path
No Git repository Command hidden from UI; error shown if triggered via command palette
No changes detected Informational message
OpenCode times out Error message with suggestion to increase opencodeCommit.opencode.timeout
OpenCode returns empty Warning message; existing input box content is preserved
Operation cancelled Clean abort — no changes to the input box

Architecture

User clicks button
       │
       ▼
┌─────────────────┐
│  extension.ts   │  Reads config, validates opencodePath,
│  (orchestrator) │  gets Git repo, checks staged/unstaged
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  opencodeRunner │  spawn('opencode', ['run', prompt],
│    .run()       │    { cwd: repoRoot })
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  OpenCode CLI   │  Runs inside the project directory.
│  (AI agent)     │  Inspects git diff, files, and changes
│                 │  independently using its own tools.
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  extension.ts   │  Parses the response, sets repo.inputBox.value
└─────────────────┘

Project Structure

src/
├── extension.ts         # Entry point: activate, command registration, orchestration
├── config.ts            # Reads extension settings (path, prompt, timeout)
├── outputChannel.ts     # Singleton OutputChannel for logging
├── gitService.ts        # Wraps the VS Code Git Extension API
├── opencodeRunner.ts    # Executes OpenCode CLI via child_process
└── test/
    ├── runTest.ts       # VS Code test runner bootstrap
    └── suite/
        ├── index.ts     # Mocha test loader
        └── extension.test.ts  # Unit tests

Development

# Clone and setup
git clone https://github.com/vitormcampos/vscode-opencode-generate-commit-message.git
cd vscode-opencode-generate-commit-message
npm install

# Compile
npm run compile

# Watch mode (auto-compile on save)
npm run watch

# Run tests
npm test

# Launch extension in VS Code dev mode
code --extensionDevelopmentPath=.

Publishing

# Package the extension
npx vsce package

# Publish to VS Code Marketplace
npx vsce publish

# Publish to Open VSX
npx ovsx publish

License

MIT

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors