Skip to content

Replace file watcher with Claude Code hook for todo/plan detection #67

Description

@dang-hai

Summary

Replace the current file watcher-based todo detection with a proper hook-based approach once Claude Code provides the necessary hooks.

Current Implementation (File Watcher - Unreliable)

File Purpose
apps/desktop/src/main/services/session-watcher/SessionFileWatcher.ts Uses fs.watch to monitor .jsonl session files
packages/shared/src/parsers/todo-extractor.ts Parses JSONL files to find TodoWrite tool calls
apps/desktop/src/renderer/hooks/useSessionFileWatcher.ts React hook subscribing to file change events
apps/desktop/src/renderer/hooks/useSessionOverview.ts Integrates file watching with todo extraction

How it works now:

  1. SessionFileWatcher uses Node.js fs.watch to detect .jsonl file changes
  2. Debounces rapid writes (300ms base, 1000ms max) to handle streaming
  3. On change, useSessionOverview re-reads and parses the entire JSONL file
  4. extractLatestTodoList() scans from the end to find the latest TodoWrite tool_use block
  5. Converts to TodoListProgress for UI rendering

Problems:

  • Inefficient: Must re-parse entire session file on every change
  • Complex debouncing: 300ms/1000ms timing to handle streaming writes
  • No granularity: Can't distinguish message changes from todo updates
  • No plan detection: No way to detect when a plan is created
  • Timing issues: Missed updates or duplicate processing

Desired Solution

Use Claude Code's hook system with PostToolUse matcher for TodoWrite:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": {
          "tool_name": "TodoWrite"
        },
        "command": "notify-agent-base"
      }
    ]
  }
}

Benefits:

  • Real-time notifications without file polling
  • Todo content delivered directly in hook payload (no parsing needed)
  • React only to todo changes, not every session update
  • Cleaner, more reliable architecture

Blockers

Claude Code does not currently have a dedicated hook for todo/plan creation.

Available hooks per DeepWiki:

  • PreToolUse / PostToolUse - could work if payload includes tool input
  • No dedicated TodoCreated or PlanCreated hook

Questions for Anthropic:

  1. Does PostToolUse include the tool's input (todo list content) in its payload?
  2. Is there a separate "plan" concept with its own tool, or is it all TodoWrite?

Action Items

  • Investigate if current PostToolUse hook provides enough data
  • If not, request feature from Anthropic (anthropics/claude-code)
  • Once hooks are available, refactor to use hook-based approach
  • Remove file watcher complexity

Related Files

apps/desktop/src/main/services/session-watcher/
├── SessionFileWatcher.ts
├── index.ts
└── ipc.ts

packages/shared/src/parsers/
├── todo-extractor.ts
└── types.ts

apps/desktop/src/renderer/hooks/
├── useSessionFileWatcher.ts
└── useSessionOverview.ts

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions