README file from
GithubContextual AI Reader
Contextual AI Reader is a desktop reading companion for English material with AI-assisted Chinese translation, vocabulary explanation, text-to-speech, excerpts, and Markdown file translation.
It can use local AI assistant CLIs such as Codex and Claude Code, or direct API-token backends such as OpenAI and Anthropic.
Features
- Translate selected text to Simplified Chinese.
- Show the selection popup only when holding
Commandwhile selecting text. - Explain a selected English word with local/cache definitions first, then optionally enrich it with AI using the current paragraph as context.
- Translate selected text from PDFs when Obsidian can select the PDF text layer.
- Read selected English text aloud with the system text-to-speech voice.
- Save selected passages or vocabulary notes to an excerpt note with source references.
- Translate the current Markdown file and append the Chinese translation below the original.
- Translate the current Markdown file into interleaved English/Chinese paragraphs.
- Batch translate multiple Markdown files by file path, folder path, or wildcard.
- Reduce token overhead on long chapters by merging consecutive short prose paragraphs into larger translation units.
- Show token usage after AI calls when the selected backend reports usage.
- Add custom reading context, terminology, and translation style instructions.
AI Backends
Open plugin settings and choose AI backend.
Available modes:
Auto: use local Codex first when available, then local Claude Code.Codex: use a local Codex executable and your local Codex/ChatGPT login.Claude Code: use a local Claude Code executable and your local Claude login.OpenAI API token: call the OpenAI Chat Completions API with your configured API key.Anthropic API token: call the Anthropic Messages API with your configured API key.
The default mode is Auto, so existing local Codex usage remains the default path.
Configuration
Recommended basic settings:
AI backend: leave asAutoif you want Codex first and Claude Code as fallback.Require Command key for auto translate: keep enabled so normal text selection does not trigger translation.Custom prompt / context: add the book, domain, terminology, and tone you want the AI to respect.Timeout: increase this for long full-file or batch translation.Single-shot translation limit: smaller notes are translated in one request for better context. Defaults to60000characters.Batch chunk size: larger chunks reduce process startup overhead and repeated prompt tokens. Defaults to30000characters.
Local backend settings:
Codex command: optional path tocodex; leave empty to auto-detect.Codex model: model used by Codex.Reasoning effort: defaults tonone, which is usually best for translation speed and cost.Claude command: optional path toclaude; leave empty to auto-detect.Claude model: model used by Claude Code.
API backend settings:
OpenAI API key: required only when usingOpenAI API token.OpenAI model: defaults togpt-4.1-mini.OpenAI base URL: defaults tohttps://api.openai.com/v1; can be changed for compatible endpoints.Anthropic API key: required only when usingAnthropic API token.Anthropic model: defaults toclaude-sonnet-4-5.Anthropic base URL: defaults tohttps://api.anthropic.com/v1.
API keys are stored in this plugin's local Obsidian settings data. Do not publish your vault's .obsidian/plugins/.../data.json file.
Example custom prompt:
I am reading Poor Charlie's Almanack. Translate into natural Simplified Chinese.
Keep investment, psychology, and business terms consistent. Preserve Markdown structure.
Usage
Selection Popup
By default, normal text selection does nothing. This avoids interrupting ordinary note-taking.
To open the popup:
- Open a Markdown note or a selectable PDF.
- Hold
Commandon macOS. - While holding
Command, select English text. - Release the mouse or trackpad.
- The popup appears near the selected text.
If you turn off Require Command key for auto translate, the popup appears after ordinary text selection. This is not recommended for heavy note-taking workflows.
Popup Buttons
The popup can show different buttons depending on the selected text and result state:
- Speaker: read the original English text aloud with the system text-to-speech voice.
- Sparkles: send the selection to the configured AI backend for a higher-quality translation or contextual explanation.
- Book plus: save the selection, translation, or vocabulary note to the configured excerpt note.
- Copy: copy the translation or vocabulary note to the system clipboard.
- Stop: cancel a running AI request and kill the active local CLI process when using Codex or Claude Code.
Paragraph Translation
When you select a phrase, sentence, or paragraph:
- Hold
Commandand select the text. - The plugin first tries a quick translation for the popup.
- Click the Sparkles button if you want the configured AI backend to refine the translation.
- Use Copy or Book plus if you want to keep the result.
For selected paragraphs, the quick popup translation is meant for speed. The Sparkles button is the higher-quality AI path and uses your selected backend, custom prompt, model, and token budget.
Single-Word Vocabulary
When you select exactly one English word:
- Hold
Commandand select the word. - The popup first checks the local vocabulary cache and built-in dictionary.
- If a local/cache definition exists, it appears immediately.
- The plugin then uses the surrounding paragraph and your custom prompt to generate an AI context explanation.
- Use Book plus to save the vocabulary note, including the source context.
Single-word mode is different from paragraph translation: it focuses on what the word means in the current paragraph or book, not only on a generic dictionary definition.
Selection Commands
You can also use commands from the command palette:
Translate selection to Chinese: replaces the selected text with Chinese.Append Chinese translation below selection: keeps the original selection and inserts the Chinese translation below it.Speak selected English text: reads the selected English text aloud.Save selection to excerpts: saves the selected text to your excerpt note with source information.
Current Markdown File Translation
- Open a Markdown file.
- Open the command palette.
- Run one of the current-file translation commands.
Available modes:
Translate current Markdown file: append Chinese belowTranslate current Markdown file: interleave Chinese paragraphs
Append mode:
Original English content
Chinese translation of the whole note
Use this when you want to keep the English source intact and place the full Chinese translation after it.
Interleave mode:
English paragraph 1
Chinese paragraph 1
English paragraph 2
Chinese paragraph 2
Use this when you want side-by-side reading in one note. For long chapters with many tiny EPUB/OCR paragraphs, the plugin automatically merges consecutive short prose paragraphs into larger translation units before sending them to AI. The original English text is preserved, but the Chinese translation may be inserted after a small group of related short paragraphs instead of after every tiny fragment. This greatly reduces repeated prompt and delimiter tokens.
Only one full-file or batch translation can run at a time. If another translation is already running, the plugin asks you to stop the current task first.
Batch Markdown Translation
Use batch translation when you want to translate multiple Markdown files with one command.
- Open the command palette.
- Run one of the batch commands:
Batch translate Markdown files: append Chinese belowBatch translate Markdown files: interleave Chinese paragraphs
- Enter one Markdown file, folder, or wildcard per line.
- Click Start.
Batch commands write directly to the matched Markdown files. Back up important notes before running them.
Batch Path Rules
Batch paths are vault-relative. Do not use absolute filesystem paths.
Correct:
Books/Trading in the Zone/
Books/Trading in the Zone/08 - Chapter 1.md
Books/Trading in the Zone/*.md
Books/Trading in the Zone/1? - *.md
Books/Trading in the Zone/**/*.md
Incorrect:
/Users/me/Documents/Vault/Books/Trading in the Zone/
Supported scopes:
- Single Markdown file:
Books/Example/Chapter 1.md - Folder:
Books/Example/ - Simple wildcard:
Books/Example/*.md - Recursive wildcard:
Books/Example/**/*.md - Single-character wildcard:
Books/Example/1? - *.md
The folder mode recursively includes Markdown files inside the folder.
Excerpts
Set Excerpt file in plugin settings. When you click Book plus or run Save selection to excerpts, the plugin appends an entry to that note.
Excerpt entries can include:
- the original selected text;
- the popup translation when available;
- the source note path;
- line references when the selection comes from an open Markdown editor.
If Open excerpt file after saving is enabled, the excerpt note opens in a side split after saving.
Text-to-Speech
Use the Speaker button or the Speak selected English text command to read selected English aloud.
Useful settings:
Speech language: defaults toen-US.Speech rate: defaults to0.92.
The plugin uses the system speech synthesis voices available in your Obsidian desktop environment.
Token Usage And Cancellation
AI-powered actions show token usage when the selected backend reports it.
The token line uses this format:
input ↑ output ↓ (total, cached)
For long file translation, the progress overlay also shows:
- elapsed time;
- completed batches;
- completed translation units;
- completed source paragraphs;
- current token usage;
- a Stop button.
Click Stop to cancel queued work and kill active local CLI processes where possible.
Custom Prompt / Reading Context
Use Custom prompt / context to tell the AI what you are reading and how it should translate.
Good examples:
I am reading Poor Charlie's Almanack. Translate in natural Simplified Chinese.
Keep investing, psychology, business, and Munger-related terms consistent.
I am reading a trading psychology book. Preserve technical trading terms.
Translate "edge" as "优势" when it means trading advantage.
The custom prompt affects AI refinement, contextual vocabulary explanation, current-file translation, and batch translation. It does not affect the instant local/cache vocabulary lookup.
Commands
Translate selection to ChineseAppend Chinese translation below selectionSpeak selected English textSave selection to excerptsTranslate current Markdown file: append Chinese belowTranslate current Markdown file: interleave Chinese paragraphsBatch translate Markdown files: append Chinese belowBatch translate Markdown files: interleave Chinese paragraphsCheck Codex login
Batch Scope Examples
Batch paths are vault-relative, not absolute filesystem paths. See Batch Path Rules above for the full behavior.
Books/Trading in the Zone/
Books/Trading in the Zone/08 - Chapter 1.md
Books/Trading in the Zone/*.md
Books/Trading in the Zone/1? - *.md
Books/Trading in the Zone/**/*.md
Privacy
This plugin is not offline translation.
Depending on your selected backend, selected text and Markdown content may be sent to:
- local Codex CLI/App through your local Codex login;
- local Claude Code through your local Claude login;
- OpenAI API using your configured API key;
- Anthropic API using your configured API key.
The plugin stores settings locally in Obsidian. It does not intentionally publish or upload settings, but API keys stored in plugin settings are sensitive. Do not commit Obsidian plugin data files to a public repository.
Full-file and batch translation commands modify Markdown files directly. Back up important vaults before running bulk operations.
Development
Install dependencies:
npm install
Build:
npm run build
Manual development install:
<vault>/.obsidian/plugins/contextual-ai-reader/
The plugin folder must contain:
manifest.jsonmain.jsstyles.css
Community Plugin Release Checklist
- Update
manifest.jsonandversions.json. - Run
npm run build. - Commit
main.js,manifest.json,styles.css, and source files. - Push
main. - Push a Git tag whose name exactly matches
manifest.jsonversion, for example1.0.3. - Let the GitHub Actions release workflow create the release assets and artifact attestations.
- After the release is published, users can update from the Obsidian community plugin browser.
License
MIT