obsidian-claude-code-mcp
CLAUDE.md355 starsChanged 18 months ago0BSDView on GitHub
This is an Obsidian plugin that implements MCP (Model Context Protocol) servers to enable Claude Code and Claude Desktop integration with Obsidian vaults. The plugin provides both WebSocket (for Claude Code CLI) and HTTP/SSE (for Claude Desktop) transports for maximum compatibility. Available for both IDE and MCP: - readFile - Read file contents from vault - writeFile - Write content to vault files - getOpenFiles - Return currently active file - listFiles - List files in vault with filtering -…
- Commits and pushes
The file
We split this CLAUDE.md into the rules it gives an agent
9 rules. About 0 are common, 5 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 71
Proper Cleanup: - All event listeners registered via Obsidian's system
- Very specific: line 124
Path Handling: All paths normalized via normalizePath() utility
- Distinctive: line 133
Commit your changes with conventional commit messages
- Very specific: line 134
Run npm version patch (handles version bumping and tagging)
- Very specific: line 135
Run bun run build to create production build
- Very specific: line 137
Create GitHub release with gh release create including the three required files
- Distinctive: line 144
Test thoroughly with both Claude Code and Claude Desktop
- Distinctive: line 145
Create GitHub release with version tag
- Distinctive: line 150
When refactoring, don't create files with a -refactored suffix, carry out the refactoring as a senior engineer would
≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
This is an Obsidian plugin that implements MCP (Model Context Protocol) servers to enable Claude Code and Claude Desktop integration with Obsidian vaults. The plugin provides both WebSocket (for Claude Code CLI) and HTTP/SSE (for Claude Desktop) transports for maximum compatibility.
Development Commands
bun install- Install dependenciesbun run dev- Start compilation in watch modebun run build- Type check and build for productionbun run version patch|minor|major- Bump version and update manifest fileseslint main.ts- Run linting
Architecture
Core Components
- main.ts - Plugin entry point that orchestrates initialization, settings management, and server lifecycle
- src/settings.ts - Comprehensive settings management with real-time server status display
- src/mcp/ - MCP protocol implementation
- dual-server.ts - Manages both WebSocket and HTTP servers with tool registry
- server.ts - WebSocket server for Claude Code CLI integration
- http-server.ts - HTTP/SSE server for Claude Desktop (uses MCP spec 2024-11-05)
- handlers.ts - Request routing with separation of IDE/MCP concerns
- types.ts - TypeScript interfaces for MCP protocol
- src/ide/ - Claude Code IDE-specific functionality
- ide-handler.ts - Handles IDE-specific requests (ide_connected, etc.)
- ide-tools.ts - IDE-specific tool implementations (openDiff, close_tab, etc.)
- src/shared/ - Common functionality
- tool-registry.ts - Automatic tool registration and validation system
- src/obsidian/ - Obsidian API integration
- workspace-manager.ts - Tracks active file and selection using DOM events
- utils.ts - Path normalization and validation utilities
- src/tools/ - MCP tool implementations
- file-tools.ts - File read/write operations
- general-tools.ts - General workspace and file manipulation tools
- src/terminal/ - Optional embedded terminal feature
- terminal-view.ts - Terminal UI implementation using xterm.js
- pseudoterminal.ts - Platform-specific terminal spawning
- python-detection.ts - Python environment detection
MCP Tools Implemented
Available for both IDE and MCP:
readFile- Read file contents from vaultwriteFile- Write content to vault filesgetOpenFiles- Return currently active filelistFiles- List files in vault with filteringgetWorkspaceInfo- Return vault metadataobsidian_api- Execute Obsidian API commandsview- View file contents with optional line rangesstr_replace- Replace text in filescreate- Create new filesinsert- Insert text at specific line numbersget_current_file- Get the currently active fileget_workspace_files- List all files in vault
IDE-specific tools (WebSocket only):
getDiagnostics- Return file diagnosticsopenDiff- Open diff view for file changesclose_tab- Close specific tabscloseAllDiffTabs- Close all diff views
Key Design Patterns
- Event-Driven Architecture - Uses DOM
selectionchangeevents instead of polling - Lazy Loading - Terminal features loaded only when needed
- Proper Cleanup - All event listeners registered via Obsidian's system
- Error Boundaries - Graceful error handling with user notifications
- Port Conflict Detection - Automatic detection with guidance for resolution
- Tool Registry - Automatic tool registration with runtime validation
- Separation of Concerns - IDE-specific code isolated from standard MCP protocol
- Dual Tool Registries - Separate tool sets for WebSocket/IDE vs HTTP/MCP servers
Building and Testing
Build System
- Uses esbuild with custom configuration (esbuild.config.mjs)
- Bundles to single main.js file (CommonJS format)
- PNG files bundled as data URLs
- Python scripts bundled as text
Testing Workflow
- Build:
bun run build - Copy output to test vault:
.obsidian/plugins/claude-code-terminal/ - Enable plugin in Obsidian settings
- For Claude Code: Run
claudein terminal and use/idecommand - For Claude Desktop: Configure in settings (see README)
Manual Testing Scripts
test-manual-requests.js- Interactive MCP request testertest-mcp-client.js- Full MCP client implementation
Configuration
Claude Desktop Setup
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"obsidian": {
"url": "http://localhost:22360/mcp",
"env": {}
}
}
}Plugin Settings
- Enable/disable WebSocket and HTTP servers independently
- Configure HTTP server port (default: 22360)
- Enable/disable terminal feature
- Real-time server status display
Important Implementation Notes
- Lock Files: WebSocket server creates
[port].lockfiles in the Claude config directory for auto-discovery:- Uses
CLAUDE_CONFIG_DIRenvironment variable if set - Otherwise
$XDG_CONFIG_HOME/claude/ide/or~/.config/claude/ide/(new default since Claude Code v1.0.30) - Falls back to
~/.claude/ide/(legacy location)
- Uses
- Path Handling: All paths normalized via
normalizePath()utility - Security: File operations restricted to vault boundaries
- Multi-Vault Support: Each vault needs unique HTTP port
- MCP Spec Version: HTTP server uses 2024-11-05 spec for compatibility
Release Process
Patch Releases (Bug Fixes)
For patch releases, use the automated process:
- Commit your changes with conventional commit messages
- Run
npm version patch(handles version bumping and tagging) - Run
bun run buildto create production build - Push with
git push && git push --tags - Create GitHub release with
gh release createincluding the three required files
See docs/AUTOMATED_PATCH_RELEASE.md for detailed steps.
Minor/Major Releases
For minor and major releases, follow the manual process in docs/RELEASE_CHECKLIST.md:
- Run
bun run version minor/major - Test thoroughly with both Claude Code and Claude Desktop
- Create GitHub release with version tag
- Upload
manifest.json,main.js, andstyles.cssas assets
Coding Guidelines and Best Practices
- When refactoring, don't create files with a -refactored suffix, carry out the refactoring as a senior engineer would
Memories
- be sure to read patch release process from CLAUDE.md prior to creating a new release
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

