My Opencode Setup: Guardrails, Intelligence, and Skill-Driven AI Workflows

· 5 min read ai

TL;DR: Here’s the layer I do

LayerToolProblem It Solves
1 — RAGContext7 + TavilyOutdated docs → hallucinated code
2 — Context Engineeringcontext-modeTool output bloat → burned context window
3 — Code IntelligenceGitNexusBlind edits → breaking unknown dependencies
4 — Visionagent-browser + zai-mcp-serverTerminal blindness → can’t see UI or errors
5 — Model ProviderZ.ai Coding PlanModels + MCP servers (vision, search, GitHub)
Core — Prompt EngineeringSuperpowersInconsistent processes → babysitting sessions

Start with whatever solves your biggest pain point:

  • Outdated docs → Context7
  • Context bloat → context-mode
  • Blind edits → GitNexus
  • Inconsistent workflows → Superpowers

The Problem

In the last long holiday, I was given Z.AI Coding Plan. At first, I was tempted to use it for Claude and opencode. I benchmarked it along with Qwen Code. After a while, I was tempted to build a good workflow for AI coding.

The few things that I think most of us who use LLM for coding run thru these problems:

ProblemWhat Happens
Context bloatTool outputs flood the context window, eating capacity before any real work happens. Long process of development makes even the mighties Claude down.
Blind editingChanges break things you didn’t know depended on the code you touched.
Chaotic workflowsWithout enforced processes, results vary wildly between sessions.

Thus, I make a new architecture for my coding plan. Each problem has a dedicated solution in my stack. Each solution is configured once in AGENTS.md and enforced automatically — the AI doesn’t get to opt out.

There are many tools to empower AI pipeline and solving the problems. I feel as long as these principles are there, we can make a good pipeline regardlesss the tools:

  1. Prompt Engineering.
  2. RAG.
  3. Context Engineering. Based on these principles I put these:
flowchart TB subgraph Core["Core Workflow"] S["Superpowers: \n brainstorming → writing-plans → \n TDD → verification → finishing"] end subgraph L1["Layer 1: RAG"] D["Context7 + Tavily \n Current Information \n Live docs + web research"] end subgraph L2["Layer 2"] C["context-mode \n Clean Context \n 99% context saved"] end subgraph L3["Layer 3"] G["GitNexus \n Code Intelligence \n Blast radius analysis"] end subgraph L4["Layer 4"] V["agent-browser + zai-mcp \n Vision \n Screenshot → Analyze"] end S --> D S --> C S --> G S --> V style Core fill:#fff3e0,stroke:#f57c00,stroke-width:3px style L1 fill:#e3f2fd,stroke:#1976d2,stroke-width:2px style L2 fill:#e8f5e9,stroke:#388e3c,stroke-width:2px style L3 fill:#e0f2f1,stroke:#00796b,stroke-width:2px style L4 fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px

This article walks through my setup with the workflow at the center, and each layer explained by how it enables that workflow.


The Core — Skill-Driven Workflows

Without structure, AI assistants freestyle. Sometimes it writes tests first, sometimes it doesn’t. Sometimes it plans, sometimes it dives straight in. The results are inconsistent, and you end up babysitting the session instead of getting work done.

Don’t let the AI improvise. Enforce a structured pipeline where skills activate in sequence and the AI can’t skip steps.

The Superpowers Pipeline

flowchart LR A["brainstorming"] --> B["writing-plans"] B --> C["TDD"] C --> D["build"] D --> E["verification"] E --> F["finishing"] style A fill:#fff3e0,stroke:#f57c00,stroke-width:2px style B fill:#fff3e0,stroke:#f57c00,stroke-width:2px style C fill:#e8f5e9,stroke:#388e3c,stroke-width:2px style D fill:#e3f2fd,stroke:#1976d2,stroke-width:2px style E fill:#f3e5f5,stroke:#7b1fa2,stroke-width:2px style F fill:#e0f2f1,stroke:#00796b,stroke-width:2px

Skills follow a priority hierarchy. Process skills fire first because they determine how to approach the task. Implementation skills guide execution. Review skills ensure quality:

  1. Process skills — brainstorming, systematic-debugging, TDD, writing-plans. These determine HOW to approach the task.
  2. Implementation skills — frontend-design, find-docs, accessibility-a11y. These guide execution.
  3. Review skills — verification-before-completion, requesting-code-review. These ensure quality.

The Brainstorming Flow

When I type /brainstorming add a dark mode toggle, the skill:

  1. Asks clarifying questions one at a time (scope, constraints, preferences)
  2. For UI work, requests a design reference (Figma mockup, reference site, HTML sketch)
  3. Generates a structured implementation plan via writing-plans
  4. Offers execution choice: subagents (parallel) vs current session (sequential)
  5. Runs TDD per task
  6. Triggers verification (tests, lint, impact check)
  7. Hands off to finishing (review, commit, merge)

Greenfield vs Brownfield

The pipeline looks different depending on whether you’re starting from scratch or working in an existing codebase:

AspectGreenfieldBrownfield
First stepDefine requirementsUnderstand existing code
Before editingNo existing depsMUST run gitnexus_impact
RiskLOWHIGH
DebuggingRarely neededPrimary concern
RefactoringMinimalCritical for safety

Configuration

{
"plugin": [
"superpowers@git+https://github.com/obra/superpowers.git"
]
}

Installation:

Fetch and follow instructions from https://raw.githubusercontent.com/obra/superpowers/refs/heads/main/.opencode/INSTALL.md

Key point: This pipeline is the core. Every other layer exists to make it work reliably.


Layer 1 — Current Information (Context7 + Tavily)

Skills need accurate information. Outdated docs = hallucinated code = broken tests. This is the RAG foundation of the workflow.

The Problem

Models trained 6 months ago don’t know about Astro 6 breaking changes or Tailwind v4 APIs. They hallucinate confidently.

The Philosophy

Skills should query live docs, not rely on stale training data.

Context7 — Live Library Documentation

Context7 solves this by providing a CLI that queries live library documentation on demand. The AI runs a resolve step to find the right library, then queries current docs. No stale training data, no guessing.

Installation:

Terminal window
bun i -g ctx7
ctx setup # installs find-docs skill
ctx login

How it works:

  1. ctx7 library <name> "<question>" — find the right library ID
  2. ctx7 docs <libraryId> "<question>" — get current docs

The find-docs skill provides the same workflow for contexts where the AI uses its native skill system. Both enforce the same pattern: resolve first, then query.

Tavily — Web Research Escalation

The web research problem splits into distinct modes: sometimes you need a quick answer, sometimes you need to pull content from a known URL, and sometimes you need a full multi-source analysis with citations.

Installation:

Terminal window
curl -fsSL https://cli.tavily.com/install.sh | bash
tvly login
tvly skills install

Escalation pattern:

flowchart LR A["tvly search\nNo URL — find pages"] --> B["tvly extract\nHave URL — pull content"] B --> C["tvly research\nDeep multi-source analysis"] style A fill:#e0f2f1,stroke:#00796b,stroke-width:2px style B fill:#e0f2f1,stroke:#00796b,stroke-width:2px style C fill:#e0f2f1,stroke:#00796b,stroke-width:2px

The seven Tavily skills:

SkillCommandWhen It Fires
tavily-searchtvly searchNo URL — find pages, answer questions
tavily-extracttvly extractHave URL — pull content as markdown
tavily-maptvly mapLarge site — discover URLs
tavily-crawltvly crawlBulk content from site section
tavily-researchtvly researchDeep multi-source analysis
tavily-clitvly <command>General reference
tavily-best-practices(reference)Production patterns

Why This Enables the Workflow

The writing-plans skill generates accurate implementation steps when it has current docs. The brainstorming skill answers questions correctly when it can research live.


Layer 2 — Context Protection (context-mode)

Skills need clean context to work. A flooded context window breaks the pipeline.

The Problem

Raw MCP tool outputs dump directly into context. A single Playwright snapshot is 56 KB. Five of those and the session dies before the skill pipeline can complete.

The Philosophy

Raw data should never enter the context window unless you’re editing it.

The Solution — context-mode

context-mode is an MCP plugin that intercepts tool outputs and routes them through an isolated subprocess. Only a condensed summary enters the context window. The full data stays in a searchable FTS5 database, available on demand through query tools.

flowchart LR A["AI Agent\n200K context"] --> B["context-mode MCP"] B --> C["Isolated Subprocess"] C --> D["Summary only"] D --> A

Configuration

{
"plugin": ["superpowers@...", "context-mode"],
"mcp": {
"context-mode": {
"type": "local",
"command": ["context-mode"]
}
}
}

AGENTS.md Routing Rules

The plugin alone isn’t enough. The real enforcement comes from routing rules written into AGENTS.md:

RuleWhat’s BlockedWhat You Use Instead
curl/wgetShell HTTP callsctx_fetch_and_index or ctx_execute
Inline HTTPfetch(), requests.get() in shellctx_execute sandbox
Shell >20 linesRaw command output in contextctx_batch_execute or ctx_execute

Tool Hierarchy

  1. GATHER: ctx_batch_execute — run multiple commands + search in ONE call. This is the primary tool. One call replaces 30+ individual tool invocations.
  2. FOLLOW-UP: ctx_search — query previously indexed content with natural language.
  3. PROCESSING: ctx_execute / ctx_execute_file — run code in a sandboxed subprocess. Only stdout enters context.
  4. WEB: ctx_fetch_and_index — fetch a URL, convert to markdown, chunk, index, then query. Raw HTML never touches context.
  5. INDEX: ctx_index — store arbitrary content in the FTS5 knowledge base for later retrieval.

Why This Enables the Workflow

Without context protection, the skill pipeline dies halfway through. ctx_batch_execute lets the brainstorming and writing-plans skills research your codebase without burning the session.

For the deep dive on how context-mode works, see my earlier article.


Layer 2 — Code Intelligence (GitNexus)

Skills need accurate code understanding. TDD and refactoring skills break things if they don’t know what depends on what.

The Problem

In a brownfield project, editing a function without knowing what calls it is Russian roulette. You fix one thing and break three others.

The Philosophy

Never edit code without understanding its blast radius.

The Solution — GitNexus

GitNexus builds a knowledge graph of your codebase from git history and AST analysis. Functions, classes, imports, call chains — everything becomes a queryable graph. Instead of grepping for callers and hoping you found them all, you ask the graph and get an exact answer with blast radius estimates.

Configuration

{
"mcp": {
"gitnexus": {
"type": "local",
"command": ["npx", "-y", "gitnexus", "mcp"]
}
}
}

AGENTS.md Enforcement Rules

These aren’t suggestions. They’re checked before every edit and every commit:

  • MUST run gitnexus_impact before editing any symbol
  • MUST run gitnexus_detect_changes before committing
  • MUST warn if impact analysis returns HIGH or CRITICAL risk
  • NEVER edit a function, class, or method without impact analysis first
  • NEVER rename symbols with find-and-replace — use gitnexus_rename instead

Tool Mappings

QuestionToolWhat It Returns
”How does auth work?”gitnexus_queryExecution flows ranked by relevance
”Who calls this function?”gitnexus_context360° view: callers, callees, processes
”What breaks if I change this?”gitnexus_impactBlast radius by depth (d=1, d=2, d=3)
“Did my changes affect anything unexpected?”gitnexus_detect_changesChanged symbols + affected processes

Risk Levels

DepthMeaningAction
d=1WILL BREAK — direct callersMUST update
d=2LIKELY AFFECTED — indirect depsShould test
d=3MAY NEED TESTING — transitiveTest if critical path

Why This Enables the Workflow

The TDD and verification skills can’t work safely without knowing what they’re affecting. gitnexus_impact runs automatically before edits. gitnexus_detect_changes confirms scope before finishing merges.

Practical Note

After committing, the GitNexus index goes stale. Run npx gitnexus analyze to refresh it. If the index previously included embeddings, add --embeddings to preserve them.


Layer 3 — Code Intelligence (GitNexus)

Skills need accurate code understanding. TDD and refactoring skills break things if they don’t know what depends on what.

The Problem

In a brownfield project, editing a function without knowing what calls it is Russian roulette. You fix one thing and break three others.

The Philosophy

Never edit code without understanding its blast radius.

The Solution — GitNexus

GitNexus builds a knowledge graph of your codebase from git history and AST analysis. Functions, classes, imports, call chains — everything becomes a queryable graph. Instead of grepping for callers and hoping you found them all, you ask the graph and get an exact answer with blast radius estimates.

Configuration

{
"mcp": {
"gitnexus": {
"type": "local",
"command": ["npx", "-y", "gitnexus", "mcp"]
}
}
}

AGENTS.md Enforcement Rules

These aren’t suggestions. They’re checked before every edit and every commit:

  • MUST run gitnexus_impact before editing any symbol
  • MUST run gitnexus_detect_changes before committing
  • MUST warn if impact analysis returns HIGH or CRITICAL risk
  • NEVER edit a function, class, or method without impact analysis first
  • NEVER rename symbols with find-and-replace — use gitnexus_rename instead

Tool Mappings

QuestionToolWhat It Returns
”How does auth work?”gitnexus_queryExecution flows ranked by relevance
”Who calls this function?”gitnexus_context360° view: callers, callees, processes
”What breaks if I change this?”gitnexus_impactBlast radius by depth (d=1, d=2, d=3)
“Did my changes affect anything unexpected?”gitnexus_detect_changesChanged symbols + affected processes

Risk Levels

DepthMeaningAction
d=1WILL BREAK — direct callersMUST update
d=2LIKELY AFFECTED — indirect depsShould test
d=3MAY NEED TESTING — transitiveTest if critical path

Why This Enables the Workflow

The TDD and verification skills can’t work safely without knowing what they’re affecting. gitnexus_impact runs automatically before edits. gitnexus_detect_changes confirms scope before finishing merges.

Practical Note

After committing, the GitNexus index goes stale. Run npx gitnexus analyze to refresh it. If the index previously included embeddings, add --embeddings to preserve them.


Layer 4 — Vision (agent-browser + zai-mcp-server)

Skills need to see what users see. Terminal-based AI is blind to UI bugs and error dialogs.

The Problem

You paste descriptions like “there’s a red box with some text” and hope the AI understands. It can’t see the broken layout.

The Philosophy

Skills should diagnose from screenshots, not descriptions.

The Solution — Two-Stage Pipeline

  1. agent-browser — captures browser screenshots
  2. zai-mcp-server — analyzes (OCR, error diagnosis, UI diff)

Configuration

Terminal window
bun i -g agent-browser
agent-browser install
npx skills add https://github.com/vercel-labs/agent-browser --skill agent-browser -y -g

Why This Enables the Workflow

The verification skill can compare the implemented UI against the design reference from brainstorming. Instead of “does it look right?”, it’s “here’s the pixel diff.”


Layer 5 — The Model Provider (Z.ai)

The engine that powers everything.

The Problem

Not all tasks need a frontier model. Routing, summarization, and classification waste money on overpowered models.

The Philosophy

Dual-model setup — right tool for each job.

Configuration

{
"model": "zai-coding-plan/glm-5-turbo",
"small_model": "zai-coding-plan/glm-4.5-air"
}

Model Roles

SlotModelUse Case
modelglm-5-turboMain reasoning, code generation, complex tasks
small_modelglm-4.5-airFast/cheap: summarization, classification, routing

MCP Servers

ToolWhat It Does
zai-mcp-serverVision: screenshot-to-code, OCR, error diagnosis, UI diff
web-search-primeWeb search (Chinese + international)
web-readerFetch URL → clean markdown
zreadSearch GitHub repos — docs, issues, commits, files

Why This Enables the Workflow

The skill pipeline runs cheaper when routing and summarization use glm-4.5-air. Complex reasoning and code generation fire glm-5-turbo only when needed.


How It All Fits Together

Walkthrough: “Add a dark mode toggle”

  1. Current docs (RAG): ctx7 fetches Tailwind v4 dark mode docs (not hallucinated v3 APIs)
  2. Superpowers core activates: /brainstorming asks clarifying questions one at a time
  3. Context protection: Research runs through ctx_batch_executectx_search, no bloat
  4. Code intelligence: gitnexus_query finds existing theme code, gitnexus_context shows dependencies
  5. Safety check: gitnexus_impact shows blast radius before any edit
  6. TDD skill: Writes test first, then implementation
  7. Vision verification: agent-browser captures screenshot, zai-mcp-server compares to design reference
  8. Final check: gitnexus_detect_changes confirms scope, tests pass
  9. Finishing: Review, commit, merge

Closing

The solutions that I put here is not mandatory. I used them because they were the ones that available. If you are also broke-gang fam, you can use:

  • Custom MCP/skills to use Qwen code to read image.
  • Use opencode Minimax M2.5 or any free Openrouter

Appendix: Interface (Optional)

Default keybinds fight against your muscle memory. Your TUI config is your IDE, not just decoration.

Configuration Highlights from tui.json

  • Leader key: ctrl+x (Emacs-style)
  • Input motions: ctrl+b/ctrl+f (word), ctrl+a/ctrl+e (line)
  • Session management: <leader>n (new), <leader>l (list), <leader>g (timeline)
  • Agent cycling: Tab / Shift+Tab

Key Highlights

KeyAction
ctrl+xLeader (prefix)
ctrl+x nNew session
ctrl+x lSession list
ctrl+x gSession timeline
ctrl+x xExport session
TabCycle agents
ctrl+pCommand palette

References

ToolAuthorWhat It Does
OpenCodeAnomalyThe AI coding assistant this entire setup runs on
Context7Context7Live library documentation retrieval via CLI
SuperpowersobraPlugin that provides skill-driven workflows and process enforcement
context-modemksgluMCP plugin that protects the context window from tool output bloat
GitNexusmikenyeCode intelligence — knowledge graph, blast radius analysis, safe refactoring
agent-browserVercelBrowser automation for AI agents
TavilyTavilyWeb search, extraction, crawling, and deep research for AI agents
Z.ai MCP ServerZ.aiVision, web search, web reader, GitHub integration

This article was written by opencode (GLM-5-Turbo | Z.AI Coding Plan) and edited by Qwen Code (Qwen 3.5 | Alibaba). I cheated by edited some part just to make it clear and not to exaggerate things.