Tasks orphaned when 'clear context' creates new session in plan mode

Resolved 💬 6 comments Opened Jan 25, 2026 by Nescio Closed Mar 6, 2026

Description

When exiting plan mode and selecting option 1 "Yes, clear context and auto-accept edits" (the default), a new session is created. Tasks created with TaskCreate remain in the old session's directory and become invisible to Claude's internal task tools.

Steps to Reproduce

  1. Start a Claude Code session
  2. Create tasks using TaskCreate
  3. Enter plan mode and create a plan
  4. When prompted "Would you like to proceed?", select option 1 "Yes, clear context and auto-accept edits" (default)
  5. Run TaskList

Expected: Tasks from the planning session are visible
Actual: TaskList returns empty - tasks are orphaned in the old session's directory

Technical Details

  • Tasks are stored in ~/.claude/tasks/{sessionId}/*.json
  • "Clear context" creates a new session with a new sessionId
  • The task files remain in the old session's directory
  • Claude's internal TaskList/TaskGet/TaskUpdate tools only see the current session's tasks

Impact

This breaks the workflow of using tasks for high-level planning. Users who:

  1. Create a plan with tasks to track work
  2. Accept the plan with the default option
  3. Lose visibility into their task list

The tasks still exist on disk but are disconnected from the active session.

Possible Solutions

  1. Add a SessionStart hook - allow users to run scripts when a new session starts (e.g., to migrate incomplete tasks from previous sessions for the same project)
  2. Warn users - indicate that "clear context" will orphan tasks
  3. Project-scoped tasks - store tasks by project path instead of session ID
  4. Migrate tasks when clearing context - copy task files to new session directory (updating IDs if needed)

Environment

  • Claude Code version: 2.1.16+ (Task feature is new)
  • OS: Linux (Ubuntu 20.04)

View original on GitHub ↗

This issue has 6 comments on GitHub. Read the full discussion on GitHub ↗