Global OpenCode plugin that registers Git tools and automatically guides the AI to use them instead of raw git bash commands.
- 8 Git tools:
gitStatus,gitDiff,gitLog,gitTree,gitBranch,gitCommit,gitStash,gitPrecommitReview - Auto-context injection: When working inside a Git repo, the plugin injects tool guidance into the first user message
- Compaction context: Git workflow hints survive session compaction
- Slash commands:
/git-status,/git-tree,/git-commit,/git-review - Optional pre-commit hook: Calls
opencode run gitPrecommitReviewbefore commits
OpenCode loads plugins from ~/.config/opencode/plugins/ automatically at startup.
Windows
powershell -ExecutionPolicy Bypass -File .\install.ps1Linux / macOS
bash install.shAdd --hooks (or -Hooks on Windows) to also install pre-commit hooks in the current git project.
| Path | Purpose |
|---|---|
~/.config/opencode/plugins/opencode-git-tools.ts |
Plugin entrypoint |
~/.config/opencode/commands/git-*.md |
Slash commands |
~/.config/opencode/package.json |
Local plugin dependency metadata |
This plugin is a single TypeScript entrypoint, so it is safe to install directly
in the plugins root. Plugins with helper modules should use a subdirectory with
an index.ts entrypoint.
| Script | Purpose |
|---|---|
install.ps1 / install.sh |
Global plugin (+ optional hooks) |
install-global.ps1 / install-global.sh |
Global plugin only |
setup-git-hooks.ps1 / setup-git-hooks.sh |
Project hooks only |
node scripts/install-global.mjs |
Global plugin (Node direct) |
After install, restart OpenCode.
opencode run "call gitStatus and show the result"Or in the TUI, run /git-status.
Install pre-commit hooks in the current git project:
node scripts/install-git-hooks.mjsOr use the legacy scripts:
powershell -ExecutionPolicy Bypass -File .\setup-git-hooks.ps1bash setup-git-hooks.shRegister in ~/.config/opencode/opencode.jsonc:
See opencode.json.example for a full config snippet.
You have git* plugin tools. Prefer them over raw shell git commands,
especially on Windows where long command strings and CRLF warnings make terminal
output noisy.
| Task | Tool |
|---|---|
| See current worktree state | gitStatus |
| Review unstaged or staged changes | gitDiff |
| Inspect recent commits | gitLog |
| See branch topology | gitTree |
| List/create/switch branches | gitBranch |
| Stage and commit | gitCommit |
| Stash work | gitStash |
| Review staged diff before commit | gitPrecommitReview |
Commit workflow: gitStatus → gitDiff → gitPrecommitReview →
gitCommit.
| Situation | Use instead |
|---|---|
| Non-git file search | Read / Grep / codebase-memory-mcp |
| Bash-specific scripts | bashExec from git-bash-opencode-plugin |
| User explicitly asks for raw command output | Shell is OK, but explain why |
| Destructive git operations | Ask first |
- Use
gitCommitinstead ofgit commit -m; it writes messages through a file - Keep commit subjects <= 72 chars; put details in the body
- Run
gitPrecommitReviewbefore committing staged changes - Do not run
git reset --hard, force push, or delete branches without user confirmation - Pair with git-bash-opencode-plugin for Unix shell tools
- When editing plugin code, keep
git -c advice.convertCRLF=falseas separate argv tokens; do not interpolate"-c advice.convertCRLF=false"as one string - Never pass
""as an optional argv placeholder; branch the command instead and filter empty file path strings beforegit add
- Plugin tools — Registered globally; OpenCode exposes them to the agent like built-in tools.
- Message transform hook — In a Git repo, injects
<GIT_TOOLS_PLUGIN>guidance so the model prefersgit*tools. - Compaction hook — Re-injects Git tool reminders when context is compacted.
- Slash commands — Explicit workflows (
/git-commit, etc.) that reference plugin tools by name.
- OpenCode Tools 製作流程參考 — 從零建立 Plugin、自訂 Tools、Hooks、Slash Commands 的完整步驟(含本專案實作解析、檢查清單與最小範本)
src/index.ts # Main plugin (tools + hooks)
commands/ # Global slash commands (copied on install)
docs/ # Developer guides
hooks/ # Optional git pre-commit hooks
scripts/ # install-global.mjs, install-git-hooks.mjs
| Tool | Description |
|---|---|
gitStatus |
Working tree status |
gitDiff |
Unstaged, staged, or ref diff |
gitLog |
Recent commits |
gitTree |
Commit graph with branch topology |
gitBranch |
List / create / switch branches |
gitCommit |
Stage and commit (quiet output, formatted summary) |
gitStash |
Stash push / pop / list / drop |
gitPrecommitReview |
Review staged changes before commit |
{ "plugin": ["opencode-git-tools"] }