Mastering OpenCode for FullStack Devs: Automating Git Commits with Commands
Introduction
This article is part of a series where we will learn how to use OpenCode. As I explore it, I'll be sharing my journey with fellow Full-Stack devs so we can discover it altogether. Let's dive in!
If you've ever finished a solid coding session and then stared blankly at your terminal trying to remember what you actually changed — this article is for you. We're going to build a custom OpenCode command called /double-check that does three things automatically: reviews your last code change before it reaches GitHub, reads your previous commit, increments the commit number, and generates a structured new commit message — all in one shot.
No copy-pasting. No mental overhead. Just one command.
What is OpenCode and Why Custom Commands?
OpenCode is an open source AI coding agent built for the terminal. opencode It brings the power of large language models directly into your development workflow without leaving the command line.
One of its most powerful and underused features is Custom Commands. Custom commands are predefined prompts stored as Markdown files. Each .md file in the designated directories becomes a custom command, where the file name becomes the command ID.
This means you can encode entire workflows — review logic, Git conventions, formatting rules — into a single slash command that the AI inside OpenCode will follow precisely.
The Problem We're Solving
Every developer has a commit message convention. Mine looks like this:
03) Refactoring Auth Layer
* CONCLUDED:
1 Removed legacy token handler
2 Replaced with JWT middleware
3 Updated route guards
* WORKING:
Implementing refresh token logic
* NEXT STEPS:
Write unit tests for middleware
* FUTURE FEATURES
OAuth2 support
-----------------------------------------------------------------------
The problem? Every time I committed, I had to:
Tedious, error-prone, and a total flow-killer right at the finish line.
The Solution: The '/double-check' Command
TO BEGIN WITH... EVERYTHING THAT IS GOOD... IT HAS A PRICE... SO DONT FORGET... IN, AI TIMES, EVERYTHING COST 'TOKENS'... ONCE THE DISCLAIMER WAS DONE... LET'S DIVE IN...
We built a single command that acts as the final safety gate before any code touches GitHub. It operates in three sequential parts.
Part 1 — The Code Reviewer
The first half of the command locks the AI into a strict auditor role focused exclusively on the last thing it just delivered. It is not allowed to look at old sessions or unrelated code — scope is locked tight.
It checks three things:
The AI opens its response with a mandatory confirmation phrase, then outputs one of three traffic light signals:
If the signal is red or yellow, it describes exactly what failed and delivers the corrected version. If green, it moves immediately to Part 2.
Part 2 — The Intelligent Commit Builder
This is where the automation gets interesting. Instead of asking you to type anything, the command uses OpenCode's shell interpolation feature to capture your last commit automatically:
Recommended by LinkedIn
!`git log -1 --pretty=%B`
This backtick expression runs the moment you type /double-check — injecting the real commit content directly into the AI's context. No manual copy-paste required.
From that captured commit, the AI executes five precise steps:
Step 1 — Extract the commit number It reads the first line of the captured commit (NN) Title) and pulls out the number.
Step 2 — Increment It adds 1 to that number, preserving zero-padding. 02 becomes 03, 09 becomes 10.
Step 3 — Generate the new CONCLUDED section Based exclusively on what it just built in the previous response, it writes 3 to 5 concise, technical bullet points describing what was done. Maximum one line each.
Step 4 — Preserve everything else The WORKING, NEXT STEPS, and FUTURE FEATURES blocks are copied from the captured commit without touching a single character.
Step 5 — Present the full draft The AI assembles and displays the complete new commit message for your review before anything is committed.
Part 3 — The Git Execution
Only after you approve the draft does the command release the Git block. It uses --amend with the editor — not -m with an inline string — because multiline commit messages with special characters are fragile inside shell quotes.
The commands are delivered one per line, with && strictly forbidden:
git add .
git commit --allow-empty -m "placeholder"
git commit --amend
git push origin main
When git commit --amend opens your editor, you paste the approved draft, save, and close. Clean, auditable, and safe.
The Frontmatter: Making it a Valid OpenCode Command
Every OpenCode custom command requires a YAML frontmatter block at the top of the .md file. Two important notes from real-world debugging:
---
description: "Double check pre-GitHub: functional review + intelligent commit auto-generated"
agent: build
---
Save the file as double-check.md in your OpenCode commands directory:
The Complete Command
---
description: "Double check pre-GitHub: functional review + intelligent commit auto-generated"
agent: build
---
You are the final safety barrier before my code reaches GitHub.
### 🛑 STRICT SCOPE LIMITER (VERY IMPORTANT)
Do not look at previous procedures from our chat. Your role is to audit **EXCLUSIVELY AND STRICTLY the last task you just processed and delivered in the response immediately before this command**. Only that — nothing else.
### 🎯 YOUR MISSION (MENTAL TEST OF THE LAST TASK)
Perform a thorough review and audit:
1. Go through everything you did in the previous cycle, step by step;
2. Run a critical fine-tooth comb, mentally simulating real execution;
3. After that mental simulation, answer me with absolute functional certainty:
"Has this code, validated step by step, going to WORK ON THE FIRST TRY in the final environment — or did we miss something that will break everything?"
Check the immediately previous delivery looking for:
1. **Ghost references:** Did we call a method we forgot to create in this round?
2. **Syntax holes:** Missing semicolons, unclosed quotes, loose typos?
3. **Direct functionality:** Can the developer copy this right now, paste it into the IDE, and have it run without crashing?
### 🗣️ MANDATORY OPENING CONFIRMATION
Begin your response strictly with the following phrase:
> *"🔎 REVIEWER MODE ON! I am looking EXCLUSIVELY at our last delivery that was just completed. I will review what I did step by step and run a mental fine-tooth comb to ensure that, when pushed to GitHub right now, this change will run smoothly on the first try."*
---
## YOUR RESPONSE FORMAT:
### 🚦 WILL IT WORK ON THE FIRST TRY?
Explicitly state your current status ONLY regarding the last processed block:
- [✅ GREEN LIGHT: Yes, I checked our last action step by step and it will run on the first try!]
- [🟡 YELLOW LIGHT: In theory yes, but I noticed an alert in the structure of this exact last change...]
- [🔴 RED LIGHT: I MADE A MISTAKE! I just reviewed my last code and left a gap. Fixing it now!]
### 🛠️ FIXES FOUND
*(Fill in only if you found a breaking error during your step-by-step. If nothing was found, write exactly: "The last change passed 100% with no errors.")*
- What failed: ...
- How it is corrected now: ...
---
### ✅ GITHUB FLOW (EXECUTE ONLY IF GREEN LIGHT)
The content of the last commit was automatically captured below:
!`git log -1 --pretty=%B`
**STEP 1 — Extract the commit number**
Read the first line above. The format is: `NN) Commit title`
Extract the number `NN`.
**STEP 2 — Calculate the next number**
Add +1 keeping the leading zero.
Examples: `02` → `03`, `09` → `10`, `14` → `15`
**STEP 3 — Build the new CONCLUDED section**
Based EXCLUSIVELY on what you just implemented in the response immediately before this command, generate 3 to 5 numbered, concise, technical bullet points describing what was done. Maximum one line each.
**STEP 4 — Preserve the rest**
Copy the `* WORKING:`, `* NEXT STEPS:` and `* FUTURE FEATURES` blocks from the commit captured above exactly as they are. Do not change a single character.
**STEP 5 — Present the complete draft** in this exact format:
```
NN) Commit title
* CONCLUDED:
1 [topic generated by you]
2 [topic generated by you]
3 [topic generated by you]
* WORKING:
[copied from previous commit unchanged]
* NEXT STEPS:
[copied from previous commit unchanged]
* FUTURE FEATURES
[copied from previous commit unchanged]
-----------------------------------------------------------------------
```
**End your response OBLIGATORILY with this exact question:**
`"❓ Does the draft look good, or would you like to adjust any topic before I generate the Git commands?"`
---
### 🚀 AFTER USER CONFIRMATION
If the user confirms (replies with "go", "yes", "send it", "go ahead" or similar), deliver EXCLUSIVELY this block, one command per line, with `&&` strictly forbidden:
```bash
git add .
git commit --allow-empty -m "placeholder"
git commit --amend
git push origin main
```
> ⚠️ When `git commit --amend` opens the editor, replace the placeholder with the approved draft, save and close.
Summary
References
Disclaimer: This article originated from the author's writing. Artificial intelligence was used to refine it and make it clearer, more professional, and easier to read.