Coding & DevelopmentāØļøcursoršuniversal
OpenCode Rules Plugin
[WIP] An opencode plugin to handle rules files, like cursor
Quick Start
Install this Skill
npx skills add frap129/opencode-rules# OpenCode Rules Plugin
A lightweight OpenCode plugin that discovers and injects markdown rule files into AI agent system prompts, enabling flexible behavior customization without per-project configuration.
## Overview
OpenCode Rules automatically loads rule files from standard directories and integrates them into AI agent prompts, allowing you to:
- Define global coding standards that apply across all projects
- Create project-specific rules for team collaboration
- Apply conditional rules based on file patterns
- Maintain zero-configuration workflow with sensible defaults
## Features
- **Dual-format support**: Load rules from both `.md` and `.mdc` files
- **Conditional rules**: Apply rules based on file paths using glob patterns
- **Global and project-level rules**: Define rules at both system and project scopes
- **Context-aware injection**: Rules filtered by extracted file paths from messages
- **Zero-configuration**: Works out of the box with XDG Base Directory specification
- **TypeScript-first**: Built with TypeScript for type safety and developer experience
- **Performance optimized**: Efficient file discovery and minimal startup overhead
## Quick Start
### Installation
Add the plugin to your opoencode config:
```json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-rules"]
}
```
### Create Your First Rule
1. Create the global rules directory:
```bash
mkdir -p ~/.config/opencode/rules
```
2. Add a simple rule file:
```bash
cat > ~/.config/opencode/rules/coding-standards.md << 'EOF'
# Coding Standards
- Use meaningful variable names
- Follow the project's code style guide
- Write self-documenting code
EOF
```
That's it! The rule will now be automatically injected into all AI agent prompts.
## Configuration
### Rule Discovery Locations
Rules are automatically discovered from these directories:
1. **Global rules**: `$XDG_CONFIG_HOME/opencode/rules/` (typically `~/.config/opencode/rules/`)
2. **Project rules**: `.opencode/rules/` (in your project root)
### Supported File Formats
- `.md` - Standard markdown files with optional metadata
- `.mdc` - Markdown files with optional metadata
## Usage Examples
### Basic Rule File
Create `~/.config/opencode/rules/naming-convention.md`:
```markdown
# Naming Convention Rules
- Use camelCase for variables and functions
- Use PascalCase for classes and interfaces
- Use UPPER_SNAKE_CASE for constants
- Prefix private properties with underscore
```
### Conditional Rule with Metadata
Create `~/.config/opencode/rules/typescript.mdc`:
```markdown
---
globs:
- '**/*.ts'
- '**/*.tsx'
---
# TypeScript Best Practices
- Always use `const` and `let`, avoid `var`
- Use interfaces for object types
- Add type annotations for function parameters
- Avoid `any` type without justification
- Enable strict mode in tsconfig.json
```
This rule only applies when processing TypeScript files.
### Project-Specific Rules
Create `.opencode/rules/react-components.mdc` in your project:
```markdown
---
globs:
- 'src/components/**/*.tsx'
---
# React Component Guidelines
- Use functional components with hooks
- Export components as named exports
- Include PropTypes or TypeScript interfaces
- Use React.memo for expensive components
- Co-locate styles with components
```
## Metadata Format
Both `.md` and `.mdc` files support optional YAML metadata for conditional rule application:
```yaml
---
globs:
- 'src/**/*.ts'
- 'lib/**/*.js'
- '*.test.ts'
---
```
### Supported Fields
- `globs` (optional): Array of glob patterns for conditional application
- If specified: Rule applies only to files matching at least one pattern
- If omitted: Rule applies unconditionally
## Glob Pattern Reference
The plugin uses `minimatch` for pattern matching:
| Pattern | Matches |
| ----------------------------- | ----------------------------------------------- |
| `src/**/*.ts` | All TypeScript files in src and subdirectories |
| `**/*.test.ts` | All test files at any depth |
| `src/components/**/*.tsx` | React components in components directory |
| `*.json` | JSON files in root directory only |
| `lib/{utils,helpers}/**/*.js` | JavaScript files in specific lib subdirectories |
## Development
### Project Structure
```
opencode-rules/
āāā src/
ā āāā index.ts # Main plugin entry point
ā āāā utils.ts # File discovery and processing utilities
ā āāā index.test.ts # Test suite
āāā docs/
ā āāā rules.md # Detailed usage documentation
āāā openspec/ # Project specifications and proposals
āāā dist/ # Compiled JavaScript output
```
### Build and Test
```bash
# Install dependencies
bun install
# Run tests in watch mode
bun run test
# Run tests once
bun run test:run
# Build the project
bun run
... (truncated)Related Skills
More coding & development skills you might like
Reticle
Coding & DevelopmentAI agents can generate code, but still struggle to understand what they build. Reticle brings Jev-style machine-native runtime perception to web & desktop applications.
š¤claudešuniversal
1.2k
190
View
agentscope-java
Coding & DevelopmentExpert Java developer skill for AgentScope Java framework - a reactive, message-driven multi-agent system built on Project Reactor. Use when working with reactive programming, LLM integration, agent orchestration, multi-agent systems, or when the user mentions AgentScope, ReActAgent, Mono/Flux, Project Reactor, or Java agent development. Specializes in non-blocking code, tool integration, hooks, pipelines, and production-ready agent applications.
šuniversal
6.0k
1.5k
View
ospec
Coding & DevelopmentDocument-driven OSpec workflow for initialization, change/goal routing, validation, archiving, and durable project knowledge.
āØgeminiš¤claudeš¬gptšuniversal
524
34
View
misakanet-failure-memory
Coding & Developmentš A zero-dependency, git-backed micro-lesson library for AI Agents to asynchronously share and search verified debugging experience. Python stdlib only. | https://misakanet.org
š¤claudeāØļøcursoršuniversal
424
158
View