|
| 1 | +# claude-trace Implementation Summary |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +`claude-trace` is a terminal user interface (TUI) tool for reviewing and annotating Claude Code conversation logs. It provides an interactive way to go through session traces and mark them up with tags and notes. |
| 6 | + |
| 7 | +## Architecture |
| 8 | + |
| 9 | +### Project Structure |
| 10 | + |
| 11 | +``` |
| 12 | +claude-trace/ |
| 13 | +├── cmd/ |
| 14 | +│ └── main.go # Application entry point |
| 15 | +├── pkg/ |
| 16 | +│ ├── storage/ # Trace file management |
| 17 | +│ │ ├── discovery.go # Finds Claude Code trace locations |
| 18 | +│ │ └── trace.go # Load/save traces and annotations |
| 19 | +│ └── tui/ # Terminal user interface |
| 20 | +│ └── model.go # Bubbletea TUI model and views |
| 21 | +├── traces/ # Sample trace files for testing |
| 22 | +├── README.md # User documentation |
| 23 | +└── go.mod # Go module dependencies |
| 24 | +``` |
| 25 | + |
| 26 | +## Key Components |
| 27 | + |
| 28 | +### 1. Trace Discovery (`pkg/storage/discovery.go`) |
| 29 | + |
| 30 | +The tool searches for Claude Code traces in multiple platform-specific locations: |
| 31 | + |
| 32 | +**Linux/XDG:** |
| 33 | +- `~/.config/Claude/traces` |
| 34 | +- `~/.local/share/Claude/traces` |
| 35 | +- `~/.local/share/claude-code/traces` |
| 36 | + |
| 37 | +**macOS:** |
| 38 | +- `~/Library/Application Support/Claude/traces` |
| 39 | +- `~/Library/Application Support/claude-code/traces` |
| 40 | + |
| 41 | +**Windows:** |
| 42 | +- `%APPDATA%/Claude/traces` |
| 43 | +- `%LOCALAPPDATA%/Claude/traces` |
| 44 | + |
| 45 | +**Fallback:** |
| 46 | +- `./traces` (current directory for testing) |
| 47 | + |
| 48 | +The tool automatically finds all available trace locations and loads files from them. |
| 49 | + |
| 50 | +### 2. Trace Management (`pkg/storage/trace.go`) |
| 51 | + |
| 52 | +**Data Structure:** |
| 53 | +```go |
| 54 | +type Trace struct { |
| 55 | + Path string // Full path to trace file |
| 56 | + Name string // Filename |
| 57 | + Content string // File content |
| 58 | + ModTime time.Time // Last modification time |
| 59 | + Annotations []Annotation // History of annotations |
| 60 | + Tags map[string]bool // Active tags |
| 61 | + FreeformNote string // User's notes |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +**Features:** |
| 66 | +- Loads trace files (`.log`, `.json`, `.txt`, `.md`) |
| 67 | +- Sorts traces by modification time (newest first) |
| 68 | +- Saves annotations as JSON files (`.annotations.json`) |
| 69 | +- Loads existing annotations on startup |
| 70 | + |
| 71 | +### 3. Terminal UI (`pkg/tui/model.go`) |
| 72 | + |
| 73 | +Built with [Charm's Bubbletea](https://github.com/charmbracelet/bubbletea) framework. |
| 74 | + |
| 75 | +**Three Modes:** |
| 76 | + |
| 77 | +1. **List Mode** - Browse traces |
| 78 | + - Navigate with arrow keys or vim bindings (j/k) |
| 79 | + - Quick tag application |
| 80 | + - Shows active tags inline |
| 81 | + |
| 82 | +2. **View Mode** - Read trace content |
| 83 | + - Scrollable viewport |
| 84 | + - Tag display |
| 85 | + - Notes display |
| 86 | + - Apply tags while viewing |
| 87 | + |
| 88 | +3. **Annotate Mode** - Add freeform notes |
| 89 | + - Multi-line text input |
| 90 | + - Save with Ctrl+S |
| 91 | + - Cancel with Esc |
| 92 | + |
| 93 | +## Tag System |
| 94 | + |
| 95 | +Five quick-access tags for common annotations: |
| 96 | + |
| 97 | +- **G** (Good) - Sessions that went well |
| 98 | +- **S** (Suspicious) - Potential issues |
| 99 | +- **F** (Frustration) - Challenging sessions |
| 100 | +- **B** (Bug) - Bug-related conversations |
| 101 | +- **W** (Win) - Successful outcomes |
| 102 | + |
| 103 | +Tags can be toggled on/off and are saved with timestamp history. |
| 104 | + |
| 105 | +## Annotation Persistence |
| 106 | + |
| 107 | +Annotations are saved as JSON files alongside traces: |
| 108 | + |
| 109 | +``` |
| 110 | +session-2024-03-15.log # Original trace |
| 111 | +session-2024-03-15.log.annotations.json # Annotations |
| 112 | +``` |
| 113 | + |
| 114 | +The annotation file contains: |
| 115 | +- All trace metadata |
| 116 | +- Active tags |
| 117 | +- Freeform notes |
| 118 | +- Complete annotation history with timestamps |
| 119 | + |
| 120 | +## Dependencies |
| 121 | + |
| 122 | +- **bubbletea** (v1.3.10) - TUI framework |
| 123 | +- **lipgloss** (v1.1.0) - Terminal styling |
| 124 | +- **bubbles** (v0.21.0) - TUI components (viewport, textarea) |
| 125 | + |
| 126 | +All dependencies checked for vulnerabilities - none found. |
| 127 | + |
| 128 | +## Usage Flow |
| 129 | + |
| 130 | +1. **Discovery** - Tool searches common locations for traces |
| 131 | +2. **Loading** - Loads all trace files and existing annotations |
| 132 | +3. **Browsing** - User navigates through traces in list view |
| 133 | +4. **Reviewing** - User views trace content in detail |
| 134 | +5. **Annotating** - User adds tags and notes |
| 135 | +6. **Saving** - Annotations saved to disk (manual with 'S' or automatic with Ctrl+S) |
| 136 | + |
| 137 | +## Testing |
| 138 | + |
| 139 | +The repository includes three sample trace files in `traces/`: |
| 140 | +- `session-2024-03-15.log` - Simple successful session |
| 141 | +- `session-2024-03-16.log` - Debugging session with frustration |
| 142 | +- `session-2024-03-17.log` - Test writing session |
| 143 | + |
| 144 | +These can be used to explore the tool's functionality. |
| 145 | + |
| 146 | +## Future Enhancements |
| 147 | + |
| 148 | +Potential improvements (not implemented): |
| 149 | +- Search/filter traces by content or tags |
| 150 | +- Export annotations to different formats (markdown, CSV) |
| 151 | +- Aggregate statistics (most common tags, session duration analysis) |
| 152 | +- Integration with actual Claude Code trace format parsing |
| 153 | +- Support for trace format auto-detection |
| 154 | +- Multi-trace comparison view |
0 commit comments