-
Notifications
You must be signed in to change notification settings - Fork 1
✨ Add todo persistence hooks to survive context compaction #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,11 @@ co-creative evolution for the whole. | |
|
|
||
| Coding rules are available in `rules/`. Use `/load-rules` to analyze the current task | ||
| and load relevant rules dynamically. | ||
|
|
||
| # Todo Persistence | ||
|
|
||
| Todos are automatically saved to Claude's project directory via hooks. After context | ||
| compaction, if your todo list appears empty but you were working on tasks: | ||
|
|
||
| 1. Check for saved todos: `cat ~/.claude/projects/$(echo $PWD | sed 's|/|-|g')/todos.md` | ||
cursor[bot] marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recovery path computation differs from save path locationHigh Severity The recovery command in Additional Locations (1)There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recovery command fails for paths containing spacesMedium Severity The recovery command lacks proper quoting: |
||
| 2. If found, restore them via TodoWrite to continue tracking progress | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "hooks": { | ||
| "PostToolUse": [ | ||
| { | ||
| "matcher": "TodoWrite", | ||
| "hooks": [ | ||
| { | ||
| "type": "command", | ||
| "command": "${CLAUDE_PLUGIN_ROOT}/hooks/todo-persist.sh" | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| #!/bin/bash | ||
| # PostToolUse hook for TodoWrite: Save todos in human-readable format | ||
| # Saves to Claude's existing project directory for restoration after compaction | ||
|
|
||
| # Read JSON input from stdin | ||
| INPUT=$(cat) | ||
|
|
||
| # Extract fields | ||
| TOOL_NAME=$(echo "$INPUT" | jq -r '.tool_name // empty') | ||
| TRANSCRIPT_PATH=$(echo "$INPUT" | jq -r '.transcript_path // empty') | ||
|
|
||
| # Only process TodoWrite calls | ||
| if [ "$TOOL_NAME" != "TodoWrite" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Extract todos array from tool_input | ||
| TODOS=$(echo "$INPUT" | jq -r '.tool_input.todos // empty') | ||
|
|
||
| if [ -z "$TODOS" ] || [ "$TODOS" = "null" ] || [ -z "$TRANSCRIPT_PATH" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Use Claude's existing project directory (parent of transcript file) | ||
| PROJECT_DIR=$(dirname "$TRANSCRIPT_PATH") | ||
|
Comment on lines
+24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The analysis is incorrect. Claude Code stores transcript files directly in the project directory (~/.claude/projects//<session_id>.jsonl), not in a transcripts/ subdirectory. So dirname "$TRANSCRIPT_PATH" correctly points to the project directory where recovery expects to find todos.md. Verified: The saved file at ~/.claude/projects/-Users-nick-src-ai-coding-config/todos.md matches the recovery path from context.md. |
||
|
|
||
| # Convert to readable markdown | ||
| { | ||
| echo "# Saved Todos" | ||
| echo "" | ||
| echo "Updated: $(date -u +"%Y-%m-%dT%H:%M:%SZ")" | ||
| echo "" | ||
|
|
||
| # Group by status | ||
| for status in "in_progress" "pending" "completed"; do | ||
| items=$(echo "$TODOS" | jq -r --arg s "$status" '.[] | select(.status == $s) | .content') | ||
| if [ -n "$items" ]; then | ||
| case $status in | ||
| in_progress) echo "## In Progress" ;; | ||
| pending) echo "## Pending" ;; | ||
| completed) echo "## Completed" ;; | ||
| esac | ||
| echo "" | ||
| echo "$items" | while read -r item; do | ||
| [ -n "$item" ] && echo "- $item" | ||
| done | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multi-line todo content splits into separate list itemsLow Severity The |
||
| echo "" | ||
| fi | ||
| done | ||
| } > "$PROJECT_DIR/todos.md" | ||
|
|
||
| exit 0 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation command fails for paths containing spaces
Low Severity
The todo restore command
cat ~/.claude/projects/$(echo $PWD | sed 's|/|-|g')/todos.mdhas an unquoted command substitution. When$PWDcontains spaces (e.g.,/home/user/my project), the sed output-home-user-my projectundergoes word splitting, causingcatto receive incorrect arguments and fail. The command substitution needs to be quoted to preserve spaces in the resulting path.Additional Locations (1)
plugins/core/context.md#L23-L24