|
| 1 | +# Claude Code Universal Behavior Guidelines |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +This document defines universal behavior guidelines for Claude Code across all commands and workflows. These principles apply regardless of the specific command being executed. |
| 6 | + |
| 7 | +## Core Principles |
| 8 | + |
| 9 | +### 1. Complete Documentation |
| 10 | +- Document every action you take in the appropriate JSON file |
| 11 | +- Track all files created, modified, or deleted |
| 12 | +- Capture task progress and status changes |
| 13 | +- Include all relevant context, decisions, and assumptions |
| 14 | +- Never assume information is obvious - document everything explicitly |
| 15 | + |
| 16 | +### 2. Consistent Output Format |
| 17 | +- Always use the unified JSON schema (see below) |
| 18 | +- Include all required fields for the relevant status |
| 19 | +- Use optional fields as needed to provide additional context |
| 20 | +- Validate JSON structure before completing work |
| 21 | +- Ensure JSON is properly formatted and parseable |
| 22 | + |
| 23 | +### 3. Session Management & Stateful Resumption |
| 24 | +- Claude Code provides a session ID that maintains conversation context automatically |
| 25 | +- Always include `session_id` in your output to enable seamless continuation |
| 26 | +- When resuming work from a previous session, include `parent_session_id` to link sessions |
| 27 | +- The session ID allows Claude Code to preserve full conversation history |
| 28 | +- If you need user input, the context is preserved via session ID |
| 29 | +- Include enough detail in `session_summary` to understand what was accomplished |
| 30 | +- Don't make the user repeat information - session maintains context |
| 31 | + |
| 32 | +### 4. Task Management |
| 33 | +- Track all tasks in JSON output files (NOT in separate markdown files) |
| 34 | +- Use hierarchical task IDs: "1.0" for parent, "1.1", "1.2" for children |
| 35 | +- Track task status: pending, in_progress, completed, skipped, blocked |
| 36 | +- Include task descriptions and any relevant notes |
| 37 | +- Update task status as you work |
| 38 | +- Document which tasks were completed in each session |
| 39 | +- Note any tasks that were skipped and explain why |
| 40 | +- When blocked, document the blocker clearly |
| 41 | + |
| 42 | +### 5. Query Management |
| 43 | +- Save all queries to users in the session JSON file |
| 44 | +- When querying users, include: |
| 45 | + - Clear, specific questions |
| 46 | + - Query type (text, multiple_choice, boolean) |
| 47 | + - Any relevant context needed to answer |
| 48 | + - Query number for reference |
| 49 | +- Save user responses in the same JSON file |
| 50 | +- Link queries and responses with query numbers |
| 51 | + |
| 52 | +## File Organization Structure |
| 53 | + |
| 54 | +All agent-related documents and files must be organized under the `agent-io` directory: |
| 55 | + |
| 56 | +``` |
| 57 | +agent-io/ |
| 58 | +├── prds/ |
| 59 | +│ └── <prd-name>/ |
| 60 | +│ ├── humanprompt.md # Original user description of PRD |
| 61 | +│ ├── aiprompt.md # AI-enhanced PRD description |
| 62 | +│ ├── fullprompt.md # Fully fleshed PRD after completion |
| 63 | +│ └── data.json # JSON file documenting queries, responses, tasks, etc. |
| 64 | +└── docs/ |
| 65 | + └── <document-name>.md # Architecture docs, usage docs, etc. |
| 66 | +``` |
| 67 | + |
| 68 | +### File Organization Guidelines: |
| 69 | +- **PRD Files**: Save to `agent-io/prds/<prd-name>/` directory |
| 70 | + - Each PRD gets its own directory named after the PRD |
| 71 | + - Use kebab-case for PRD names (e.g., "user-profile-editing", "payment-integration") |
| 72 | + - Directory contains: humanprompt.md, aiprompt.md, fullprompt.md, and data.json |
| 73 | + - The data.json file tracks all queries, responses, tasks, errors, and progress |
| 74 | + |
| 75 | +- **PRD Storage and Reference**: |
| 76 | + - **When user provides a prompt without a PRD name**: |
| 77 | + - Analyze the prompt to create a descriptive PRD name (use kebab-case) |
| 78 | + - Create directory: `agent-io/prds/<prd-name>/` |
| 79 | + - Save the original user prompt to `agent-io/prds/<prd-name>/humanprompt.md` |
| 80 | + - Document the PRD name in your output for future reference |
| 81 | + - This allows users to reference this PRD by name in future sessions |
| 82 | + |
| 83 | + - **When user references an existing PRD by name**: |
| 84 | + - Look for the PRD directory: `agent-io/prds/<prd-name>/` |
| 85 | + - Read available PRD files in order of preference: |
| 86 | + 1. `fullprompt.md` - the complete, finalized PRD (if available) |
| 87 | + 2. `aiprompt.md` - the AI-enhanced version (if available) |
| 88 | + 3. `humanprompt.md` - the original user description |
| 89 | + - Use these files as context for the requested work |
| 90 | + - Update or create additional files as needed |
| 91 | + |
| 92 | + - **PRD Naming Best Practices**: |
| 93 | + - Use descriptive, feature-focused names |
| 94 | + - Keep names concise (2-4 words typically) |
| 95 | + - Use kebab-case consistently |
| 96 | + - Examples: "user-authentication", "payment-processing", "real-time-notifications" |
| 97 | + |
| 98 | +- **Documentation Files**: Save to `agent-io/docs/` |
| 99 | + - Architecture documentation: `agent-io/docs/<project-name>-architecture.md` |
| 100 | + - Usage documentation: `agent-io/docs/<project-name>-usage.md` |
| 101 | + - Other documentation as appropriate |
| 102 | + |
| 103 | +- **Code Files**: Save to appropriate project locations |
| 104 | + - Follow existing project structure |
| 105 | + - Document each file in the JSON tracking file |
| 106 | + - Include purpose and type for each file |
| 107 | + |
| 108 | +### JSON Documentation Files: |
| 109 | +- Every PRD must have an associated `data.json` file in its directory |
| 110 | +- The data.json file documents: |
| 111 | + - Tasks and their status |
| 112 | + - Queries to users and their responses |
| 113 | + - Errors and problems encountered |
| 114 | + - Files created, modified, deleted |
| 115 | + - Session information and summaries |
| 116 | + - Comments and context |
| 117 | + |
| 118 | +## Unified JSON Output Schema |
| 119 | + |
| 120 | +Use this schema for all JSON output files: |
| 121 | + |
| 122 | +```json |
| 123 | +{ |
| 124 | + "command_type": "string (create-prd | doc-code-for-dev | doc-code-usage | free-agent | generate-tasks)", |
| 125 | + "status": "string (complete | incomplete | user_query | error)", |
| 126 | + "session_id": "string - Claude Code session ID for this execution", |
| 127 | + "parent_session_id": "string | null - Session ID of previous session when resuming work", |
| 128 | + "session_summary": "string - Brief summary of what was accomplished", |
| 129 | + |
| 130 | + "tasks": [ |
| 131 | + { |
| 132 | + "task_id": "string (e.g., '1.0', '1.1', '2.0')", |
| 133 | + "description": "string", |
| 134 | + "status": "string (pending | in_progress | completed | skipped | blocked)", |
| 135 | + "parent_task_id": "string | null", |
| 136 | + "notes": "string (optional details about completion/issues)" |
| 137 | + } |
| 138 | + ], |
| 139 | + |
| 140 | + "files": { |
| 141 | + "created": [ |
| 142 | + { |
| 143 | + "path": "string (relative to working directory)", |
| 144 | + "purpose": "string (why this file was created)", |
| 145 | + "type": "string (markdown | code | config | documentation)" |
| 146 | + } |
| 147 | + ], |
| 148 | + "modified": [ |
| 149 | + { |
| 150 | + "path": "string", |
| 151 | + "changes": "string (description of modifications)" |
| 152 | + } |
| 153 | + ], |
| 154 | + "deleted": [ |
| 155 | + { |
| 156 | + "path": "string", |
| 157 | + "reason": "string" |
| 158 | + } |
| 159 | + ] |
| 160 | + }, |
| 161 | + |
| 162 | + "artifacts": { |
| 163 | + "prd_filename": "string (for create-prd command)", |
| 164 | + "documentation_filename": "string (for doc-code commands)", |
| 165 | + "git_commit": "string | null (commit hash if committed)" |
| 166 | + }, |
| 167 | + |
| 168 | + "queries_for_user": [ |
| 169 | + { |
| 170 | + "query_number": "integer", |
| 171 | + "query": "string", |
| 172 | + "type": "string (text | multiple_choice | boolean)", |
| 173 | + "choices": [ |
| 174 | + { |
| 175 | + "id": "string", |
| 176 | + "value": "string" |
| 177 | + } |
| 178 | + ], |
| 179 | + "response": "string | null - User's response (populated after query is answered)" |
| 180 | + } |
| 181 | + ], |
| 182 | + |
| 183 | + "comments": [ |
| 184 | + "string - important notes, warnings, observations" |
| 185 | + ], |
| 186 | + |
| 187 | + "context": "string - optional supplementary state details. Session ID preserves full context automatically, so this field is only needed for additional implementation-specific state not captured in the conversation.", |
| 188 | + |
| 189 | + "metrics": { |
| 190 | + "duration_seconds": "number (optional)", |
| 191 | + "files_analyzed": "number (optional)", |
| 192 | + "lines_of_code": "number (optional)" |
| 193 | + }, |
| 194 | + |
| 195 | + "errors": [ |
| 196 | + { |
| 197 | + "message": "string", |
| 198 | + "type": "string", |
| 199 | + "fatal": "boolean" |
| 200 | + } |
| 201 | + ] |
| 202 | +} |
| 203 | +``` |
| 204 | + |
| 205 | +## Required Fields by Status |
| 206 | + |
| 207 | +### Status: "complete" |
| 208 | +- `command_type`, `status`, `session_id`, `session_summary`, `files`, `comments` |
| 209 | +- `parent_session_id` (if this session continues work from a previous session) |
| 210 | +- Plus any command-specific artifacts (prd_filename, documentation_filename, etc.) |
| 211 | +- `tasks` array if the command involves tasks |
| 212 | + |
| 213 | +### Status: "user_query" |
| 214 | +- `command_type`, `status`, `session_id`, `session_summary`, `queries_for_user` |
| 215 | +- `files` (for work done so far) |
| 216 | +- `comments` (explaining why input is needed) |
| 217 | +- `context` (optional - session_id maintains context automatically) |
| 218 | +- Note: When user provides answers, they'll create a new session with `parent_session_id` linking back to this one |
| 219 | + |
| 220 | +### Status: "incomplete" |
| 221 | +- `command_type`, `status`, `session_id`, `session_summary`, `files`, `comments` |
| 222 | +- Explanation in `comments` of what's incomplete and why |
| 223 | +- `errors` array if errors caused incompleteness |
| 224 | +- `context` (optional - session_id maintains context automatically) |
| 225 | + |
| 226 | +### Status: "error" |
| 227 | +- `command_type`, `status`, `session_id`, `session_summary`, `errors`, `comments` |
| 228 | +- `files` (if any work was done before error) |
| 229 | +- `context` (optional - for additional recovery details beyond what session maintains) |
| 230 | + |
| 231 | +## Error Handling |
| 232 | + |
| 233 | +When errors occur: |
| 234 | +1. Set status to "error" (or "incomplete" if partial work succeeded) |
| 235 | +2. Document the error in the `errors` array |
| 236 | +3. Include what failed, why it failed, and potential fixes |
| 237 | +4. Document any work that was completed before the error |
| 238 | +5. Provide context for potential recovery |
| 239 | +6. Save error details to the JSON file |
| 240 | + |
| 241 | +## Code Development Guidelines |
| 242 | + |
| 243 | +### Keep Code Simple |
| 244 | +- Prefer simple, straightforward implementations over clever or complex solutions |
| 245 | +- Write code that is easy to read and understand |
| 246 | +- Avoid unnecessary abstractions or over-engineering |
| 247 | +- Use clear, descriptive variable and function names |
| 248 | +- Comment complex logic, but prefer self-documenting code |
| 249 | + |
| 250 | +### Limit Complexity |
| 251 | +- Minimize the number of classes and Python files |
| 252 | +- Consolidate related functionality into fewer, well-organized modules |
| 253 | +- Only create new files when there's a clear separation of concerns |
| 254 | +- Avoid deep inheritance hierarchies |
| 255 | +- Prefer composition over inheritance when appropriate |
| 256 | + |
| 257 | +### Use JSON Schema Validation |
| 258 | +- All JSON files must have corresponding JSON schemas |
| 259 | +- Validate JSON files against their schemas |
| 260 | +- Document the schema in comments or separate schema files |
| 261 | +- Use schema validation to catch errors early |
| 262 | +- Keep schemas simple and focused |
| 263 | + |
| 264 | +### Keep Code Management Simple |
| 265 | +- Don't use excessive linting rules |
| 266 | +- Avoid complex documentation frameworks (like Sphinx) unless truly needed |
| 267 | +- Use simple, standard tools (pytest for testing, basic linting) |
| 268 | +- Focus on clear code over extensive tooling |
| 269 | +- Documentation should be clear markdown files, not generated sites |
| 270 | + |
| 271 | +## Best Practices |
| 272 | + |
| 273 | +- **Be Specific**: Include file paths, line numbers, function names |
| 274 | +- **Be Complete**: Don't leave out details assuming the user knows them |
| 275 | +- **Be Clear**: Write for someone who wasn't watching you work |
| 276 | +- **Be Actionable**: Comments should help the user understand next steps |
| 277 | +- **Be Honest**: If something is incomplete or uncertain, say so |
| 278 | +- **Be Consistent**: Follow the same patterns and conventions throughout |
| 279 | +- **Be Thorough**: Test your work and verify it functions correctly |
| 280 | +- **Be Organized**: Maintain clean directory structure and file organization |
| 281 | + |
| 282 | +## Workflow Principles |
| 283 | + |
| 284 | +### PRD Workflow |
| 285 | +1. User provides initial feature description → saved as `humanprompt.md` |
| 286 | +2. AI enhances and clarifies → saved as `aiprompt.md` |
| 287 | +3. Complete PRD after workflow → saved as `fullprompt.md` |
| 288 | +4. All progress tracked in `<prd-name>.json` |
| 289 | + |
| 290 | +### Task Workflow |
| 291 | +1. Break work into clear, manageable tasks |
| 292 | +2. Use hierarchical task IDs (1.0, 1.1, 1.2, 2.0, etc.) |
| 293 | +3. Update task status as work progresses |
| 294 | +4. Document completed work and any blockers |
| 295 | +5. Track everything in JSON file |
| 296 | + |
| 297 | +### Documentation Workflow |
| 298 | +1. Understand the codebase or feature thoroughly |
| 299 | +2. Create clear, well-organized documentation |
| 300 | +3. Save to appropriate location in `agent-io/docs/` |
| 301 | +4. Track file creation and content in JSON output |
| 302 | +5. Include examples and practical guidance |
| 303 | + |
| 304 | +### Query Workflow |
| 305 | +1. Only query when genuinely needed |
| 306 | +2. Ask clear, specific questions |
| 307 | +3. Save query to JSON file with query_number |
| 308 | +4. Wait for user response |
| 309 | +5. Save response to same JSON file |
| 310 | +6. Continue work with provided information |
0 commit comments