Code Development Skill
This skill provides a structured approach to coding tasks with emphasis on quality, security, and maintainability.
When to Use This Skill
Use this skill for any coding task including:
- Implementing new features or functionality
- Fixing bugs or issues
- Refactoring existing code
- Optimizing performance
- Adding or modifying tests
- Making any changes to source code
Core Development Workflow
1. Understand Before Coding
Before making changes:
- Read relevant existing code to understand current implementation
- Identify the scope of changes needed
- Consider edge cases and potential side effects
- Check for existing patterns and conventions in the codebase
2. Plan the Implementation
For non-trivial tasks:
- Use TodoWrite to break down the work into clear steps
- Identify files that need to be modified
- Consider the order of operations (e.g., tests before implementation, or vice versa)
- Plan for both happy path and error handling
3. Write Quality Code
Follow these principles:
Code Style & Conventions:
- Follow existing code style and patterns in the codebase
- Use spaces not tabs (per user configuration)
- Choose descriptive variable and function names
- Keep functions focused and single-purpose
- Add comments for complex logic, but prefer self-documenting code
Security Considerations:
- NEVER introduce security vulnerabilities
- Watch for: command injection, XSS, SQL injection, path traversal, insecure deserialization
- Validate and sanitize all user inputs
- Use parameterized queries for database operations
- Avoid hardcoding secrets or credentials
- Use secure defaults and principle of least privilege
- For detailed security guidance, consult
references/security-guidelines.md
Error Handling:
- Handle errors gracefully with appropriate error messages
- Avoid exposing sensitive information in error messages
- Clean up resources properly (close files, connections, etc.)
- Consider failure modes and recovery strategies
Performance:
- Avoid unnecessary computations or database queries
- Consider time and space complexity for data structures and algorithms
- Use caching appropriately
- Profile before optimizing (don't prematurely optimize)
4. Testing
Prefer integration tests over unit tests. Integration tests:
- Test the full application as users would interact with it
- Catch more bugs (import issues, config problems, integration bugs)
- Are easier to maintain during refactoring
- Provide confidence that the actual user experience works
When changing program behavior:
- Add tests (per user configuration)
- Write integration tests first - test the full application/CLI
- Run the actual application process, don't import functions directly
- Write tests that cover both happy path and edge cases
- Ensure existing tests still pass
- Add unit tests sparingly - only for complex logic that needs isolation
- Test error handling and boundary conditions
- For TypeScript/JavaScript, use Jest
- For deterministic output, add snapshot tests - snapshots provide excellent regression protection
- When making changes, update snapshots if test output changes (
npm test -- -u)
Test-driven development approach:
- Write failing integration test first (recommended)
- Implement the minimal code to make tests pass
- Refactor while keeping tests green
- Add unit tests only if needed for complex logic
For detailed testing guidance, consult references/testing-guidelines.md
5. Review Your Work
Before marking a task complete:
- Re-read the changes you made
- Check for introduced bugs or regressions
- Verify security considerations are addressed
- Ensure tests pass
- Look for opportunities to simplify
- Remove debug code, console.logs, or temporary changes
6. Iterate and Improve
If errors or issues arise:
- Don't mark tasks as complete if there are failures
- Debug systematically (check error messages, add logging, isolate the issue)
- Fix the root cause, not just symptoms
- Verify the fix works with tests
Common Patterns
When Editing Files
- Always use Read before Edit or Write
- Preserve exact indentation when using Edit tool
- Use Edit for targeted changes, Write for new files or complete rewrites
When Searching Code
- Use Grep for content search
- Use Glob for finding files by pattern
- Use Task tool with Explore agent for open-ended exploration
When Working with Git
- Check git status before committing
- Write clear, concise commit messages
- Don't commit secrets, credentials, or sensitive data
- Follow the repository's commit message conventions
Anti-Patterns to Avoid
- Don't write code without reading existing implementation
- Don't mark tasks complete when tests are failing
- Don't skip error handling or edge cases
- Don't introduce security vulnerabilities
- Don't hardcode values that should be configurable
- Don't duplicate code instead of extracting common functionality
- Don't leave commented-out code or debug statements
- Don't make changes without understanding the full impact
Language-Specific Considerations
When working in different languages, adapt to their idioms and best practices:
JavaScript/TypeScript:
- Use const/let, never var
- Prefer async/await over raw promises
- Handle promise rejections
- Use TypeScript types effectively
- Use Jest for testing
- Write integration tests that run the actual CLI/application process
Python:
- Follow PEP 8 style guidelines
- Use type hints for better code clarity
- Properly handle exceptions with try/except
- Use context managers (with statements) for resources
Go:
- Handle errors explicitly (don't ignore them)
- Use defer for cleanup
- Follow Go conventions (e.g., early returns)
Rust:
- Handle Result and Option types properly
- Use borrowing and ownership correctly
- Leverage the type system for safety
Java:
- Use appropriate exception handling
- Follow naming conventions (camelCase for methods/variables, PascalCase for classes)
- Properly close resources (use try-with-resources)
Best Practices Summary
- Read first, code second - Understand before changing
- Security by default - Never introduce vulnerabilities
- Test your changes - Write integration tests first, unit tests sparingly
- Follow conventions - Match the existing codebase style
- Handle errors properly - Don't let exceptions crash the system
- Review before submitting - Catch issues early
- Iterate on feedback - Fix problems until tests pass
For more detailed information on specific topics:
- Security best practices:
references/security-guidelines.md
- Testing strategies:
references/testing-guidelines.md
1---2name: dev-code3description: This skill should be used when performing any coding task including implementing features, fixing bugs, refactoring code, or making any modifications to source code. Provides best practices, security considerations, testing guidelines, and a structured workflow for development tasks.4---5
6# Code Development Skill
7
8This skill provides a structured approach to coding tasks with emphasis on quality, security, and maintainability.
9
10## When to Use This Skill
11
12Use this skill for any coding task including:
13- Implementing new features or functionality
14- Fixing bugs or issues
15- Refactoring existing code
16- Optimizing performance
17- Adding or modifying tests
18- Making any changes to source code
19
20## Core Development Workflow
21
22### 1. Understand Before Coding
23
24Before making changes:
25- Read relevant existing code to understand current implementation
26- Identify the scope of changes needed
27- Consider edge cases and potential side effects
28- Check for existing patterns and conventions in the codebase
29
30### 2. Plan the Implementation
31
32For non-trivial tasks:
33- Use TodoWrite to break down the work into clear steps
34- Identify files that need to be modified
35- Consider the order of operations (e.g., tests before implementation, or vice versa)
36- Plan for both happy path and error handling
37
38### 3. Write Quality Code
39
40Follow these principles:
41
42**Code Style & Conventions:**
43- Follow existing code style and patterns in the codebase
44- Use spaces not tabs (per user configuration)
45- Choose descriptive variable and function names
46- Keep functions focused and single-purpose
47- Add comments for complex logic, but prefer self-documenting code
48
49**Security Considerations:**
50- NEVER introduce security vulnerabilities
51- Watch for: command injection, XSS, SQL injection, path traversal, insecure deserialization
52- Validate and sanitize all user inputs
53- Use parameterized queries for database operations
54- Avoid hardcoding secrets or credentials
55- Use secure defaults and principle of least privilege
56- For detailed security guidance, consult `references/security-guidelines.md`
57
58**Error Handling:**
59- Handle errors gracefully with appropriate error messages
60- Avoid exposing sensitive information in error messages
61- Clean up resources properly (close files, connections, etc.)
62- Consider failure modes and recovery strategies
63
64**Performance:**
65- Avoid unnecessary computations or database queries
66- Consider time and space complexity for data structures and algorithms
67- Use caching appropriately
68- Profile before optimizing (don't prematurely optimize)
69
70### 4. Testing
71
72**Prefer integration tests over unit tests.** Integration tests:
73- Test the full application as users would interact with it
74- Catch more bugs (import issues, config problems, integration bugs)
75- Are easier to maintain during refactoring
76- Provide confidence that the actual user experience works
77
78When changing program behavior:
79- Add tests (per user configuration)
80- **Write integration tests first** - test the full application/CLI
81- Run the actual application process, don't import functions directly
82- Write tests that cover both happy path and edge cases
83- Ensure existing tests still pass
84- Add unit tests sparingly - only for complex logic that needs isolation
85- Test error handling and boundary conditions
86- For TypeScript/JavaScript, use Jest
87- **For deterministic output, add snapshot tests** - snapshots provide excellent regression protection
88- When making changes, update snapshots if test output changes (`npm test -- -u`)
89
90Test-driven development approach:
911. Write failing integration test first (recommended)
922. Implement the minimal code to make tests pass
933. Refactor while keeping tests green
944. Add unit tests only if needed for complex logic
95
96For detailed testing guidance, consult `references/testing-guidelines.md`
97
98### 5. Review Your Work
99
100Before marking a task complete:
101- Re-read the changes you made
102- Check for introduced bugs or regressions
103- Verify security considerations are addressed
104- Ensure tests pass
105- Look for opportunities to simplify
106- Remove debug code, console.logs, or temporary changes
107
108### 6. Iterate and Improve
109
110If errors or issues arise:
111- Don't mark tasks as complete if there are failures
112- Debug systematically (check error messages, add logging, isolate the issue)
113- Fix the root cause, not just symptoms
114- Verify the fix works with tests
115
116## Common Patterns
117
118### When Editing Files
119- Always use Read before Edit or Write
120- Preserve exact indentation when using Edit tool
121- Use Edit for targeted changes, Write for new files or complete rewrites
122
123### When Searching Code
124- Use Grep for content search
125- Use Glob for finding files by pattern
126- Use Task tool with Explore agent for open-ended exploration
127
128### When Working with Git
129- Check git status before committing
130- Write clear, concise commit messages
131- Don't commit secrets, credentials, or sensitive data
132- Follow the repository's commit message conventions
133
134## Anti-Patterns to Avoid
135
136- **Don't** write code without reading existing implementation
137- **Don't** mark tasks complete when tests are failing
138- **Don't** skip error handling or edge cases
139- **Don't** introduce security vulnerabilities
140- **Don't** hardcode values that should be configurable
141- **Don't** duplicate code instead of extracting common functionality
142- **Don't** leave commented-out code or debug statements
143- **Don't** make changes without understanding the full impact
144
145## Language-Specific Considerations
146
147When working in different languages, adapt to their idioms and best practices:
148
149**JavaScript/TypeScript:**
150- Use const/let, never var
151- Prefer async/await over raw promises
152- Handle promise rejections
153- Use TypeScript types effectively
154- Use Jest for testing
155- Write integration tests that run the actual CLI/application process
156
157**Python:**
158- Follow PEP 8 style guidelines
159- Use type hints for better code clarity
160- Properly handle exceptions with try/except
161- Use context managers (with statements) for resources
162
163**Go:**
164- Handle errors explicitly (don't ignore them)
165- Use defer for cleanup
166- Follow Go conventions (e.g., early returns)
167
168**Rust:**
169- Handle Result and Option types properly
170- Use borrowing and ownership correctly
171- Leverage the type system for safety
172
173**Java:**
174- Use appropriate exception handling
175- Follow naming conventions (camelCase for methods/variables, PascalCase for classes)
176- Properly close resources (use try-with-resources)
177
178## Best Practices Summary
179
1801. **Read first, code second** - Understand before changing
1812. **Security by default** - Never introduce vulnerabilities
1823. **Test your changes** - Write integration tests first, unit tests sparingly
1834. **Follow conventions** - Match the existing codebase style
1845. **Handle errors properly** - Don't let exceptions crash the system
1856. **Review before submitting** - Catch issues early
1867. **Iterate on feedback** - Fix problems until tests pass
187
188For more detailed information on specific topics:
189- Security best practices: `references/security-guidelines.md`
190- Testing strategies: `references/testing-guidelines.md`