Skip to content

doc

Generate or update documentation including API docs, README files, code comments, and technical specifications.

/doc [target | 'api' | 'readme' | 'changelog']
  • $ARGUMENTS:
    • File/function path: Document specific code
    • api: Generate API documentation
    • readme: Update README file
    • changelog: Generate changelog from commits

Generate documentation for: $ARGUMENTS

  1. Analyze Code

    • Read the code thoroughly
    • Understand purpose and behavior
    • Identify inputs and outputs
    • Note side effects
  2. Generate Documentation

    • Add docstrings/JSDoc
    • Include examples
    • Document edge cases
    • Add type annotations
  1. Find All Endpoints

    • Scan route definitions
    • Identify HTTP methods
    • Note authentication requirements
  2. Document Each Endpoint

    • Request format
    • Response format
    • Error responses
    • Examples
  1. Analyze Project

    • Purpose and features
    • Installation steps
    • Usage examples
    • Configuration
  2. Generate/Update

    • Clear structure
    • Working examples
    • Up-to-date info
  1. Analyze Commits

    Terminal window
    git log --oneline --since="last release"
  2. Categorize Changes

    • Added
    • Changed
    • Fixed
    • Removed
def calculate_discount(price: float, percentage: float) -> float:
"""
Calculate discounted price.
Args:
price: Original price in dollars.
percentage: Discount percentage (0-100).
Returns:
The discounted price.
Raises:
ValueError: If percentage is not between 0 and 100.
Example:
>>> calculate_discount(100.0, 20)
80.0
"""
/**
* Calculate discounted price.
*
* @param price - Original price in dollars
* @param percentage - Discount percentage (0-100)
* @returns The discounted price
* @throws {RangeError} If percentage is not between 0 and 100
*
* @example
* calculateDiscount(100, 20); // returns 80
*/
## POST /api/orders
Create a new order.
### Authentication
Requires Bearer token.
### Request Body
```json
{
"items": [
{ "productId": "123", "quantity": 2 }
],
"shippingAddress": {
"street": "123 Main St",
"city": "New York",
"zip": "10001"
}
}
{
"id": "order_456",
"status": "pending",
"total": 99.99,
"createdAt": "2024-01-15T10:00:00Z"
}
StatusCodeDescription
400INVALID_ITEMSItems array is empty
401UNAUTHORIZEDInvalid or missing token
422OUT_OF_STOCKItem not available
### README Section
```markdown
## Installation
```bash
npm install my-package
import { Client } from 'my-package';
const client = new Client({ apiKey: 'your-key' });
const result = await client.fetch();
OptionTypeDefaultDescription
apiKeystringrequiredYour API key
timeoutnumber5000Request timeout in ms
### Changelog Entry
```markdown
## [1.2.0] - 2024-01-15
### Added
- Password reset functionality (#123)
- Email verification for new accounts
### Changed
- Improved error messages for validation failures
- Updated dependencies to latest versions
### Fixed
- Race condition in session handling (#456)
- Incorrect timezone in date displays
## Documentation Updated
### Files Modified
- `src/services/auth.ts` - Added JSDoc comments
- `docs/api/auth.md` - New API documentation
- `README.md` - Updated configuration section
### Documentation Added
#### Code Comments
- `AuthService.login()` - Full JSDoc with examples
- `AuthService.logout()` - Parameter documentation
- `validateToken()` - Return type and exceptions
#### API Documentation
- POST /api/auth/login
- POST /api/auth/logout
- POST /api/auth/refresh
### Coverage
- Functions documented: 15/18 (83%)
- Endpoints documented: 12/12 (100%)
### Next Steps
1. Add examples to remaining functions
2. Create getting started guide
3. Add architecture diagram

Modify behavior via CLAUDE.md:

  • Documentation format
  • Required sections
  • Example requirements
  • API documentation tool

Always identify gaps and suggest next steps to users. In case there is no gaps anymore, then AI should clearly state that there is no gap left.