new-task-tool.mdx 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. ---
  2. title: "New Task Tool"
  3. ---
  4. ### The `new_task` Tool & Context Management Strategies
  5. #### Overview
  6. Cline includes a powerful internal tool, `new_task`, designed to help manage workflow continuity and context preservation, especially during complex or long-running tasks. This tool, combined with Cline's awareness of its own context window usage and the flexibility of `.clinerules`, enables sophisticated strategies for breaking down work and ensuring seamless transitions between task sessions.
  7. Understanding the core capabilities and how they interact with custom rules is key to leveraging this feature effectively.
  8. #### Core Capabilities
  9. Two fundamental capabilities enable advanced context management:
  10. 1. **The `new_task` Tool:**
  11. - **Function:** Allows Cline, upon user approval, to end the current task session and immediately start a new one.
  12. - **Context Preloading:** Crucially, Cline can **preload** this new task session with specific context provided within the tool's `<context>` block. This context can be anything Cline or a `.clinerules` file defines – summaries, code snippets, next steps, project state, etc.
  13. 2. **Context Window Awareness:**
  14. - **Tracking:** Cline internally tracks the percentage of its available context window currently being used during a task.
  15. - **Visibility:** This information is visible in the `environment_details` provided to Cline in its prompt.
  16. #### Using the `/newtask` Slash Command
  17. As a quick alternative to Cline suggesting the `newtask` tool or defining complex rules, you can directly initiate the process using a Slash Command.
  18. - **How:** Simply type `/newtask` in the chat input field.
  19. - **Action:** Cline will propose creating a new task, typically suggesting context based on the current session (similar to its default behavior when using the tool). You will still get the `ask_followup_question` prompt to confirm and potentially modify the context before the new task is created.
  20. - **Benefit:** Provides a fast, user-initiated way to leverage the `new_task` functionality for branching explorations or managing long sessions without waiting for Cline to suggest it.
  21. <Note>
  22. For more details on using the `/newtask` slash command, see the [New Task Command](/features/slash-commands/new-task)
  23. documentation.
  24. </Note>
  25. #### Default Behavior (Without `.clinerules`)
  26. By default, without specific `.clinerules` dictating its behavior:
  27. - **Tool Availability:** The `new_task` tool exists, and Cline _can_ choose to use it.
  28. - **Context Awareness:** Cline _is_ aware of its context usage percentage.
  29. - **No Automatic Trigger:** Cline **will not** automatically initiate a task handoff _solely_ based on context usage reaching a specific percentage (like 50%). The decision to suggest using `new_task` comes from the AI model's reasoning based on the overall task progress and prompt instructions.
  30. - **Basic Context Preloading:** If `new_task` is used without specific rules defining the `<context>` block structure, Cline will attempt to preload relevant information based on its current understanding (e.g., a basic summary of progress and next steps), but this may be less comprehensive than a rule-driven approach.
  31. #### The Power of `.clinerules`: Enabling Custom Workflows
  32. While the core capabilities exist by default, the true power, automation, and customization emerge when you combine `new_task` and context awareness with custom workflows defined in `.clinerules`. This allows you to precisely control _when_ and _how_ Cline manages context and task continuity.
  33. Key benefits of using `.clinerules` with `new_task`:
  34. - **Automated Context Management:** Define rules to automatically trigger handoffs at specific context percentages (e.g., >50%, >70%) or token counts, ensuring optimal performance and preventing context loss.
  35. - **Model-Specific Optimization:** Tailor handoff triggers based on known thresholds for different LLMs (e.g., trigger earlier for models known to degrade past a certain token count).
  36. - **Intelligent Breakpoints:** Instruct Cline via rules to find logical stopping points (e.g., after completing a function or test) _after_ a context threshold is passed, ensuring cleaner handoffs.
  37. - **Structured Task Decomposition:** Use Plan Mode to define subtasks, then use `.clinerules` to have Cline automatically create a new task via `new_task` upon completing each subtask, preloading the context for the _next_ subtask.
  38. - **Custom Context Packaging:** Mandate the exact structure and content of the `<context>` block in `.clinerules` for highly detailed and consistent handoffs (see example below).
  39. - **Improved Memory Persistence:** Use `new_task` context blocks as a primary, integrated way to persist information across sessions, potentially replacing or supplementing file-based memory systems.
  40. - **Workflow Automation:** Define rules for specific scenarios, like always preloading certain setup instructions or project boilerplate when starting tasks of a particular type.
  41. #### Example Rule-Driven Workflow: Task Handoff Process
  42. A common workflow, **driven by specific `.clinerules` like the example below**, involves these steps:
  43. 1. **Trigger Identification (Rule-Based):** Cline monitors for handoff points defined in the rules (e.g., context usage > 50%, task completion).
  44. 2. **User Confirmation:** Cline uses `ask_followup_question` to propose creating a new task, often showing the intended context defined by the rules.
  45. ```xml
  46. <ask_followup_question>
  47. <question>I've completed [specific accomplishment] and context usage is high (XX%). Would you like me to create a new task to continue with [remaining work], preloading the following context?</question>
  48. <options>["Yes, create new task", "Modify context first", "No, continue this session"]</options>
  49. </ask_followup_question>
  50. ```
  51. 3. **User Control:** You can approve, deny, or ask Cline to modify the context before the new task is created.
  52. 4. **Context Packaging (`new_task` Tool):** If approved, Cline uses `new_task`, packaging the context according to the structure mandated by the `.clinerules`.
  53. 5. **New Task Creation:** The current task ends, and a new session begins immediately, preloaded with the specified context.
  54. #### The Handoff Context Block (Rule-Defined Structure)
  55. The effectiveness of rule-driven handoffs depends heavily on how `.clinerules` define the `<context>` block. A comprehensive structure often includes:
  56. - **`## Completed Work`**: Detailed list of accomplishments, files modified/created, key decisions.
  57. - **`## Current State`**: Project status, running processes, key file states.
  58. - **`## Next Steps`**: Clear, prioritized list of remaining tasks, implementation details, known challenges.
  59. - **`## Reference Information`**: Links, code snippets, patterns, user preferences.
  60. - **Actionable Start:** A clear instruction for the immediate next action.
  61. #### Potential Use Cases & Workflows
  62. The flexibility of `new_task` combined with `.clinerules` opens up many possibilities:
  63. - **Proactive Context Window Management:** Automatically trigger handoffs at specific percentages (e.g., 50%, 70%) or token counts to maintain optimal performance.
  64. - **Intelligent Breakpoints:** Instruct Cline to find logical stopping points (e.g., after completing a function or test) _after_ a context threshold is passed, ensuring cleaner handoffs.
  65. - **Structured Task Decomposition:** Use Plan Mode to define subtasks, then use `.clinerules` to have Cline automatically create a new task via `new_task` upon completing each subtask.
  66. - **Automated Session Summaries:** Configure the `<context>` block to always include a summary of the previous session's key discussion points.
  67. - **Preloading Boilerplate/Setup:** Start new tasks related to specific projects preloaded with standard setup instructions or file templates.
  68. - **"Memory Bank" Alternative:** Use `new_task` context blocks as the primary way to persist information across sessions, potentially replacing file-based memory systems.
  69. Experimenting with `.clinerules` is encouraged to discover workflows that best suit your needs!
  70. #### Example `.clinerules`: Task Handoff Strategy Guide
  71. Below is an example `.clinerules` file focused specifically on using `new_task` for context window management. **Remember, this is just one specific strategy; the core `new_task` tool can be used differently with other custom rules.**
  72. ````markdown
  73. # You MUST use the `new_task` tool: Task Handoff Strategy Guide
  74. **CRITICAL INSTRUCTIONS - YOU MUST FOLLOW THESE GUIDELINES**
  75. This guide provides **MANDATORY** instructions for effectively breaking down complex tasks and implementing a smooth handoff process between tasks. You **MUST** follow these guidelines to ensure continuity, context preservation, and efficient task completion.
  76. ## CONTEXT WINDOW MONITORING - MANDATORY ACTION REQUIRED
  77. You **MUST** monitor the context window usage displayed in the environment details. When usage exceeds 50% of the available context window, you **MUST** initiate a task handoff using the `new_task` tool.
  78. Example of context window usage over 50% with a 200K context window:
  79. \`\`\`text
  80. # Context Window Usage
  81. 105,000 / 200,000 tokens (53%)
  82. Model: anthropic/claude-sonnet-4 (200K context window)
  83. \`\`\`
  84. **IMPORTANT**: When you see context window usage at or above 50%, you MUST:
  85. 1. Complete your current logical step
  86. 2. Use the `ask_followup_question` tool to offer creating a new task
  87. 3. If approved, use the `new_task` tool with comprehensive handoff instructions
  88. ## Task Breakdown in Plan Mode - REQUIRED PROCESS
  89. Plan Mode is specifically designed for analyzing complex tasks and breaking them into manageable subtasks. When in Plan Mode, you **MUST**:
  90. ### 1. Initial Task Analysis - REQUIRED
  91. - **MUST** begin by thoroughly understanding the full scope of the user's request
  92. - **MUST** identify all major components and dependencies of the task
  93. - **MUST** consider potential challenges, edge cases, and prerequisites
  94. ### 2. Strategic Task Decomposition - REQUIRED
  95. - **MUST** break the overall task into logical, discrete subtasks
  96. - **MUST** prioritize subtasks based on dependencies (what must be completed first)
  97. - **MUST** aim for subtasks that can be completed within a single session (15-30 minutes of work)
  98. - **MUST** consider natural breaking points where context switching makes sense
  99. ### 3. Creating a Task Roadmap - REQUIRED
  100. - **MUST** present a clear, numbered list of subtasks to the user
  101. - **MUST** explain dependencies between subtasks
  102. - **MUST** provide time estimates for each subtask when possible
  103. - **MUST** use Mermaid diagrams to visualize task flow and dependencies when helpful
  104. \`\`\`mermaid
  105. graph TD
  106. A[Main Task] --> B[Subtask 1: Setup]
  107. A --> C[Subtask 2: Core Implementation]
  108. A --> D[Subtask 3: Testing]
  109. A --> E[Subtask 4: Documentation]
  110. B --> C
  111. C --> D
  112. \`\`\`
  113. ### 4. Getting User Approval - REQUIRED
  114. - **MUST** ask for user feedback on the proposed task breakdown
  115. - **MUST** adjust the plan based on user priorities or additional requirements
  116. - **MUST** confirm which subtask to begin with
  117. - **MUST** request the user to toggle to Act Mode when ready to implement
  118. ## Task Implementation and Handoff Process - MANDATORY PROCEDURES
  119. When implementing tasks in Act Mode, you **MUST** follow these guidelines for effective task handoff:
  120. ### 1. Focused Implementation - REQUIRED
  121. - **MUST** focus on completing the current subtask fully
  122. - **MUST** document progress clearly through comments and commit messages
  123. - **MUST** create checkpoints at logical completion points
  124. ### 2. Recognizing Completion Points - CRITICAL
  125. You **MUST** identify natural handoff points when:
  126. - The current subtask is fully completed
  127. - You've reached a logical stopping point in a larger subtask
  128. - The implementation is taking longer than expected and can be continued later
  129. - The task scope has expanded beyond the original plan
  130. - **CRITICAL**: The context window usage exceeds 50% (e.g., 100,000+ tokens for a 200K context window)
  131. ### 3. Initiating the Handoff Process - MANDATORY ACTION
  132. When you've reached a completion point, you **MUST**:
  133. 1. Summarize what has been accomplished so far
  134. 2. Clearly state what remains to be done
  135. 3. **MANDATORY**: Use the `ask_followup_question` tool to offer creating a new task:
  136. \`\`\`xml
  137. <ask_followup_question>
  138. <question>I've completed [specific accomplishment]. Would you like me to create a new task to continue with [remaining work]?</question>
  139. <options>["Yes, create a new task", "No, continue in this session", "Let me think about it"]</options>
  140. </ask_followup_question>
  141. \`\`\`
  142. ### 4. Creating a New Task with Context - REQUIRED ACTION
  143. If the user agrees to create a new task, you **MUST** use the `new_task` tool with comprehensive handoff instructions:
  144. \`\`\`xml
  145. <new_task>
  146. <context>
  147. # Task Continuation: [Brief Task Title]
  148. ## Completed Work
  149. - [Detailed list of completed items]
  150. - [Include specific files modified/created]
  151. - [Note any important decisions made]
  152. ## Current State
  153. - [Description of the current state of the project]
  154. - [Any running processes or environment setup]
  155. - [Key files and their current state]
  156. ## Next Steps
  157. - [Detailed list of remaining tasks]
  158. - [Specific implementation details to address]
  159. - [Any known challenges to be aware of]
  160. ## Reference Information
  161. - [Links to relevant documentation]
  162. - [Important code snippets or patterns to follow]
  163. - [Any user preferences noted during the current session]
  164. Please continue the implementation by [specific next action].
  165. </context>
  166. </new_task>
  167. \`\`\`
  168. ### 5. Detailed Context Transfer - MANDATORY COMPONENTS
  169. When creating a new task, you **MUST** always include:
  170. #### Project Context - REQUIRED
  171. - **MUST** include the overall goal and purpose of the project
  172. - **MUST** include key architectural decisions and patterns
  173. - **MUST** include technology stack and dependencies
  174. #### Implementation Details - REQUIRED
  175. - **MUST** list files created or modified in the current session
  176. - **MUST** describe specific functions, classes, or components implemented
  177. - **MUST** explain design patterns being followed
  178. - **MUST** outline testing approach
  179. #### Progress Tracking - REQUIRED
  180. - **MUST** provide checklist of completed items
  181. - **MUST** provide checklist of remaining items
  182. - **MUST** note any blockers or challenges encountered
  183. #### User Preferences - REQUIRED
  184. - **MUST** note coding style preferences mentioned by the user
  185. - **MUST** document specific approaches requested by the user
  186. - **MUST** highlight priority areas identified by the user
  187. ## Best Practices for Effective Handoffs - MANDATORY GUIDELINES
  188. ### 1. Maintain Continuity - REQUIRED
  189. - **MUST** use consistent terminology between tasks
  190. - **MUST** reference previous decisions and their rationale
  191. - **MUST** maintain the same architectural approach unless explicitly changing direction
  192. ### 2. Preserve Context - REQUIRED
  193. - **MUST** include relevant code snippets in the handoff
  194. - **MUST** summarize key discussions from the previous session
  195. - **MUST** reference specific files and line numbers when applicable
  196. ### 3. Set Clear Next Actions - REQUIRED
  197. - **MUST** begin the handoff with a clear, actionable next step
  198. - **MUST** prioritize remaining tasks
  199. - **MUST** highlight any decisions that need to be made
  200. ### 4. Document Assumptions - REQUIRED
  201. - **MUST** clearly state any assumptions made during implementation
  202. - **MUST** note areas where user input might be needed
  203. - **MUST** identify potential alternative approaches
  204. ### 5. Optimize for Resumability - REQUIRED
  205. - **MUST** structure the handoff so the next session can begin working immediately
  206. - **MUST** include setup instructions if environment configuration is needed
  207. - **MUST** provide a quick summary at the top for rapid context restoration
  208. ## Example Task Handoff
  209. ### Example #1 of an effective task handoff:
  210. \`\`\`xml
  211. <new_task>
  212. <context>
  213. # Task Continuation: Implement User Authentication System
  214. ## Completed Work
  215. - Created basic Express.js server structure
  216. - Implemented MongoDB connection and user schema
  217. - Completed user registration endpoint with password hashing
  218. - Added input validation using Joi
  219. - Created initial test suite for registration endpoint
  220. ## Current State
  221. - Server runs successfully on port 3000
  222. - MongoDB connection is established
  223. - Registration endpoint (/api/users/register) is fully functional
  224. - Test suite passes for all registration scenarios
  225. ## Next Steps
  226. 1. Implement login endpoint (/api/users/login)
  227. - Use bcrypt to compare passwords
  228. - Generate JWT token upon successful login
  229. - Add proper error handling for invalid credentials
  230. 2. Create authentication middleware
  231. - Verify JWT tokens
  232. - Extract user information
  233. - Handle expired tokens
  234. 3. Add protected routes that require authentication
  235. 4. Implement password reset functionality
  236. ## Reference Information
  237. - JWT secret should be stored in .env file
  238. - Follow the existing error handling pattern in routes/users.js
  239. - User schema is defined in models/User.js
  240. - Test patterns are established in tests/auth.test.js
  241. Please continue by implementing the login endpoint following the same patterns established in the registration endpoint.
  242. </context>
  243. </new_task>
  244. \`\`\`
  245. ### Example #2 of an ineffective task handoff:
  246. _(Note: The example provided in the original rules showing "YOLO MODE Implementation" seems less like a direct handoff context block and more like a general status update with future considerations. A true ineffective handoff might lack detail in 'Current State' or 'Next Steps')._
  247. ## When to Use Task Handoffs - MANDATORY TRIGGERS
  248. You **MUST** initiate task handoffs in these scenarios:
  249. 1. **CRITICAL**: When context window usage exceeds 50% (e.g., 100,000+ tokens for a 200K context window)
  250. 2. **Long-running projects** that exceed a single session
  251. 3. **Complex implementations** with multiple distinct phases
  252. 4. **When context window limitations** are approaching
  253. 5. **When switching focus areas** within a larger project
  254. 6. **When different expertise** might be beneficial for different parts of the task
  255. **FINAL REMINDER - CRITICAL INSTRUCTION**
  256. You **MUST** monitor the context window usage in the environment details section. When it exceeds 50% (e.g., "105,000 / 200,000 tokens (53%)"), you **MUST** proactively initiate the task handoff process using the `ask_followup_question` tool followed by the `new_task` tool. You MUST use the `new_task` tool.
  257. By strictly following these guidelines, you'll ensure smooth transitions between tasks, maintain project momentum, and provide the best possible experience for users working on complex, multi-session projects.
  258. ```markdown
  259. ## User Interaction & Workflow Considerations
  260. - **Linear Flow:** Currently, using `new_task` creates a linear sequence. The old task ends, and the new one begins. The old task history remains accessible for backtracking.
  261. - **User Approval:** You always have control, approving the handoff and having the chance to modify the context Cline proposes to carry forward.
  262. - **Flexibility:** The core `new_task` tool is a flexible building block. Experiment with `.clinerules` to create workflows that best suit your needs, whether for strict context management, task decomposition, or other creative uses.
  263. ```
  264. ````