Build an LLM Journaling Reflection Plugin for Obsidian
Demo of Obsidian reflective journaling
Building an LLM Journaling Reflection Plugin for Obsidian
Journaling has been a game changer for me. It's an exercise that forces me to structure my thoughts into
language and helps me identify where I lack mental clarity. But sometimes when my thoughts are a big hazy mess,
it's difficult to write with structure.
Enter LLMs! I've found a writing paradigm that enforces clarity and draws out new thoughts
is one where AI gives me reflective questions throughout the writing process.
That's why I built an Obsidian plugin to do exactly that. As I journal, I can invoke AI to give me a reflective question to guide my writing.
This post documents how I built this Obsidian plugin that uses Claude (Anthropic's AI model) to help make journaling more insightful.
If you just want to see the full source code, take a look at the repo here.
Prequisites
You'll need:
Obsidian desktop app
Node.js (the LTS version works great)
A package manager (I like pnpm, but npm or yarn work too)
A Claude API key from Anthropic (head over to their site to get one)
Setting Up Our Project
Let's get our files organized. Here's what we need:
Nothing too fancy here - just the essentials for an Obsidian plugin. The real magic happens in main.ts.
The Good Stuff: Our Plugin Code
I'll walk you through the most important parts of our code. First up, here's our main plugin file:
This is the core setup of our plugin minus the Claude API integration. The logic
grabs the content of the active editor, and sends that to the getSuggestedQuestion method which we will implement next.
It then inserts it into the editor as a Markdown blockquote.
Now we need to add the logic behind the getSuggestedQuestion function. In the ReflectiveJournalPlugin class,
add this function:
The last thing we need to add is the ReflectiveJournalSettingTab class to render
a settings UI in Obsidian settings:
Let's break down everything that's happening in our plugin:
We're creating a settings interface to store your Claude API key (gotta keep that safe!)
When the plugin loads, it:
Grabs your saved settings
Adds a settings tab
Creates a "Reflect" command you can use anytime
When you trigger "Reflect", it sends your journal entry to Claude and gets back a personalized question
Making It All Work Together
Our package.json is pretty straightforward:
Taking It For a Spin
Ready to try it out? Here's how:
First, find your Obsidian vault's .obsidian/plugins folder. Make sure that this project is in the plugins folder (or create a symlink from your original folder to this one).
I won't be covering that here for brevity, but ask your LLM for help if you're unsure. :)
Next, install everything:
To build the plugin, run:
This will watch your files and rebuild whenever you make changes - super handy while you're tweaking things.
When you're ready to use it in Obsidian:
Go to settings -> Community plugins -> Enable community plugins
If your plugin doesn't automatically appear, restart Obsidian
In your Settings sidebar, there should be a "Reflective Journal Plugin" tab now. Click it and enter your Anthropic API key in the text box.
Now when you're journaling, use cmd+P and trigger the plugin whenever you want a reflective question from Claude!
What's Next?
Now that you've got this working, the fun part begins! You could:
Play with different prompting styles to get different kinds of questions
Add features like sentiment analysis
Create different reflection modes (gratitude, goal-setting, problem-solving)
Wrapping Up
And there you have it! A plugin that makes journaling a bit more structured with some AI-powered help. It's pretty cool what you can build when you combine Obsidian's powerful plugin system with Claude's ability to understand and respond to your writing.
Got ideas for making this better? Or just want to discuss anything? Drop me a message on X.