This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Tauri desktop application for translating selected text between Japanese and English. It uses a global hotkey (Cmd+J on macOS, Ctrl+J on Windows) to capture selected text, translate it via Cloudflare Workers AI (Gemma 3 model), and display the translation in a floating overlay - all without leaving the active application.
npm run dev- Start Vite dev server (frontend only)npm run tauri dev- Run full Tauri app in dev mode (builds Rust + frontend)npm run build- Build TypeScript and frontendnpm run tauri build- Create production bundle
cargo check --manifest-path src-tauri/Cargo.toml- Type check Rust codecargo build --manifest-path src-tauri/Cargo.toml- Build Rust backendcargo test --manifest-path src-tauri/Cargo.toml- Run Rust tests
- src/App.tsx: Main React component that displays translation overlay
- Listens for
show-translationevents from Rust backend - Shows translation in a floating overlay window
- Auto-hides after 10 seconds
- Provides copy button to copy translation to clipboard
- Listens for
The Rust backend handles all system integration and translation logic:
-
src-tauri/src/lib.rs: Application entry point
- Initializes Tauri plugins (clipboard, global-shortcut, opener)
- Registers global hotkey (Cmd+J / Ctrl+J)
- Sets up
SmartClipboardstate management - Wires hotkey handler to
translate_selectioncommand
-
src-tauri/src/commands.rs: Tauri command handlers
translate_selection: Main workflow command- Saves current clipboard content
- Simulates Cmd+C to copy selected text
- Reads clipboard to get selected text
- Detects language (Japanese vs English)
- Calls Cloudflare Worker for translation
- Restores original clipboard content
- Emits
show-translationevent to frontend (overlay-only mode, no pasting)
-
src-tauri/src/clipboard_manager.rs: SmartClipboard utility
- Manages clipboard save/restore to avoid clobbering user's clipboard
- Uses
enigocrate for cross-platform keyboard simulation - Critical: All keyboard operations (
copy_selection,paste) MUST run on main thread viaapp.run_on_main_thread()on macOS due to Accessibility API requirements
-
src-tauri/src/translation.rs: Translation logic
detect_language(): Detects if text contains Japanese characters (Hiragana, Katakana, Kanji)get_target_language(): Maps source language to target (JA→EN or EN→JA)translate(): Calls Cloudflare Worker proxy endpoint for translation- Worker uses Gemma 3 (12B) model for high-quality multilingual translation
- Note: Worker URL is configured via WORKER_URL environment variable
- Window is transparent, always-on-top, borderless, non-resizable (450x250)
- Uses
macOSPrivateApi: truefor advanced window features - Capabilities defined in
capabilities/desktop.jsonfor permissions
- macOS: Requires Accessibility permissions for global hotkey registration and keyboard simulation
- Global Shortcut: Defined in
capabilities/desktop.jsonwith explicit allow list - Clipboard Manager: Tauri plugin for clipboard access
The app requires macOS Accessibility permissions to:
- Register global hotkeys (Cmd+J)
- Simulate keyboard events (Cmd+C, Cmd+V)
If hotkey registration fails, the app prints instructions to System Settings → Privacy & Security → Accessibility.
The SmartClipboard pattern is critical:
- Save original clipboard before any operation
- Copy selected text via keyboard simulation
- Read clipboard to get selected text
- Write translation to clipboard
- Paste translation via keyboard simulation
- Restore original clipboard content
This ensures user's clipboard isn't permanently modified.
- Desktop app calls Cloudflare Worker proxy endpoint
- Worker runs
@cf/google/gemma-3-12b-itmodel (140+ languages) - Request format:
{text: string, target_lang: "ja" | "en"} - Response format:
{translation: string, model: string, detected_lang: string} - Language detection: Heuristic-based (checks for Japanese Unicode ranges)
- Threshold: >10% Japanese characters → considered Japanese text
- API credentials stored server-side in Worker (not exposed to desktop app)
Rust backend → Frontend communication uses Tauri's event system:
app.emit("show-translation", TranslationResult { ... })Frontend listens with:
listen<TranslationResult>("show-translation", (event) => { ... })-
Main Thread Requirement: All
enigokeyboard operations must run on main thread on macOS. Useapp.run_on_main_thread()with channel-based result passing. -
Lock Lifecycle: Release
Mutexlocks beforeawaitoperations to prevent deadlocks. Thetranslate_selectionfunction carefully scopes lock acquisition. -
Worker URL Configuration: The Cloudflare Worker URL is configured via the
WORKER_URLenvironment variable. Must point to a deployed Worker with the@cf/google/gemma-3-12b-itmodel bound asAI. -
Internet Requirement: Unlike the previous Ollama implementation, this version requires internet connectivity for all translations. The Worker must be reachable.
-
Window Visibility: The Tauri window starts visible but empty. Frontend shows hint text when no translation is active.