This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Obsidian plugin that generates Anki flashcards from note content using LLMs (Google Gemini, OpenAI, Ollama). Cards are defined in anki-cards code blocks, synced to Anki via the AnkiConnect addon (localhost:8765).
npm install # Install dependencies
npm run dev # esbuild watch mode (rebuilds on changes)
npm run build # TypeScript type-check + production bundle
npm run version # Bump version in manifest.json & versions.json
eslint ./src/ # Lint (requires global eslint: npm install -g eslint)No test framework is configured. Testing is manual: copy main.js, manifest.json, styles.css into the vault plugin folder and reload Obsidian.
Entry point: src/main.ts → bundled to main.js by esbuild (esbuild.config.mjs). Output format is CommonJS. External deps (obsidian, electron, @codemirror/*, @lezer/*) are excluded from the bundle.
Core flow: anki-cards code block → ankiBlockProcessor.ts (renders UI) → generationManager.ts (orchestrates) → aiGenerator.ts (LLM calls) → CardPreviewModal (edit/review) → syncManager.ts (sync to Anki via AnkiConnect)
Key modules:
src/main.ts— Plugin lifecycle, command/ribbon registration, file decorationssrc/settings.ts— Settings tab UI andAnkiGeneratorSettingsinterface (30+ options)src/aiGenerator.ts— Prompt construction, multi-provider LLM calls (Gemini/OpenAI/Ollama)src/generationManager.ts— Generation workflow orchestrationsrc/ankiBlockProcessor.ts— Markdown code block processor, renders in-note UIsrc/anki/AnkiConnect.ts— HTTP client for AnkiConnect APIsrc/anki/ankiParser.ts— Parses/formatsanki-cardsblock contentsrc/anki/syncManager.ts— Card sync logic with image handling and duplicate detectionsrc/ui/— 25+ modal/view components (preview, edit, deck selection, feedback, decorations)src/lang/— i18n (Germande.ts, Englishen.ts)src/types.ts— Card, ChatMessage, ImageInput interfaces
Plugin state (on the plugin instance):
settings— User configurationfeedbackCache— Chat history keyed by file pathactiveGenerations— Map of running generation tasks with AbortControllers
TARGET DECK: DeckName::Subdeck
INSTRUCTION: Custom instruction for AI
STATUS: OVERLOADED (optional)
Q: Question text
A: Answer text
ID: 12345
Q: Cloze question with {{c1::cloze}}
ID: 12346
Q: Type-in question
A (type): Expected typed answer
ID: 12347
Card types: Basic (Q:/A:), Cloze ({{c1::...}}), Type-In (A (type):).
- TypeScript strict mode enabled (
tsconfig.json) - Keep
main.tsminimal — lifecycle only, delegate to modules - Use
this.register*helpers for all listeners/intervals (cleanup on unload) - Command IDs are stable — never rename after release
manifest.jsonidfield must never change- Release artifacts:
main.js,manifest.json,styles.cssat plugin root - i18n: use the helper from
src/lang/helpers.tsfor user-facing strings