2025-07-21 12:01:55 -04:00
# CLAUDE.md
2025-07-21 12:52:39 -04:00
This file provides guidance to Claude Code (claude.ai/code) when working with the cnotes codebase.
2025-07-21 12:01:55 -04:00
## Build and Run Commands
```bash
# Build the binary
2025-07-21 12:52:39 -04:00
go build -o cnotes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
# Install cnotes to capture conversation notes (project-level by default)
2025-07-21 13:02:15 -04:00
cnotes install
2025-07-21 12:01:55 -04:00
# Install to different scopes
2025-07-21 13:02:15 -04:00
cnotes install --global # ~/.claude/settings.json
cnotes install --local # ./.claude/settings.json
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
# Uninstall cnotes
2025-07-21 13:02:15 -04:00
cnotes install --uninstall
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
# View conversation notes for commits
2025-07-21 13:02:15 -04:00
cnotes show # Show notes for HEAD
cnotes show abc1234 # Show notes for specific commit
cnotes list # List all commits with notes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
# Backup and restore notes
2025-07-21 13:02:15 -04:00
cnotes backup my-backup.json
cnotes restore my-backup.json
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
# Test hook execution manually (for debugging)
2025-07-21 13:02:15 -04:00
echo '{"hook_event_name":"PostToolUse","tool_name":"Bash","tool_input":"{\"command\":\"git commit -m test\"}"}' | cnotes
2025-07-21 12:52:39 -04:00
```
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
## What cnotes Does
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
cnotes is a focused tool that automatically captures Claude conversation context in git notes. It integrates with Claude Code as a PostToolUse hook handler and:
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
1. **Monitors git commit commands** in bash tool executions
2. **Extracts conversation context** from Claude transcript files
3. **Attaches structured notes** to commits using `git notes --ref=claude-conversations`
4. **Provides user-friendly commands** to view, backup, and restore conversation notes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
## Architecture Overview
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**Core Components:**
2025-07-21 12:35:09 -04:00
2025-07-21 12:52:39 -04:00
**`main.go` ** - Entry point that calls cmd.Execute()
2025-07-21 12:35:09 -04:00
2025-07-21 12:52:39 -04:00
**`cmd/root.go` ** - Main cnotes command that handles Claude Code hook calls
- Receives JSON input from Claude Code hooks via stdin
- Only processes PostToolUse events for Bash commands containing "git commit"
- Extracts conversation context and attaches it as git notes
- Returns JSON response to Claude Code
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**`cmd/notes.go` ** - User-facing commands for managing notes
- `show` - Pretty-print conversation notes in Markdown format
- `list` - List all commits with conversation notes
- `backup` - Create JSON backups of all notes
- `restore` - Restore notes from JSON backup files
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**`cmd/install.go` ** - Installation command
- Configures Claude Code settings to call cnotes as a hook handler
- Supports project-level, global, and local installations
- Sets up git configuration to preserve notes during rebases
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**`internal/notes/` ** - Git notes operations
- `git_notes.go` - Core git notes CRUD operations using command-line git
- `backup.go` - Backup and restore functionality for notes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**`internal/context/` ** - Conversation context extraction
- `conversation.go` - Parses Claude transcripts to extract relevant conversation context
- Privacy-aware filtering to exclude sensitive information
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**`internal/config/` ** - Configuration management
- `settings.go` - Handles reading/writing Claude settings.json files
- `notes.go` - Configuration for git notes behavior with privacy controls
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
## Key Features
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**Automatic Git Notes Creation:**
- Detects `git commit` commands in Claude conversations
- Extracts commit hashes from git command output
- Stores conversation context as structured JSON in git notes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
**Pretty-Printed Viewing:**
```bash
2025-07-21 13:02:15 -04:00
cnotes show # Beautifully formatted Markdown output
2025-07-21 12:01:55 -04:00
```
2025-07-21 12:52:39 -04:00
**Backup and Restore:**
```bash
2025-07-21 13:02:15 -04:00
cnotes backup notes.json
cnotes restore notes.json
2025-07-21 12:01:55 -04:00
```
2025-07-21 12:52:39 -04:00
**Privacy Controls:**
- Filters sensitive patterns (passwords, tokens, keys)
- Configurable exclusion patterns
- Length limits on conversation excerpts
2025-07-21 12:35:09 -04:00
2025-07-21 12:52:39 -04:00
## Configuration
2025-07-21 12:35:09 -04:00
2025-07-21 12:52:39 -04:00
Create `.claude/notes.json` to customize behavior:
2025-07-21 12:35:09 -04:00
```json
{
"enabled": true,
"max_excerpt_length": 5000,
"max_prompts": 2,
"notes_ref": "claude-conversations",
"exclude_patterns": ["password", "token", "key", "secret"]
}
```
2025-07-21 12:52:39 -04:00
## Hook Integration
2025-07-21 12:40:04 -04:00
2025-07-21 12:52:39 -04:00
cnotes registers as a Claude Code hook handler for:
- **PostToolUse** events on **Bash** tools
- Processes git commit commands to attach conversation context
- Configures git to preserve notes during rebase operations
2025-07-21 12:40:04 -04:00
2025-07-21 12:52:39 -04:00
## Development Notes
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
- **Focused Scope**: Only handles git notes functionality, removed all other hook handling
- **Type Safety**: Uses json.RawMessage and typed structs, no string casting
- **Privacy-First**: Built-in filtering for sensitive information
- **User Experience**: Prioritizes readable Markdown output over raw JSON
- **Reliability**: Comprehensive backup/restore system for data protection
2025-07-21 12:01:55 -04:00
2025-07-21 12:52:39 -04:00
When making changes, ensure:
1. Git notes functionality remains the primary focus
2. Privacy controls are maintained
3. Backup/restore capabilities work correctly
4. Pretty-printed output remains readable
2025-07-21 13:02:15 -04:00
5. Installation process configures Claude Code correctly