.opencode/instructions/INSTRUCTIONS.md
This document consolidates the core rules and guidelines from the Claude Code configuration for use with OpenCode.
Before ANY commit:
// NEVER: Hardcoded secrets
const apiKey = "sk-proj-xxxxx"
// ALWAYS: Environment variables
const apiKey = process.env.OPENAI_API_KEY
if (!apiKey) {
throw new Error('OPENAI_API_KEY not configured')
}
If security issue found:
ALWAYS create new objects, NEVER mutate:
// WRONG: Mutation
function updateUser(user, name) {
user.name = name // MUTATION!
return user
}
// CORRECT: Immutability
function updateUser(user, name) {
return {
...user,
name
}
}
MANY SMALL FILES > FEW LARGE FILES:
ALWAYS handle errors comprehensively:
try {
const result = await riskyOperation()
return result
} catch (error) {
console.error('Operation failed:', error)
throw new Error('Detailed user-friendly message')
}
ALWAYS validate user input:
import { z } from 'zod'
const schema = z.object({
email: z.string().email(),
age: z.number().int().min(0).max(150)
})
const validated = schema.parse(input)
Before marking work complete:
Test Types (ALL required):
MANDATORY workflow:
<type>: <description>
<optional body>
Types: feat, fix, refactor, docs, test, chore, perf, ci
When creating PRs:
git diff [base-branch]...HEAD to see all changes-u flag if new branchPlan First
TDD Approach
Code Review
Commit & Push
| Agent | Purpose | When to Use |
|---|---|---|
| planner | Implementation planning | Complex features, refactoring |
| architect | System design | Architectural decisions |
| tdd-guide | Test-driven development | New features, bug fixes |
| code-reviewer | Code review | After writing code |
| security-reviewer | Security analysis | Before commits |
| build-error-resolver | Fix build errors | When build fails |
| e2e-runner | E2E testing | Critical user flows |
| refactor-cleaner | Dead code cleanup | Code maintenance |
| doc-updater | Documentation | Updating docs |
| go-reviewer | Go code review | Go projects |
| go-build-resolver | Go build errors | Go build failures |
| database-reviewer | Database optimization | SQL, schema design |
No user prompt needed:
Haiku (90% of Sonnet capability, 3x cost savings):
Sonnet (Best coding model):
Opus (Deepest reasoning):
Avoid last 20% of context window for:
If build fails:
interface ApiResponse<T> {
success: boolean
data?: T
error?: string
meta?: {
total: number
page: number
limit: number
}
}
export function useDebounce<T>(value: T, delay: number): T {
const [debouncedValue, setDebouncedValue] = useState<T>(value)
useEffect(() => {
const handler = setTimeout(() => setDebouncedValue(value), delay)
return () => clearTimeout(handler)
}, [value, delay])
return debouncedValue
}
interface Repository<T> {
findAll(filters?: Filters): Promise<T[]>
findById(id: string): Promise<T | null>
create(data: CreateDto): Promise<T>
update(id: string, data: UpdateDto): Promise<T>
delete(id: string): Promise<void>
}
Since OpenCode does not support hooks, the following actions that were automated in Claude Code must be done manually:
prettier --write <file> to format JS/TS filesnpx tsc --noEmit to check for TypeScript errorsUse these commands in OpenCode:
/plan - Create implementation plan/tdd - Enforce TDD workflow/code-review - Review code changes/security - Run security review/build-fix - Fix build errors/e2e - Generate E2E tests/refactor-clean - Remove dead code/orchestrate - Multi-agent workflowYou are successful when: