You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: introduce comment directives for inline development guidance
- Added @implement and @docs directives to streamline implementation instructions and documentation references within code comments.
- Provided detailed syntax, expected behavior, and examples for each directive to enhance developer workflow and maintainability.
- Emphasized best practices for using comment directives to improve clarity and traceability in code.
Copy file name to clipboardExpand all lines: claude-code-4.5/CLAUDE.md
+137Lines changed: 137 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,6 +36,143 @@ When creating a new project with its own claude.md (or other tool base system pr
36
36
- Purpose: This establishes our unique working relationship for each project context
37
37
</project_setup>
38
38
39
+
# Comment Directives
40
+
41
+
<comment_directives>
42
+
Special comment annotations enable inline implementation instructions and documentation references, streamlining development workflows and reducing context switching.
43
+
44
+
## @implement Directive
45
+
46
+
**Purpose**: Inline implementation instructions directly in code comments.
47
+
48
+
**Syntax**:
49
+
```
50
+
/* @implement [implementation instructions]
51
+
- Requirement 1
52
+
- Requirement 2
53
+
*/
54
+
```
55
+
56
+
**Behavior**:
57
+
1. Implement the specified changes
58
+
2. Transform the comment into proper documentation (JSDoc, inline comments)
59
+
3. Preserve intent and requirements in final documentation
60
+
4. Consider delegating to specialized agents (backend-developer, frontend-developer, superstar-engineer) for complex implementations
61
+
62
+
**Example**:
63
+
64
+
```typescript
65
+
/* @implement
66
+
Add Redis caching with 5-minute TTL:
67
+
- Cache by user ID
68
+
- Handle cache misses gracefully
69
+
- Log cache hit/miss metrics
70
+
*/
71
+
exportclassUserService {
72
+
// Implementation goes here
73
+
}
74
+
```
75
+
76
+
**After Implementation**:
77
+
```typescript
78
+
/**
79
+
* User service with Redis caching (5-minute TTL).
80
+
* Tracks cache hit/miss metrics for monitoring.
81
+
*/
82
+
exportclassUserService {
83
+
private cache =newRedisCache({ ttl: 300 });
84
+
85
+
async getUser(id:string):Promise<User> {
86
+
const cached =awaitthis.cache.get(id);
87
+
if (cached) {
88
+
this.metrics.increment('cache.hit');
89
+
returncached;
90
+
}
91
+
92
+
this.metrics.increment('cache.miss');
93
+
const user =awaitthis.fetchUser(id);
94
+
awaitthis.cache.set(id, user);
95
+
returnuser;
96
+
}
97
+
}
98
+
```
99
+
100
+
## @docs Directive
101
+
102
+
**Purpose**: Reference external documentation for implementation context.
103
+
104
+
**Syntax**:
105
+
```
106
+
/* @docs <external-documentation-url> */
107
+
```
108
+
109
+
**Behavior**:
110
+
1. Fetch the referenced documentation (use WebFetch tool)
111
+
2. Verify URL safety (security check)
112
+
3. Use documentation as implementation context
113
+
4. Preserve the `@docs` reference in code
114
+
5. Consider delegating to web-search-researcher agent for complex documentation exploration
Copy file name to clipboardExpand all lines: claude-code/CLAUDE.md
+149Lines changed: 149 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -183,6 +183,155 @@ Key principles:
183
183
- NEVER name things as 'improved' or 'new' or 'enhanced', etc. Code naming should be evergreen. What is new today will be "old" someday.
184
184
</documentation_standards>
185
185
186
+
<comment_directives>
187
+
## Comment Directives for Inline Development Guidance
188
+
189
+
Special comment annotations provide inline implementation instructions and documentation references, streamlining the development workflow and reducing context switching.
190
+
191
+
### @implement Directive
192
+
193
+
**Purpose**: Provide inline implementation instructions directly in code comments, enabling focused development without external context.
194
+
195
+
**Syntax**:
196
+
```
197
+
/* @implement [implementation instructions]
198
+
- Detail 1
199
+
- Detail 2
200
+
- Detail 3
201
+
*/
202
+
```
203
+
204
+
**Expected Behavior**:
205
+
When encountering an `@implement` directive, you MUST:
206
+
1.**Follow TDD**: Write tests first for the described implementation
207
+
2.**Implement**: Write minimal code to satisfy the tests
208
+
3.**Transform Comment**: Convert the `@implement` comment into proper documentation (JSDoc, inline comments, etc.)
209
+
4.**Maintain Traceability**: Preserve the intent and requirements in the final documentation
210
+
211
+
**Integration with TDD Workflow**:
212
+
1. Read the `@implement` directive
213
+
2. Write failing tests that validate the described behavior (RED)
214
+
3. Implement minimal code to pass tests (GREEN)
215
+
4. Refactor and improve documentation (REFACTOR)
216
+
5. Replace `@implement` with proper JSDoc/documentation
217
+
218
+
**Examples**:
219
+
220
+
```typescript
221
+
/* @implement
222
+
Add a caching layer for user data:
223
+
- Cache user objects by ID in a Map
224
+
- Expire entries after 5 minutes
225
+
- Return cached data when available
226
+
- Fetch from API only on cache miss
227
+
*/
228
+
exportclassUserService {
229
+
// Implementation will go here
230
+
}
231
+
```
232
+
233
+
**After Implementation**:
234
+
```typescript
235
+
/**
236
+
* Service for managing user data with a 5-minute TTL cache.
237
+
* Reduces API calls by serving cached user objects when available.
- Breaking down large features into manageable chunks
315
+
316
+
**Use `@docs` when**:
317
+
- Integrating with external libraries or APIs
318
+
- Following specific framework patterns
319
+
- Referencing standard protocols or specifications
320
+
- Documenting design decisions based on external sources
321
+
- Providing learning resources for future maintainers
322
+
323
+
### Best Practices
324
+
325
+
1.**Be Specific**: Provide clear, actionable implementation details in `@implement` directives
326
+
2.**Test First**: Always follow TDD—write tests before implementing `@implement` directives
327
+
3.**Update Documentation**: Transform `@implement` directives into proper documentation after implementation
328
+
4.**Verify URLs**: Ensure `@docs` references point to official, trustworthy documentation
329
+
5.**Keep References**: Preserve `@docs` comments in the codebase for long-term maintainability
330
+
6.**Combine Directives**: Use both together when external docs inform implementation
331
+
332
+
**Rationale**: Comment directives reduce context switching, provide inline guidance, maintain traceability of implementation decisions, and streamline communication between developer and AI assistant while maintaining the integrity of the TDD workflow.
0 commit comments