Loading...
Loading...
Run OpenCode CLI for code generation, analysis, and development tasks. Uses OAuth authentication. Use for rapid prototyping, code refactoring, testing, and automation. Preferred for load balancing sub-agent work (35% weight).
npx skill4agent add opendndapps/ogt-skills ogt-cli-opencodeopencodeopencode generate "Create a function that validates user emails"opencode generate --template react-component "Button with loading state"opencode analyze myfile.jsopencode test "src/utils/auth.js"# npm (recommended)
npm install -g opencode-cli
# Verify installation
opencode --version| Command | Description |
|---|---|
| Interactive mode |
| Generate code from description |
| Analyze code quality and structure |
| Generate test cases for file |
| Suggest refactoring improvements |
| Generate documentation |
| Option | Description |
|---|---|
| Use specific code template |
| Target language (js, ts, python, go, etc.) |
| Output file path |
| Output format (default, json, etc.) |
| Model variant (default, fast, quality) |
# First-time authentication
opencode auth login
# Check auth status
opencode auth status# Analyze a file
opencode analyze src/api.ts
# Generate tests for existing code
opencode test src/utils/helpers.js
# Refactor code
opencode refactor src/components/Form.jsx
# Generate documentation
opencode document src/services/auth.js# List available templates
opencode templates list
# Use a specific template
opencode generate --template express-api "User management API"
opencode generate --template react-form "Login form"
opencode generate --template node-cli "CLI tool for backups"# Generate code non-interactively
opencode generate "Express API with validation" 2>&1
# Analyze code and capture output
opencode analyze myfile.js --format json > analysis.json
# Generate tests
opencode test src/utils.js --output test/utils.test.js 2>&1
# Run with timeout
timeout 180 opencode generate "Database schema for e-commerce" 2>&1node {baseDir}/scripts/run-opencode-task.cjs "Your task prompt" [options]--action <action>generateanalyzetestrefactordocument--file <path>--template <name>--language <lang>--timeout <secs>--output <path>--workdir <path>| Variant | Best For |
|---|---|
| Quick generation, simple tasks |
| Balanced speed and quality (recommended) |
| Complex code, high-quality output |
opencode generate --model quality "Complex state management system"| Feature | OpenCode | Claude CLI | Gemini CLI | Copilot CLI |
|---|---|---|---|---|
| Template library | ✅ Extensive | ❌ | ❌ | ❌ |
| Test generation | ✅ Native | ❌ | ❌ | ❌ |
| Code analysis | ✅ Native | ❌ | ❌ | ❌ |
| Fast generation | ✅ Optimized | Slower | Medium | Medium |
| Extended context | ❌ | ✅ 200K tokens | ✅ 1M tokens | Limited |
opencode analyze myfile.js --format json | jq '.issues'# Output to file
opencode generate "REST API boilerplate" --output api.js
# Or redirect
opencode generate "Database schema" > schema.sql# Generate, format, then lint
opencode generate "Express app" | prettier --write /dev/stdin
# Generate test and run immediately
opencode test src/utils.js && npm test# Check auth status
opencode auth status
# Re-authenticate
opencode auth logout
opencode auth login# Verify installation
which opencode
# Reinstall
npm install -g opencode-cli# Use longer timeout or simpler prompt
timeout 300 opencode generate "Simpler version: Basic auth endpoint"
# Try fast model
opencode generate --model fast "Your prompt"# Use quality model
opencode generate --model quality "Complex feature needed here"
# Be more specific in prompt
opencode generate "User authentication API with JWT, email verification, and refresh tokens"
# Check templates first
opencode templates list