From b5083354d0822ea9c57102959022ceb7b7447c70 Mon Sep 17 00:00:00 2001 From: Luke Hoersten Date: Thu, 2 Oct 2025 14:49:13 -0500 Subject: Updated intermediate context file to json. --- README.md | 68 +++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 1be2357..a2f61ed 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ Add to your `init.el`: (setq claude-code-context-update-interval 3) ;; Optional: customize the context file location -(setq claude-code-context-file "~/.emacs.d/claude-context.txt") +(setq claude-code-context-file "~/.emacs.d/claude-code-context.json") ``` ### Claude Code Hook Setup @@ -64,7 +64,7 @@ Add this hook configuration to your `~/.claude/settings.json`: "hooks": [ { "type": "command", - "command": "CONTEXT_FILE=\"$HOME/.emacs.d/claude-context.txt\"; if [ -f \"$CONTEXT_FILE\" ]; then echo \"\\n---\\n## Emacs Context\\n\"; cat \"$CONTEXT_FILE\"; echo \"\\n---\"; fi" + "command": "CONTEXT_FILE=\"$HOME/.emacs.d/claude-code-context.json\"; if [ -f \"$CONTEXT_FILE\" ]; then echo \"\\n---\\n## Emacs Context\\n\"; cat \"$CONTEXT_FILE\"; echo \"\\n---\"; fi" } ] } @@ -79,7 +79,7 @@ See [claude-code-hook-example.json](claude-code-hook-example.json) for a complet ### Automatic Mode -When `claude-code-context-mode` is enabled, your current buffer context is automatically written to `~/.emacs.d/claude-context.txt` every time Emacs is idle for the configured interval. +When `claude-code-context-mode` is enabled, your current buffer context is automatically written to `~/.emacs.d/claude-code-context.json` every time Emacs is idle for the configured interval. ### Manual Commands @@ -101,38 +101,46 @@ When `claude-code-context-mode` is enabled, your current buffer context is autom ## Context Format -The context file includes: +The context file is JSON format for easy parsing and includes: -- **File**: Full path to the current buffer's file -- **Line**: Current line number -- **Column**: Current column number -- **Selection**: Any highlighted text (if region is active) -- **Diagnostics**: Flymake errors/warnings (when using `C-c C-l d`) +- **file**: Full path to the current buffer's file +- **line**: Current line number +- **column**: Current column number +- **modified**: Boolean indicating if the buffer has unsaved changes +- **selection**: Any highlighted text (if region is active) +- **diagnostics**: Flymake errors/warnings (when using `C-c C-l d`) Example context: -``` -# Emacs Context for Claude Code -# This file is automatically updated by Emacs - -File: /Users/username/project/src/main.py -Line: 42, Column: 8 -Selection: -``` -def process_data(items): - return [x * 2 for x in items] -``` - -Flymake Diagnostics: - 45 error e-f-b-c undefined variable 'result' - 52 warning e-f-b-c unused variable 'temp' +```json +{ + "file": "/Users/username/project/src/main.py", + "line": 42, + "column": 8, + "modified": true, + "selection": "def process_data(items):\n return [x * 2 for x in items]", + "diagnostics": [ + { + "line": 45, + "type": "error", + "backend": "eglot", + "text": "undefined variable 'result'" + }, + { + "line": 52, + "type": "warning", + "backend": "eglot", + "text": "unused variable 'temp'" + } + ] +} ``` ## Customization ### Variables -- `claude-code-context-file`: Location of the context file (default: `~/.emacs.d/claude-context.txt`) +- `claude-code-context-file`: Location of the context file (default: `~/.emacs.d/claude-code-context.json`) - `claude-code-context-update-interval`: Idle time in seconds before updating context (default: 2) ### Custom Keybindings @@ -146,15 +154,15 @@ If you prefer different keybindings: ## How It Works -1. **Emacs side**: This package writes your current buffer context to a file (`~/.emacs.d/claude-context.txt`) -2. **Claude Code side**: A hook in Claude Code's settings reads this file before every prompt submission -3. **Integration**: Claude Code automatically receives your Emacs context with each query +1. **Emacs side**: This package writes your current buffer context to a JSON file (`~/.emacs.d/claude-code-context.json`) +2. **Claude Code side**: A hook in Claude Code's settings reads this JSON file before every prompt submission +3. **Integration**: Claude Code automatically receives and parses your Emacs context with each query ## Troubleshooting **Context not appearing in Claude Code:** - Verify the hook is properly configured in `~/.claude/settings.json` -- Check that the context file exists: `cat ~/.emacs.d/claude-context.txt` +- Check that the context file exists: `cat ~/.emacs.d/claude-code-context.json` - Make sure `claude-code-context-mode` is enabled in Emacs **Performance issues:** @@ -171,4 +179,4 @@ GPL-3.0-or-later ## Author -Luke Hoersten +Luke Hoersten -- cgit v1.2.3