Back to Skills

oclif-patterns

verified

Enterprise CLI patterns using oclif framework with TypeScript. Use when building oclif CLIs, creating plugins, implementing commands with flags/args, adding auto-documentation, testing CLI commands, or when user mentions oclif, enterprise CLI, TypeScript CLI, plugin system, or CLI testing.

View on GitHub

Marketplace

cli-builder

vanman2024/cli-builder

Plugin

cli-builder

development

Repository

vanman2024/cli-builder

plugins/cli-builder/skills/oclif-patterns/SKILL.md

Last Verified

January 22, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/vanman2024/cli-builder/blob/main/plugins/cli-builder/skills/oclif-patterns/SKILL.md -a claude-code --skill oclif-patterns

Installation paths:

Claude
.claude/skills/oclif-patterns/
Powered by add-skill CLI

Instructions

# oclif Enterprise CLI Patterns

Provides comprehensive patterns for building production-grade CLIs with oclif framework.

## Core Capabilities

### 1. Command Structure
- Single and multi-command CLIs
- Flag definitions (string, boolean, integer, custom)
- Argument parsing with validation
- Command inheritance and base classes
- Async command execution

### 2. Plugin System
- Installable plugins
- Plugin discovery and loading
- Hook system for extensibility
- Plugin commands and lifecycle

### 3. Auto-Documentation
- Auto-generated help text
- README generation
- Command reference docs
- Flag and argument documentation

### 4. Testing Patterns
- Command unit tests
- Integration testing
- Mock stdin/stdout
- Fixture management
- Test helpers

## Implementation Guide

### Command Creation

**Use templates**:
- `templates/command-basic.ts` - Simple command with flags
- `templates/command-advanced.ts` - Complex command with validation
- `templates/command-async.ts` - Async operations
- `templates/base-command.ts` - Custom base class

**Key patterns**:
1. Import Command from '@oclif/core'
2. Define flags using `Flags` object
3. Define args using `Args` object
4. Implement async run() method
5. Use this.log() for output
6. Use this.error() for errors

### Flag Patterns

**Common flags**:
- String: `Flags.string({ description, required, default })`
- Boolean: `Flags.boolean({ description, allowNo })`
- Integer: `Flags.integer({ description, min, max })`
- Custom: `Flags.custom<T>({ parse: async (input) => T })`
- Multiple: `Flags.string({ multiple: true })`

**Best practices**:
- Always provide clear descriptions
- Use char for common short flags
- Set required vs optional explicitly
- Provide sensible defaults
- Validate in parse function for custom flags

### Argument Patterns

**Definition**:
```typescript
static args = {
  name: Args.string({ description: 'Name', required: true }),
  file: Args.file({ description: 'File path', exists: true })
}
```

**Access in run()*

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
6161 chars