Overview
AI editing in Scratch:- Uses your local Claude Code CLI or Codex CLI installation
- Edits notes directly based on natural language prompts
- Runs completely locally (no data sent to Scratch servers)
- Supports undo with
Cmd+ZorCtrl+Z - Works with any markdown content
Prerequisites
Claude Code CLI
To use Claude for AI editing:- Install the Claude Code CLI from code.claude.com/docs/en/quickstart
- Restart Scratch to detect the installation
- Open any note and use the command palette (
Cmd+PorCtrl+P) - Select Edit with Claude
OpenAI Codex CLI
To use Codex for AI editing:- Install the OpenAI Codex CLI
- Restart Scratch to detect the installation
- Open any note and use the command palette (
Cmd+PorCtrl+P) - Select Edit with Codex
Scratch automatically detects which AI CLI tools are installed when you open the AI editing modal.
Using AI Editing
Basic Workflow
- Open a note you want to edit
- Open the command palette (
Cmd+PorCtrl+P) - Select Edit with Claude or Edit with Codex
- Enter a natural language prompt describing your desired changes
- Press
Enterto submit - Review the AI-generated changes
- Undo with
Cmd+ZorCtrl+Zif needed
Example Prompts
AI Edit Modal
The AI editing interface provides: Input Field- Natural language prompt entry
- Auto-focus on open
- Disabled if CLI not installed
- Automatic CLI availability check
- Installation instructions if not found
- Spinner during detection
Enter- Submit prompt and execute editEsc- Cancel and return to command palette
- Explains how the feature works
- Links to CLI installation instructions
- Shows active provider (Claude or Codex)
Response Display
After AI editing completes, Scratch displays a toast notification with:- Success message: “AI Edit Complete”
- Output preview: Shows the AI’s response with markdown formatting
- Undo instructions: Reminder that
Cmd+ZorCtrl+Zwill undo changes - Provider icon: Visual indicator of which AI was used
- Headers
- Bold and italic text
- Inline code
- Code blocks
- Bulleted lists
- Numbered lists
Implementation
AI editing is implemented across multiple layers:Frontend Service (src/services/ai.ts)
UI Components
AiEditModal (src/components/ai/AiEditModal.tsx)
- Prompt input interface
- CLI availability detection
- Provider-specific icons and messaging
- Loading states during execution
- Error handling for missing CLI
src/components/ai/AiResponseToast.tsx)
- Response display with markdown parsing
- Undo instructions
- Provider branding
Backend Commands
The Rust backend exposes these Tauri commands:| Command | Description |
|---|---|
ai_check_claude_cli | Checks if Claude Code CLI is installed |
ai_execute_claude | Executes Claude edit on file with prompt |
ai_check_codex_cli | Checks if Codex CLI is installed |
ai_execute_codex | Executes Codex edit on file with prompt |
Security & Privacy
Data Flow:- Your prompt and note content stay on your machine
- Scratch calls the local CLI tool
- The CLI tool may send data to Claude/OpenAI servers (per their terms)
- Edited content is written back to your local file
- Send your notes to Scratch servers
- Store prompts or responses
- Track AI usage
- Require a Scratch account or API key
Troubleshooting
CLI Not Detected
If Scratch doesn’t detect your installed CLI:- Ensure the CLI is in your system PATH
- Restart Scratch after installation
- Try running the CLI command manually in a terminal
- Check that the CLI binary has execute permissions
Edit Failed
If an AI edit fails:- Check your internet connection (CLIs need to reach AI servers)
- Verify your CLI authentication is configured
- Try a simpler prompt
- Check the CLI logs for detailed error messages
Changes Not Applied
If changes aren’t appearing:- Check the toast notification for errors
- Try reloading the note (
Cmd+RorCtrl+R) - Verify the file wasn’t modified by another process
- Check file permissions
Advanced Usage
Batch Editing
While Scratch doesn’t support batch AI editing through the UI, you can:- Use the AI CLI directly on multiple files
- Use git to track and review changes
- Reload notes in Scratch to see updates
Custom Prompts
Create reusable prompts for common tasks:- “Format as weekly review with sections for wins, challenges, and next week”
- “Convert meeting notes to action items with owners and deadlines”
- “Generate a table of contents for this document”
- “Extract key takeaways as a bulleted summary”
Integration with External Agents
Scratch detects external file changes, so you can:- Use AI agents outside Scratch to edit notes
- Scratch will detect changes and prompt to reload
- Maintain full edit history via git
Limitations
- One note at a time (no batch editing)
- Requires local CLI installation
- Depends on CLI tool availability and authentication
- No streaming or progress indication during long edits
- Limited to providers with CLI tools (Claude Code, Codex)
Future Enhancements
Potential improvements being considered:- Support for additional AI providers
- Batch editing across multiple notes
- Prompt templates and history
- Streaming responses for long edits
- Diff preview before applying changes