Skip to content

Instantly share code, notes, and snippets.

@paul-english
Created April 24, 2026 20:05
Show Gist options
  • Select an option

  • Save paul-english/92dfcfba28d297097686b8ad64a1e330 to your computer and use it in GitHub Desktop.

Select an option

Save paul-english/92dfcfba28d297097686b8ad64a1e330 to your computer and use it in GitHub Desktop.
UV plugin for opencode
// ~/.opencode/plugins/uv-enforcer.ts
import type { Plugin } from "@opencode-ai/plugin"
function rewrite(cmd: string): string {
return cmd
.replace(/^\s*pip3?\s+install\s+(.+)$/m, "uv add $1")
.replace(/^\s*python3?\s+(-m\s+.+)$/m, "uv run python $1")
.replace(/^\s*python3?\s+(.+\.py(?:\s+.*)?)$/m, "uv run python $1")
.replace(/^\s*pytest(\s|$)/m, "uv run pytest$1")
}
export const UvEnforcer: Plugin = async () => {
return {
"tool.execute.before": async (input, output) => {
if (input.tool !== "bash") return
const original = output.args.command
const rewritten = rewrite(original)
if (rewritten !== original) {
output.args.command = rewritten
}
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment