Major OpenCode integration overhaul: - llms.txt: Comprehensive OpenCode documentation for LLMs (642 lines) - .opencode/plugins/ecc-hooks.ts: All Claude Code hooks translated to OpenCode's plugin system - .opencode/tools/*.ts: 3 custom tools (run-tests, check-coverage, security-audit) - .opencode/commands/*.md: All 24 commands in OpenCode format - .opencode/package.json: npm package structure for opencode-ecc - .opencode/index.ts: Main plugin entry point - Delete incorrect LIMITATIONS.md (hooks ARE supported via plugins) - Rewrite MIGRATION.md with correct hook event mapping - Update README.md OpenCode section to show full feature parity OpenCode has 20+ events vs Claude Code's 3 phases: - PreToolUse → tool.execute.before - PostToolUse → tool.execute.after - Stop → session.idle - SessionStart → session.created - SessionEnd → session.deleted - Plus: file.edited, file.watcher.updated, permission.asked, todo.updated - 12 agents: Full parity - 24 commands: Full parity (+1 from original 23) - 16 skills: Full parity - Hooks: OpenCode has MORE (20+ events vs 3 phases) - Custom Tools: 3 native OpenCode tools The OpenCode configuration can now be: 1. Used directly: cd everything-claude-code && opencode 2. Installed via npm: npm install opencode-ecc
7.7 KiB
Everything Claude Code - OpenCode Instructions
This document consolidates the core rules and guidelines from the Claude Code configuration for use with OpenCode.
Security Guidelines (CRITICAL)
Mandatory Security Checks
Before ANY commit:
- No hardcoded secrets (API keys, passwords, tokens)
- All user inputs validated
- SQL injection prevention (parameterized queries)
- XSS prevention (sanitized HTML)
- CSRF protection enabled
- Authentication/authorization verified
- Rate limiting on all endpoints
- Error messages don't leak sensitive data
Secret Management
// 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')
}
Security Response Protocol
If security issue found:
- STOP immediately
- Use security-reviewer agent
- Fix CRITICAL issues before continuing
- Rotate any exposed secrets
- Review entire codebase for similar issues
Coding Style
Immutability (CRITICAL)
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
}
}
File Organization
MANY SMALL FILES > FEW LARGE FILES:
- High cohesion, low coupling
- 200-400 lines typical, 800 max
- Extract utilities from large components
- Organize by feature/domain, not by type
Error Handling
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')
}
Input Validation
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)
Code Quality Checklist
Before marking work complete:
- Code is readable and well-named
- Functions are small (<50 lines)
- Files are focused (<800 lines)
- No deep nesting (>4 levels)
- Proper error handling
- No console.log statements
- No hardcoded values
- No mutation (immutable patterns used)
Testing Requirements
Minimum Test Coverage: 80%
Test Types (ALL required):
- Unit Tests - Individual functions, utilities, components
- Integration Tests - API endpoints, database operations
- E2E Tests - Critical user flows (Playwright)
Test-Driven Development
MANDATORY workflow:
- Write test first (RED)
- Run test - it should FAIL
- Write minimal implementation (GREEN)
- Run test - it should PASS
- Refactor (IMPROVE)
- Verify coverage (80%+)
Troubleshooting Test Failures
- Use tdd-guide agent
- Check test isolation
- Verify mocks are correct
- Fix implementation, not tests (unless tests are wrong)
Git Workflow
Commit Message Format
<type>: <description>
<optional body>
Types: feat, fix, refactor, docs, test, chore, perf, ci
Pull Request Workflow
When creating PRs:
- Analyze full commit history (not just latest commit)
- Use
git diff [base-branch]...HEADto see all changes - Draft comprehensive PR summary
- Include test plan with TODOs
- Push with
-uflag if new branch
Feature Implementation Workflow
-
Plan First
- Use planner agent to create implementation plan
- Identify dependencies and risks
- Break down into phases
-
TDD Approach
- Use tdd-guide agent
- Write tests first (RED)
- Implement to pass tests (GREEN)
- Refactor (IMPROVE)
- Verify 80%+ coverage
-
Code Review
- Use code-reviewer agent immediately after writing code
- Address CRITICAL and HIGH issues
- Fix MEDIUM issues when possible
-
Commit & Push
- Detailed commit messages
- Follow conventional commits format
Agent Orchestration
Available Agents
| 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 |
Immediate Agent Usage
No user prompt needed:
- Complex feature requests - Use planner agent
- Code just written/modified - Use code-reviewer agent
- Bug fix or new feature - Use tdd-guide agent
- Architectural decision - Use architect agent
Performance Optimization
Model Selection Strategy
Haiku (90% of Sonnet capability, 3x cost savings):
- Lightweight agents with frequent invocation
- Pair programming and code generation
- Worker agents in multi-agent systems
Sonnet (Best coding model):
- Main development work
- Orchestrating multi-agent workflows
- Complex coding tasks
Opus (Deepest reasoning):
- Complex architectural decisions
- Maximum reasoning requirements
- Research and analysis tasks
Context Window Management
Avoid last 20% of context window for:
- Large-scale refactoring
- Feature implementation spanning multiple files
- Debugging complex interactions
Build Troubleshooting
If build fails:
- Use build-error-resolver agent
- Analyze error messages
- Fix incrementally
- Verify after each fix
Common Patterns
API Response Format
interface ApiResponse<T> {
success: boolean
data?: T
error?: string
meta?: {
total: number
page: number
limit: number
}
}
Custom Hooks Pattern
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
}
Repository Pattern
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>
}
OpenCode-Specific Notes
Since OpenCode does not support hooks, the following actions that were automated in Claude Code must be done manually:
After Writing/Editing Code
- Run
prettier --write <file>to format JS/TS files - Run
npx tsc --noEmitto check for TypeScript errors - Check for console.log statements and remove them
Before Committing
- Run security checks manually
- Verify no secrets in code
- Run full test suite
Commands Available
Use 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 workflow
Success Metrics
You are successful when:
- All tests pass (80%+ coverage)
- No security vulnerabilities
- Code is readable and maintainable
- Performance is acceptable
- User requirements are met