/bodnar-skills:opentui-developmentfrom bodnar-skills
Development guide for OpenTUI terminal UI library and OpenCode AI integration. Use when working with OpenTUI codebase (github.com/sst/opentui), building TUI applications, integrating OpenCode AI capabilities (@opencode-ai/sdk), creating structured AI-powered CLI tools (NEVER conversational), using Zod schemas for tool definitions, contributing to OpenTUI packages (@opentui/core, @opentui/solid, @opentui/react), or building terminal applications with OpenTUI + OpenCode.
Ships in bodnar-skills. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
OpenTUI is a TypeScript library for building terminal user interfaces (TUIs) with native Zig performance. This skill covers development workflows, architecture patterns, and best practices for working with the OpenTUI codebase.
Core packages:
@opentui/core - Standalone library with imperative API and all primitives@opentui/solid - SolidJS reconciler for OpenTUI@opentui/react - React reconciler for OpenTUI@opentui/vue - Vue reconciler (unmaintained)@opentui/go - Go bindings (unmaintained)Required tools:
OpenTUI is Bun-first. Always use Bun, never Node.js, npm, yarn, or pnpm.
# Run TypeScript files
bun <file> # NOT: node <file> or ts-node <file>
# Package management
bun install # NOT: npm install or yarn install
bun run <script> # NOT: npm run <script>
# Testing
bun test # NOT: jest or vitest
Key Bun APIs to prefer:
Bun.serve() - Built-in HTTP/WebSocket/HTTPS server (NOT express)bun:sqlite - Built-in SQLite (NOT better-sqlite3)Bun.redis - Built-in Redis client (NOT ioredis)Bun.sql - Built-in Postgres client (NOT pg)WebSocket - Built-in WebSocket (NOT ws package)Bun.file - File I/O (prefer over node:fs readFile/writeFile)Bun.$ - Shell commands (NOT execa)Note: Bun automatically loads .env files - don't use dotenv package.
CRITICAL: When changing TypeScript code, you do NOT need to run the build script. The build is only needed when changing native Zig code.
# Build everything (from repo root)
bun run build
# Build only native code
bun run build:native
# Build only library (TypeScript)
bun run build:lib
# Run all tests (from repo root)
bun test
# TypeScript tests (from packages/core)
cd packages/core
bun test
# Native tests (from packages/core)
cd packages/core
bun run test:native
# Filter native tests
bun run test:native -Dtest-filter="test name"
# Native benchmarks
bun run bench:native
# From repo root
bun install
cd packages/core
bun run src/examples/index.ts
Use scripts/link-opentui-dev.sh to test local changes in another project without publishing.
# Link core only (default)
./scripts/link-opentui-dev.sh /path/to/your/project
# Link core and solid
./scripts/link-opentui-dev.sh /path/to/your/project --solid
# Link core and react
./scripts/link-opentui-dev.sh /path/to/your/project --react
# Link built dist directories (for testing builds)
./scripts/link-opentui-dev.sh /path/to/your/project --dist
# Copy dist instead of symlink (for Docker/Windows)
./scripts/link-opentui-dev.sh /path/to/your/project --dist --copy
Requirements:
bun install first--dist: links to built artifacts--copy: copies instead of symlinking (for environments with symlink issues)CliRenderer - The main rendering engine that manages terminal output, input events, and the rendering loop. Can run in "live" mode (via renderer.start()) with target FPS, or auto-render on changes.
Renderables - Hierarchical building blocks for UI. Each represents a visual element (text, boxes, inputs) with positioning via Yoga layout engine. Used imperatively with new TextRenderable(renderer, {...}).
Constructs (Components) - Functional composition of renderables. Look like React/Solid components but are constructor functions, not render functions. Return VNodes that are instantiated later. More declarative than raw renderables.
FrameBuffer - Low-level 2D rendering surface for custom graphics. Supports alpha blending, cell manipulation, text drawing, and rect filling.
Console - Built-in debugging overlay that captures all console output (log, info, warn, error, debug). Toggle with renderer.console.toggle(), scroll with arrow keys, resize with +/-.
See packages/core/docs/renderables-vs-constructs.md for detailed comparison.
Imperative (Renderables):
const box = new BoxRenderable(renderer, { id: "my-box", width: 20 })
const text = new TextRenderable(renderer, { id: "my-text", content: "Hello" })
box.add(text)
renderer.root.add(box)
Declarative (Constructs):
import { Box, Text, instantiate } from "@opentui/core"
const myComponent = Box(
{ id: "my-box", width: 20 },
Text({ id: "my-text", content: "Hello" })
)
renderer.root.add(myComponent)
Use delegate() to route API calls to specific descendants in constructs:
function LabeledInput(props) {
return delegate(
{ focus: `${props.id}-input` },
Box(
{},
Text({ content: props.label }),
Input({ id: `${props.id}-input`, placeholder: props.placeholder })
)
)
}
const input = LabeledInput({ id: "username", label: "Name:", placeholder: "..." })
input.focus() // Delegates to the Input renderable
Display styled text with colors, attributes, and selection support.
import { TextRenderable, TextAttributes, t, bold, underline, fg } from "@opentui/core"
const text = new TextRenderable(renderer, {
id: "text-1",
content: "Important",
fg: "#FFFF00",
attributes: TextAttributes.BOLD | TextAttributes.UNDERLINE,
position: "absolute",
left: 5,
top: 2,
})
// Template literals for complex styling
const styled = new TextRenderable(renderer, {
content: t`${bold("Important")} ${fg("#FF0000")(underline("Message"))}`,
})
Container with borders, background colors, and layout capabilities.
const panel = new BoxRenderable(renderer, {
id: "panel",
width: 30,
height: 10,
backgroundColor: "#333366",
borderStyle: "double",
borderColor: "#FFFFFF",
title: "Settings Panel",
titleAlignment: "center",
})
Text input field with cursor, placeholder, and focus states. Must be focused to receive input.
const input = new InputRenderable(renderer, {
id: "name-input",
width: 25,
placeholder: "Enter your name...",
focusedBackgroundColor: "#1a1a1a",
})
input.on(InputRenderableEvents.CHANGE, (value) => {
console.log("Input:", value)
})
input.focus()
List selection component. Must be focused. Keys: up/k and down/j to navigate, enter to select.
const menu = new SelectRenderable(renderer, {
id: "menu",
options: [
{ name: "New File", description: "Create a new file" },
{ name: "Open File", description: "Open existing file" },
],
})
menu.on(SelectRenderableEvents.ITEM_SELECTED, (index, option) => {
console.log("Selected:", option.name)
})
menu.focus()
Horizontal tab selection. Must be focused. Keys: left/[ and right/] to navigate, enter to select.
const tabs = new TabSelectRenderable(renderer, {
id: "tabs",
width: 60,
options: [
{ name: "Home", description: "Dashboard" },
{ name: "Files", description: "File management" },
],
tabWidth: 20,
})
Display text using ASCII art fonts.
const title = new ASCIIFontRenderable(renderer, {
id: "title",
text: "OPENTUI",
font: "tiny",
fg: RGBA.fromInts(255, 255, 255, 255),
})
Low-level rendering surface for custom graphics.
const canvas = new FrameBufferRenderable(renderer, {
id: "canvas",
width: 50,
height: 20,
})
canvas.frameBuffer.fillRect(10, 5, 20, 8, RGBA.fromHex("#FF0000"))
canvas.frameBuffer.drawText("Custom", 12, 7, RGBA.fromHex("#FFFFFF"))
OpenTUI uses the RGBA class internally (float values 0.0-1.0) but provides convenient constructors:
import { RGBA, parseColor } from "@opentui/core"
const red = RGBA.fromInts(255, 0, 0, 255) // RGB integers
const blue = RGBA.fromValues(0.0, 0.0, 1.0, 1.0) // Float values
const green = RGBA.fromHex("#00FF00") // Hex strings
const transparent = RGBA.fromValues(1.0, 1.0, 1.0, 0.5) // Semi-transparent
// parseColor() accepts RGBA objects or color strings
const color = parseColor("#FF0000") // or "red" or "transparent"
Access keyboard handler via renderer.keyInput:
import { type KeyEvent } from "@opentui/core"
renderer.keyInput.on("keypress", (key: KeyEvent) => {
console.log("Key:", key.name)
console.log("Sequence:", key.sequence)
console.log("Modifiers:", { ctrl: key.ctrl, shift: key.shift, alt: key.meta })
if (key.name === "escape") {
// Handle escape
} else if (key.ctrl && key.name === "c") {
// Handle Ctrl+C
}
})
renderer.keyInput.on("paste", (text: string) => {
console.log("Pasted:", text)
})
OpenTUI uses Yoga layout engine for CSS Flexbox-like layouts:
const container = new GroupRenderable(renderer, {
id: "container",
flexDirection: "row",
justifyContent: "space-between",
alignItems: "center",
width: "100%",
height: 10,
})
const leftPanel = new BoxRenderable(renderer, {
id: "left",
flexGrow: 1,
height: 10,
})
const rightPanel = new BoxRenderable(renderer, {
id: "right",
width: 20,
height: 10,
})
container.add(leftPanel)
container.add(rightPanel)
Configure console overlay in renderer options:
import { createCliRenderer, ConsolePosition } from "@opentui/core"
const renderer = await createCliRenderer({
consoleOptions: {
position: ConsolePosition.BOTTOM,
sizePercent: 30,
colorInfo: "#00FFFF",
colorWarn: "#FFFF00",
colorError: "#FF0000",
startInDebugMode: false,
},
})
// All console.* calls appear in overlay
console.log("This appears in the overlay")
console.error("Errors are red")
// Toggle console
renderer.console.toggle()
// When focused: arrow keys scroll, +/- resize
See packages/core/docs/tree-sitter.md for complete guide.
Global default parsers (recommended for app-wide support):
import { addDefaultParsers, getTreeSitterClient } from "@opentui/core"
addDefaultParsers([
{
filetype: "python",
wasm: "https://github.com/tree-sitter/tree-sitter-python/releases/download/v0.23.6/tree-sitter-python.wasm",
queries: {
highlights: ["https://raw.githubusercontent.com/tree-sitter/tree-sitter-python/master/queries/highlights.scm"],
},
},
])
const client = getTreeSitterClient()
await client.initialize()
const result = await client.highlightOnce(pythonCode, "python")
Per-client parsers:
const client = new TreeSitterClient({ dataPath: "./cache" })
await client.initialize()
client.addFiletypeParser({
filetype: "rust",
wasm: "https://github.com/tree-sitter/tree-sitter-rust/releases/download/v0.23.2/tree-sitter-rust.wasm",
queries: {
highlights: ["https://raw.githubusercontent.com/tree-sitter/tree-sitter-rust/master/queries/highlights.scm"],
},
})
Use updateAssets utility for multiple languages:
// parsers-config.json
{
"parsers": [
{
"filetype": "python",
"wasm": "https://github.com/tree-sitter/tree-sitter-python/releases/download/v0.23.6/tree-sitter-python.wasm",
"queries": {
"highlights": ["https://raw.githubusercontent.com/tree-sitter/tree-sitter-python/master/queries/highlights.scm"]
}
}
]
}
// In package.json
{
"scripts": {
"prebuild": "bun node_modules/@opentui/core/lib/tree-sitter/assets/update.ts --config ./parsers-config.json --assets ./src/parsers --output ./src/parsers.ts"
}
}
// Or programmatically
import { updateAssets } from "@opentui/core"
await updateAssets({
configPath: "./parsers-config.json",
assetsDir: "./src/parsers",
outputPath: "./src/parsers.ts",
})
import { CodeRenderable, getTreeSitterClient } from "@opentui/core"
const client = getTreeSitterClient()
await client.initialize()
const code = new CodeRenderable("code-1", {
content: 'def hello():\n print("world")',
filetype: "python",
width: 40,
height: 10,
})
TypeScript:
Formatting:
semi: false, printWidth: 120bun run prettier:writeError Handling:
Key environment variables (see packages/core/docs/env-vars.md for full list):
OTUI_DEBUG_FFI - Enable debug logging for FFI bindingsOTUI_TRACE_FFI - Enable tracing for FFI bindingsOTUI_USE_CONSOLE - Whether to capture console output (default: true)SHOW_CONSOLE - Show console at startup (default: false)OTUI_DUMP_CAPTURES - Dump captured output on exitOTUI_NO_NATIVE_RENDER - Disable native rendering (debugging)OTUI_USE_ALTERNATE_SCREEN - Use alternate screen buffer (default: true)OTUI_OVERRIDE_STDOUT - Override stdout stream (default: true)OTUI_TS_STYLE_WARN - Warn for missing syntax styles (default: false)OTUI_TREE_SITTER_WORKER_PATH - Path to TreeSitter workerXDG_CONFIG_HOME - Base directory for config filesXDG_DATA_HOME - Base directory for data filesCRITICAL: This is a terminal UI library. When running examples or apps:
console.log output in the normal wayBest practices:
# Prepare release (updates versions)
bun run prepare-release
# Run pre-publish checks
bun run pre-publish
# Publish all packages
bun run publish
# Or publish individual packages
bun run publish:core
bun run publish:react
bun run publish:solid
import { createCliRenderer, TextRenderable } from "@opentui/core"
const renderer = await createCliRenderer()
const greeting = new TextRenderable(renderer, {
id: "greeting",
content: "Hello, OpenTUI!",
fg: "#00FF00",
position: "absolute",
left: 10,
top: 5,
})
renderer.root.add(greeting)
function LabeledInput(props: { id: string; label: string; placeholder: string }) {
return delegate(
{ focus: `${props.id}-input` },
Box(
{ flexDirection: "row", backgroundColor: "gray" },
Text({ content: props.label + " " }),
Input({
id: `${props.id}-input`,
placeholder: props.placeholder,
width: 20,
})
)
)
}
const username = LabeledInput({
id: "username",
label: "Username:",
placeholder: "Enter your username...",
})
username.focus() // Delegates to the input
import { InputRenderableEvents, SelectRenderableEvents } from "@opentui/core"
// Input events
input.on(InputRenderableEvents.CHANGE, (value) => {
console.log("Changed:", value)
})
// Select events
menu.on(SelectRenderableEvents.ITEM_SELECTED, (index, option) => {
console.log("Selected:", option.name)
})
// Keyboard events
renderer.keyInput.on("keypress", (key) => {
if (key.ctrl && key.name === "q") {
process.exit(0)
}
})
// Mouse events
box.onMouseDown = (event) => {
console.log("Mouse down at:", event.x, event.y)
}
From CONTRIBUTING.md:
AGENTS.md)CRITICAL ANTI-PATTERN: NEVER create conversational interfaces with AI in CLI/TUI applications. Always use structured, tool-based interactions.
OpenCode (https://opencode.ai) provides AI coding agent capabilities via TypeScript SDK. OpenTUI is the perfect framework for building CLI/TUI interfaces that leverage OpenCode's AI capabilities.
Installation:
bun add @opencode-ai/sdk
bun add zod # For schema validation
NEVER DO THIS (Conversational anti-pattern):
// ❌ BAD: Conversational interaction
async function badCLI() {
const response = await client.chat.send("What would you like to do?")
const userInput = await getUserInput()
const nextResponse = await client.chat.send(userInput)
// This creates a frustrating back-and-forth conversation
}
ALWAYS DO THIS (Structured tool pattern):
// ✅ GOOD: Structured tool-based interaction
import { createOpencodeClient } from "@opencode-ai/sdk"
import { tool } from "@opencode-ai/plugin"
import { z } from "zod"
// Define clear, structured tool schema
const analyzeCodeTool = tool({
description: "Analyze code quality and suggest improvements",
args: {
filePath: tool.schema.string().describe("Path to file to analyze"),
checkTypes: tool.schema.array(
tool.schema.enum(["performance", "security", "readability"])
).describe("Types of checks to run"),
outputFormat: tool.schema.enum(["json", "table", "summary"]).describe("Output format"),
},
async execute(args) {
// Execute structured analysis
return { findings: [], score: 85 }
},
})
import { createOpencodeClient } from "@opencode-ai/sdk"
import type { Session, Message, Part } from "@opencode-ai/sdk"
const client = createOpencodeClient({
baseUrl: "http://localhost:4096", // Default OpenCode server
})
// Use SDK for structured operations
const projects = await client.project.list()
const agents = await client.app.agents()
// Log events
await client.app.log({
body: {
service: "my-tui-app",
level: "info",
message: "Operation completed",
},
})
Pattern: Command → Tool → Structured Output
// 1. Define Zod schemas for all operations
const RefactorSchema = z.object({
targetFunction: z.string().describe("Function name to refactor"),
extractMethods: z.array(z.string()).describe("Methods to extract"),
renameVariables: z.record(z.string()).describe("Variable renames"),
})
// 2. Create tool with schema
const refactorTool = tool({
description: "Refactor code with specific transformations",
args: {
filePath: tool.schema.string(),
operations: tool.schema.object(RefactorSchema.shape),
},
async execute(args) {
// Execute deterministic refactor
return { success: true, changes: [] }
},
})
// 3. Build TUI with structured input/output
function buildRefactorTUI(renderer) {
const form = Box(
{},
Text({ content: "Refactor Code", attributes: TextAttributes.BOLD }),
Input({ id: "file-path", placeholder: "Enter file path..." }),
Select({
id: "operations",
options: [
{ name: "Extract Method", value: "extract" },
{ name: "Rename Variable", value: "rename" },
],
}),
Button({
id: "execute",
label: "Execute Refactor",
onClick: async () => {
const result = await refactorTool.execute({
filePath: getInputValue("file-path"),
operations: getSelectedOperations(),
})
displayResults(result) // Show structured results
},
})
)
return form
}
Create tools in .opencode/tool/ directory:
// .opencode/tool/tui-analyze.ts
import { tool } from "@opencode-ai/plugin"
export default tool({
description: "Analyze codebase and display in TUI",
args: {
path: tool.schema.string().describe("Directory to analyze"),
depth: tool.schema.number().optional().describe("Max depth to traverse"),
format: tool.schema.enum(["tree", "table", "graph"]).describe("Display format"),
},
async execute(args, context) {
// Return structured data for TUI rendering
return {
totalFiles: 42,
languages: { typescript: 30, javascript: 12 },
suggestions: [
{ file: "src/main.ts", issue: "Large function", severity: "medium" }
],
}
},
})
// .opencode/tool/database-tools.ts
import { tool } from "@opencode-ai/plugin"
export const queryTool = tool({
description: "Execute SQL query with validation",
args: {
query: tool.schema.string().describe("SQL query to execute"),
limit: tool.schema.number().max(1000).optional(),
},
async execute(args) {
// Execute and return structured results
return { rows: [], count: 0, executionTime: "12ms" }
},
})
export const schemaTool = tool({
description: "Get database schema information",
args: {
tableName: tool.schema.string().optional(),
},
async execute(args) {
return { tables: [], columns: [] }
},
})
// Creates: database-tools_query and database-tools_schema
See references/opencode-integration.md for complete examples including:
❌ Multi-turn conversations in CLI ❌ "What would you like me to do?" prompts ❌ Ambiguous natural language without structure ❌ AI responses that ask questions back ❌ Free-form chat interfaces in terminal
✅ Structured forms with Zod validation ✅ Tool calls with complete parameters ✅ Immediate execution with structured output ✅ Progress indicators for long operations ✅ Results displayed in tables/trees/lists
Documentation:
packages/core/docs/getting-started.mdpackages/core/docs/tree-sitter.mdpackages/core/docs/env-vars.mdpackages/core/docs/renderables-vs-constructs.mdreferences/opencode-integration.mdExamples:
packages/core/src/examples/ - Reference implementationsAgent Guidelines:
AGENTS.md - Development standards and best practicesGitHub:
.github/workflows/opencode.yml - OpenCode integrationWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub danielbodnar/agent-plugins --plugin bodnar-skills28 skills in this plugin
/act-platform-engineeringToolkit for Daniel Bodnar's Animal Care Technologies (ACT) platform engineering, SRE, sysadmin, and DBA work. Use this skill whenever the user mentions ACT, vsurv_production, dbprimary, pimsserver, payment gateway reliability, Zach's Bodnar Tasks, Internal Needs (EC-142), Sysadmin/IAC (EC-120), Zoho Projects task or issue creation, PostgreSQL or ZFS assessment on ACT infrastructure, PVE nodes (10.0.50.1-3), the act-infra repo, WAL shipping, dbhotswap failover, PVE3 failing drives, PowerEdge 730, Pims Garden, Miller, Ben Jumper, the assessment cheatsheet or checklist, observability deployment (Grafana, Netdata), centralized log management, secrets management, or pimsserver branch consolidation. Trigger even when the user uses shorthand like "the assessment", "the checklist", "INT-XX", "SY1-XX", or references infrastructure work without explicit naming. Also use when drafting Zoho tasks/issues, running assessment commands on dbprimary, or generating documentation for ACT infrastructure./aitmpl-composeAuthor and compose `claude-code-templates` (aitmpl.com) workflows. Use whenever the user wants to bundle catalog components (agents, commands, MCPs, hooks, settings, skills) into a reusable `workflow.yaml` or `template.json`, merge multiple templates or workflows, expand Bodnar `pack` macros, validate a workflow against the live catalog, or scaffold `.claude/workflows/`. Trigger on "aitmpl", "claude-code-templates", "compose templates", "merge templates", "scaffold a workflow", "share my Claude Code setup", "author a workflow", "author a template", "make a pack", "new pack", "expand pack", "validate workflow.yaml", or any mention of `npx claude-code-templates@latest --workflow` or `--template`. Also use when the user lists components to assemble, or describes a project intent (such as a Cloudflare Worker scaffold with security hardening) that should resolve to a concrete component bundle. Output is upstream-native YAML in `.claude/workflows/`; never invent a parallel bundle format.