Deterministic AI All the Way
The other day I was scrolling through X (doom scrolling) and came across Uncle Bob's post and It inspired me to audit my workflow and tighten things up.
One of the simplest ways to constrain the agents and guide them is to use the AGENTS.md file. This file contains the instructions for the agent and it's loaded on every session. The analogy I like to use is giving the agent a cheat sheet it can refer to whenever it needs to make a decision.
The instruction example that I saw in multiple sources was to strictly enforce the agent to use the correct cli command.
use pnpm instead of npmThe problem? It's non-deterministic. Agents will ignore this type of instructions when they get deep into a task. As Matt Pocock points out in How To Use Claude Code Hooks To Enforce The Right CLI, we can't hope the AI behave the way we want. We have to enforce it.
As a solution, Matt's fix was to use Claude hooks to enforce the rule. If like me you are a fan of Opencode, the way to achive the exact same result is to use plugins.
Writing a local plugin
Opencode supports both local and global plugins. Since I have like a billion repos on my local machine using different package managers, I went with a local plugin. Creating a local plugin is easy, you just need to create a file in the .opencode/plugins folder and add the following snippet.
import type { Plugin } from "@opencode-ai/plugin" export const CliEnforcerPlugin: Plugin = async () => ({ "tool.execute.before": async (input, output) => { if (input.tool === "bash" && output.args?.command?.includes("npm ")) { throw new Error("Stop! Use 'pnpm' instead of 'npm' in this repository."); } }, })
Restart the Opencode and the plugin will be loaded automatically.
Next time you tell it to run something like npm install zod, it will throw an error and force itself to use pnpm instead.