Note: This is a NeoForge port for Minecraft 1.21.1. For the original Fabric version, see DNGriffin/minecraftcode.
A NeoForge mod that integrates OpenCode into Minecraft Java Edition single player, with a unique pause mechanic that freezes the game while the AI is waiting for input and resumes when it's actively working.
MinecraffCodeLowRes_under10mb.mp4
- Smart Pause Mechanic - Game automatically pauses when the AI is idle, letting you focus on coding without your character dying. Resumes instantly when the AI starts working.
- In-Game Chat Interface - Send prompts and receive responses directly in Minecraft chat using
/occommands. - Session Management - Create, list, and switch between coding sessions without leaving the game.
- Real-Time Streaming - See AI responses as they're generated, token by token.
- Tool Visibility - Get feedback about what tools the AI is using (reading files, writing code, etc.).
- Configurable - Set your working directory, server URL, and other options.
- Cross-Platform - Works on macOS, Windows, and Linux.
- Install NeoForge for Minecraft 1.21.1
- Download the mod JAR from Releases and place it in your
.minecraft/modsfolder - Start OpenCode:
opencode - Launch Minecraft and create/join a single player world
- Use
/oc session list&/oc session join # - Start coding with
/oc <your prompt here>
- Minecraft 1.21.1
- NeoForge 21.1.72+
- Java 21+
- OpenCode running in server mode (
opencode serve)
- Download the latest
opencode-x.x.x.jarfrom Releases - Place the JAR file in your
.minecraft/modsfolder
git clone https://github.com/yourusername/opencode-minecraft-neoforge.git
cd opencode-minecraft-neoforge
./gradlew buildThe built JAR will be in build/libs/opencode-1.0.0.jar
| Command | Description |
|---|---|
/oc <prompt> |
Send a prompt to OpenCode |
/oc status |
Show connection and session status |
/oc session new |
Create a new coding session |
/oc session list |
List available sessions (numbered) |
/oc session use <#> |
Switch to session by number or ID |
/oc cancel |
Cancel current generation |
/oc pause |
Toggle pause control on/off - persistent across game restarts |
/oc config url <url> |
Set server URL |
/oc config dir <path> |
Set working directory |
/oc help |
Show help |
The mod uses Minecraft's integrated server to control game simulation:
| AI State | Game State | What's Happening |
|---|---|---|
| Idle | Paused | AI is waiting for your next prompt |
| Busy | Running | AI is processing (reading files, planning, etc.) |
| Generating | Running | AI is actively outputting text |
| Disconnected | Paused | Not connected to OpenCode server |
When paused:
- World simulation stops (mobs freeze, time stops)
- You cannot move or interact
- A dark overlay shows the current status
- Chat remains functional for commands
A 3-second grace period after joining a world prevents immediate pausing.
Configuration is stored in .minecraft/config/opencode.json:
{
"serverUrl": "http://localhost:4096",
"workingDirectory": "/path/to/your/project",
"lastSessionId": null,
"autoReconnect": true,
"reconnectIntervalMs": 5000,
"showStatusBar": true,
"pauseEnabled": true
}| Option | Default | Description |
|---|---|---|
serverUrl |
http://localhost:4096 |
OpenCode server URL |
workingDirectory |
Minecraft config directory | Project directory for file operations |
lastSessionId |
null |
Auto-resume last session on connect |
autoReconnect |
true |
Automatically reconnect if disconnected |
reconnectIntervalMs |
5000 |
Reconnection attempt interval |
showStatusBar |
true |
Show status in action bar |
pauseEnabled |
true |
Whether pause control is enabled (persistent) |
- Ensure OpenCode is running:
opencode serve - Check if the server is accessible at
http://localhost:4096 - Verify
serverUrlin config matches your server
- Use
/oc statusto check the current state - If stuck, use
/oc pauseto toggle pause control off - Ensure OpenCode server is running and responsive
- Create a session first:
/oc session new - Check
/oc statusfor connection issues - Look at Minecraft logs for errors
- Ensure you're using the correct mod version for Minecraft 1.21.1
- Try
./gradlew clean buildif building from source - Check for conflicting mods
# Build the mod
./gradlew build
# Run Minecraft with the mod (for development)
./gradlew runClientThe mod consists of several key components:
- OpenCodeClient - Coordinates HTTP communication and event handling
- SessionManager - Manages session lifecycle and state
- PauseController - Determines when to pause/resume based on AI state
- Mixins - Hook into Minecraft's integrated server to control ticks
Communication with OpenCode:
- REST API for session management (
/session/*endpoints) - Server-Sent Events (SSE) at
/global/eventfor real-time updates - Pause state is driven by
session.statusevents (idlevsbusy)
MIT License - see LICENSE for details.
- OpenCode - The agentic coding tool this mod integrates with
- Original Fabric Version - The original Fabric mod this is ported from