3.5 KiB
3.5 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Type
This is an Obsidian community plugin written in TypeScript and bundled to JavaScript using esbuild.
Build Commands
# Install dependencies
npm install
# Development mode (watch mode, auto-recompiles on changes)
npm run dev
# Production build (type checks, then bundles with minification)
npm run build
# Lint code
npm run lint
Architecture
Entry Points & Build Process
- Source code lives in
src/ - Main entry point:
src/main.ts(plugin lifecycle management) - Build target:
main.js(bundled output at root) - Bundler: esbuild (configured in
esbuild.config.mjs) - Required release artifacts:
main.js,manifest.json,styles.css(if present)
Code Organization Pattern
- Keep
main.tsminimal: Only plugin lifecycle (onload, onunload, command registration) - Delegate feature logic to separate modules
- Settings are defined in
src/settings.ts - Organize larger features into subdirectories:
commands/for command implementationsui/for modals, views, and UI componentsutils/for helper functions
Plugin Architecture
- Extends
Pluginclass fromobsidianpackage - Settings are loaded/saved using
this.loadData()/this.saveData() - All event listeners, intervals, and DOM events must use
this.register*()helpers for proper cleanup - Commands are registered via
this.addCommand()with stable IDs
Key Constraints
Obsidian-Specific
- Bundle everything: No external runtime dependencies (except
obsidian,electron, CodeMirror packages) - External packages: Listed in
esbuild.config.mjsexternal array; never bundle these - Mobile compatibility: Avoid Node/Electron APIs unless
isDesktopOnly: truein manifest - Network requests: Default to offline; require explicit user consent for any external calls
- No remote code execution: Never fetch/eval scripts or auto-update outside normal releases
Manifest (manifest.json)
- Never change
idafter initial release - Use semantic versioning for
version - Keep
minAppVersionaccurate when using newer Obsidian APIs - Update both
manifest.jsonandversions.jsonwhen bumping versions
Development Workflow
Testing Locally
- Build the plugin:
npm run devornpm run build - Copy
main.js,manifest.json,styles.cssto:<Vault>/.obsidian/plugins/<plugin-id>/ - Reload Obsidian and enable plugin in Settings → Community plugins
Type Checking
- TypeScript strict mode enabled in
tsconfig.json - Build command runs
tsc -noEmit -skipLibCheckbefore bundling - Fix type errors before considering build successful
Important Files
src/main.ts- Plugin class and lifecyclesrc/settings.ts- Settings interface, defaults, and settings tab UImanifest.json- Plugin metadata (never commit with wrong version)esbuild.config.mjs- Build configurationeslint.config.mts- ESLint configuration with Obsidian-specific rulesstyles.css- Optional plugin styles
Code Quality Guidelines
From AGENTS.md and Obsidian best practices:
- Split files when they exceed ~200-300 lines
- Use clear module boundaries (single responsibility per file)
- Prefer
async/awaitover promise chains - Register all cleanup via
this.register*()helpers to prevent memory leaks - Keep startup lightweight; defer heavy work until needed
- Use stable command IDs (don't rename after release)
- Provide sensible defaults for all settings