Custom instructions let you define coding standards, best practices, and project-specific guidelines that GitHub Copilot automatically applies to files matching specific patterns. This ensures consistent code quality across your project.
---description: 'React component best practices and standards'applyTo: '**/*.jsx, **/*.tsx'---# React Component Instructions## Component Structure- Use functional components with hooks- Define PropTypes or TypeScript interfaces for props- Export one component per file (named export)- Keep components under 300 lines## Naming Conventions- Component files: PascalCase (e.g., `UserProfile.tsx`)- Component names: Match filename- Props interfaces: `ComponentNameProps`- Event handlers: `handleEventName`## Best Practices- Use React.memo() for expensive renders- Extract custom hooks for reusable logic- Keep useState close to where it's used- Use useCallback for event handlers passed as props
2
Test the instructions
Create or edit a .jsx or .tsx file
Ask Copilot to generate a component
Verify it follows the guidelines
3
Refine
Adjust the instructions based on how well Copilot follows them
Here’s a production instructions file from the Awesome Copilot repository:
---description: 'Angular-specific coding standards and best practices'applyTo: '**/*.ts, **/*.html, **/*.scss, **/*.css'---# Angular Development InstructionsInstructions for generating high-quality Angular applications with TypeScript,using Angular Signals for state management, adhering to Angular best practicesas outlined at https://angular.dev.## Project Context- Latest Angular version (use standalone components by default)- TypeScript for type safety- Angular CLI for project setup and scaffolding- Follow Angular Style Guide (https://angular.dev/style-guide)- Use Angular Material or other modern UI libraries for consistent styling## Architecture- Use standalone components unless modules are explicitly required- Organize code by standalone feature modules or domains for scalability- Implement lazy loading for feature modules to optimize performance- Use Angular's built-in dependency injection system effectively- Structure components with clear separation (smart vs. presentational)## TypeScript- Enable strict mode in `tsconfig.json` for type safety- Define clear interfaces and types for components, services, and models- Use type guards and union types for robust type checking- Implement proper error handling with RxJS operators (e.g., `catchError`)- Use typed forms (e.g., `FormGroup`, `FormControl`) for reactive forms## State Management- Use Angular Signals for reactive state management in components/services- Leverage `signal()`, `computed()`, and `effect()` for reactive updates- Use writable signals for mutable state and computed signals for derived state- Handle loading and error states with signals and proper UI feedback- Use Angular's `AsyncPipe` to handle observables in templates
Provide links to official documentation and style guides. This helps Copilot generate more accurate, framework-appropriate code.
## Project Context- Framework: Next.js 14 with App Router- TypeScript: Strict mode enabled- Styling: Tailwind CSS- State: Zustand for global state- Testing: Vitest + React Testing Library
Coding standards and conventions:
## Development Standards### File Naming- Components: PascalCase (`UserCard.tsx`)- Utilities: camelCase (`formatDate.ts`)- Constants: UPPER_SNAKE_CASE in `constants.ts`### Code Style- Use functional components exclusively- Prefer arrow functions for components- Maximum function length: 50 lines- Extract complex logic into custom hooks
Framework-specific best practices:
## Best Practices### Performance- Use React.memo() for expensive renders- Implement code splitting with React.lazy()- Use useCallback for event handlers- Debounce user input handlers### Accessibility- All interactive elements must be keyboard accessible- Include ARIA labels for screen readers- Maintain proper heading hierarchy- Test with keyboard navigation
Step-by-step implementation guidance:
## Implementation Process1. Define TypeScript interfaces for props and state2. Create component skeleton with proper structure3. Implement business logic in custom hooks4. Add error handling and loading states5. Implement accessibility features6. Write unit tests with >80% coverage7. Document component usage with JSDoc
---description: 'Testing standards and best practices'applyTo: '**/*.test.ts, **/*.test.tsx, **/*.spec.ts'---# Testing Instructions## Test Structure- Use `describe` blocks to group related tests- One assertion per test when possible- Clear test names: "should [expected behavior] when [condition]"## Example Test StructureUse describe blocks to organize tests by component and scenario.Within each describe block, write focused it() statements.Follow the Arrange-Act-Assert pattern for test clarity.## Coverage Requirements- Minimum 80% code coverage- 100% coverage for critical paths- Test both happy path and error cases
---description: 'API service layer standards'applyTo: '**/services/**/*.ts, **/api/**/*.ts'---# API Service Instructions## Service StructureCreate a typed ApiResponse interface with data, optional error, and status fields.Build ApiService classes with a baseUrl property and generic get/post methods.Use TypeScript generics to ensure type safety for API responses.## Error Handling- Always wrap API calls in try-catch- Return typed error responses- Log errors with context- Retry failed requests (max 3 attempts)## Best Practices- Use TypeScript generics for type-safe responses- Implement request/response interceptors- Add timeout for all requests (30s default)- Cache GET requests where appropriate
Provide concrete examples, not vague guidelines.Good: “Use async/await instead of .then() chains”Avoid: “Use modern JavaScript features”
Include Code Examples
Show what good code looks like in your instructions file.Use descriptive text to explain patterns instead of showing raw code with JSX tags.
Define clear component signatures and explain expected prop interfaces.
Describe the structure rather than embedding complex code samples.
For projects with multiple languages, create separate instructions:
Frontend
Backend
Infrastructure
---description: 'Frontend TypeScript and React standards'applyTo: 'frontend/**/*.ts, frontend/**/*.tsx'---# Frontend Instructions- Use React 18+ with TypeScript- Implement strict null checks- Use Tailwind for styling...
---description: 'Backend Python and FastAPI standards'applyTo: 'backend/**/*.py'---# Backend Instructions- Use FastAPI with Pydantic models- Type hint all function signatures- Use async/await for I/O operations...
---description: 'Terraform infrastructure as code standards'applyTo: 'infrastructure/**/*.tf'---# Infrastructure Instructions- Use Terraform 1.5+- Define variables in variables.tf- Tag all resources with environment...