Obsidian create name=X overwrite silently wipes file when content= argument is missing (data loss)

Steps to reproduce

Reproduced in Sandbox Vault, Restricted Mode ON, no plugins, Obsidian 1.12.7.

  1. Create a test note via CLI:
    obsidian create name="bug-test" content="line 1
    line 2"
    
  2. Verify content with obsidian read file="bug-test" — outputs the 2 lines correctly :white_check_mark:
  3. Run create with overwrite but without any content= argument:
    obsidian create name="bug-test" overwrite
    
    → Output: Overwrote: bug-test.md (reports success)
  4. Read the file again with obsidian read file="bug-test"(empty — file is 0 bytes) :cross_mark:

Did you follow the troubleshooting guide? [Y/N]

Y — Updated to 1.12.7 (latest), reproduced in Sandbox Vault with Restricted Mode ON, no plugins enabled, no themes, no snippets.

Expected result

The CLI should do one of:

  • Error out: Error: 'content=' argument is required when using 'overwrite' and exit non-zero
  • No-op: leave the file unchanged when content= is missing
  • Read from stdin: accept piped input as content

If the user genuinely wants to clear a file, they should have to pass content="" explicitly.

Actual result

The file is silently truncated to 0 bytes. The CLI prints Overwrote: ... as if successful — no error, no warning.

This is a silent data-loss bug. It is particularly dangerous in scripts that programmatically rebuild content via shell variable substitution: a failed string-processing step (sed pipeline error, empty variable, special character handling) can produce an empty argument list, and the CLI happily wipes the entire file without any indication.

I lost a 2KB note this way during a sed-based link replacement script. Recovered via Obsidian Sync version history (thank you for that feature — would have been permanent data loss otherwise). A user without Sync would lose data forever.

Environment

SYSTEM INFO:
    Obsidian version: 1.12.7
    Installer version: 1.12.7
    Operating system: Darwin Kernel Version 25.4.0: Thu Mar 19 19:32:36 PDT 2026; root:xnu-12377.101.15~1/RELEASE_ARM64_T8103 25.4.0
    Login status: logged in
    Language: en-GB
    Catalyst license: none
    Insider build toggle: off
    Live preview: on
    Base theme: adapt to system
    Community theme: none
    Snippets enabled: 0
    Restricted mode: on

RECOMMENDATIONS:
    none

Additional information

Full reproduction sequence (Sandbox Vault, Restricted Mode):

  • Step 1create name="bug-test" content="..."Created: bug-test.md :white_check_mark:
  • Step 2read file="bug-test" → returns the content :white_check_mark:
  • Step 3create name="bug-test" overwriteOverwrote: bug-test.md :warning:
  • Step 4read file="bug-test"empty, file wiped :cross_mark:
  • Step 5delete file="bug-test" permanentDeleted permanently

Also reproduced on Linux (Debian 13, Obsidian 1.12.7 running headless via Xvfb). Bug is in CLI argument parsing — not platform-specific, not plugin-related, not vault-specific.

Related thread: This may be the root cause of CLI create --overwrite: Support stdin input and file source for multiline content in Feature Requests. That thread describes the symptom (multiline content silently failing). This bug report is the cause (when shell expansion produces no content= arg, the CLI wipes the file instead of erroring).

Suggested fix

Validate that content= is present when overwrite is set. If missing, print an error and exit non-zero. If a user wants to clear a file, require explicit content="".

// Pseudocode
if (args.overwrite && args.content === undefined) {
  throw new Error("'content=' argument is required when using 'overwrite'");
}

Workaround for users: Always validate content is non-empty before invoking the CLI:

[ -n "$NEW_CONTENT" ] && obsidian create name="..." content="$NEW_CONTENT" overwrite

Or use Python subprocess with args list to avoid shell escaping issues entirely:

subprocess.run(['obsidian', 'create',
    'name=' + name,
    'content=' + content,
    'overwrite'])

Sorry, I disagree with you. if you are using create with overwrite, I think should expect the file to be emptied if you don’t pass content (which is NOT mandatory in any case).

You can open a feature request asking for content to be mandatory in case of overwrite.

1 Like