Cannot set-default Vault in WSL
Describe the bug
I have setup WSL and installed obsidian-cli inside of an Ubuntu environment. I have an existing Obsidian install in standard Windows 11 which has the vault I'm trying to default. These files are accessible from within WSL via /mnt/c/Users/%USER%/%PATH_TO_VAULT%.
However, everytime I try to run obsidian-cli set-default $vault I get an error complaining about a missing config file - Failed to read Obsidian config file. Please ensure vault has been set up in Obsidian. Unfortunately, simply running the cli natively in windows is not an option for various reasons.
To Reproduce Steps to reproduce the behaviour:
- Which command?
wsl -u username
obsidian-cli set-default "my-vault"
- What version
obsidian-cli --versionversion v0.2.2 - Vault state? Exists and is completely accessible from Windows
Expected behaviour
It sets the default-vault to my-vault
Additional context Specifically, I'm trying to set this up with clawdbot/moltbot and the installation process for that setup requires using WSL on Windows.
obsidian-cli set-default "obsidian" export OBSIDIAN_VAULT_PATH="/data/obsidian"
@hGriff0n
@tangyoha so your saying I need to set the environment variable to the obsidian vault directory before running the command? I'll try that and report back on if it works
Hmm, get the same error when I try that.
export OBSIDIAN_VAULT_PATH="/mnt/c/Users/ghoop/Desktop/my-vault"
obsidian-cli set-default "my-vault"
Hello, I am sorry I don't know of a way to make this work in WSL (I cannot experiment as I do not use Windows). My guess would be that it is not possible as obsidian-cli uses the Obsidian config file, which is only populated when the GUI application opens.
Maybe another Windows WSL user might know more so I will leave this issue open
The windows file system is still accessible from WSL and I was hoping it would grab it from there. But I guess because of the linux shim that is WSL, it's expecting it to be somewhere else. Theoretically, we just need to redirect that search, but not sure if it'll be an ugly solution.
I'm not too used to Go, but I cant find any code reference to OBSIDIAN_VAULT_PATH. Either way assuming it wouldn't matter here because obsidian.json isnt isn't in the {Vault}/.obsidian dir, but in %APPDATA%\obsidian.
I think the problem traces to https://github.com/Yakitrak/obsidian-cli/blob/f6d1fcbf3dd0e6334b15a166b31c9a338526fc8d/pkg/config/cli_path.go#L9 . Because it's running inside wsl, that's would be ~/.config/obsidian instead of Window's %APPDATA%\obsidian. Allowing folks to override that manually to the mounted mnt/c/users/ghoop/AppData/Roadming/obsidian (or wherever their IRL config is located) should be all it takes.
This is a blocker for those of us running openclaw on windows and using WSL. I can see the mount and the files in /mnt but the CLI doesn't see them.
I have submitted a PR for linux (https://github.com/Yakitrak/obsidian-cli/pull/76) that deals with a similar issue if Obsidian was installed via flatpak instead of the deb. Someone with a windows box could use the same method to "fix" this problem for Windows+WSL.
Okay I have a PR ready in a local branch once #76 is merged in.
/proc/sys/fs/binfmt_misc/WSLInterop allows for checking that we are in WSL. The tricky part is resolving to the mounted appdata directory - eventually settled on cmd.exe /c echo %APPDATA%
Okay I have validated that this does work. Also had to modify vault_path.go because the obsidian config for a windows-based obsidian install stores paths as windows file paths. My solution only recognizes C: drives at the moment - not sure of a safe, general way to extend that to other drives. I'll need to fork the repo in order to actually push the pull request though.
I'm now also wondering if this is actually a good idea - the official WSL docs recommend to not write across the windows-linux boundary. Need to double-check if that's a hard rule or just a warning about apps not handling the line endings.
Hello @hGriff0n - I am in the same boat as you - Claude Code on Ubuntu (WSL) and Obsidian installed on Windows. From the above it looks like you've done a fix (thank you). When do you do submit the PR and if you remember - would you mind letting me know here so that I can wait for the merge of your solution?
I had been considering dropping it given the official obsidain cli. Created a PR: https://github.com/Yakitrak/notesmd-cli/pull/84 @michellepace
Hello @hGriff0n thank you very much! Who knows how long the offcial CLI will take to be available for free. I’m very happy for yours, thank you 🙂.
Thanks @hGriff0n, its merged! I plan to add some more functionality soon, and then will do a release which will include this change. In the mean time feel free to build from source code.