Obsidian CLI - `obsidian create` inserts a leading newline, breaking frontmatter

obsidian create inserts a leading newline, breaking frontmatter

Steps to reproduce

  1. Create a new note via CLI:

    obsidian create path="Test/bug_repro.md"
    
  2. Append content with frontmatter:

    obsidian append path="Test/bug_repro.md" content="---\ntitle: Test\n---\n\n# Hello"
    
  3. Inspect the file with a hex dump:

    xxd "<vault path>/Test/bug_repro.md" | head -3
    

Did you follow the troubleshooting guide? Y

Expected result

The file should start with 2d 2d 2d (the --- frontmatter delimiter at byte 0). Obsidian should parse the frontmatter normally.

Actual result

Byte 0 is 0a (newline). The frontmatter --- starts on line 2 instead of line 1, and Obsidian does not recognize it as valid frontmatter — properties are not parsed.

00000000: 0a2d 2d2d 0a74 6974 6c65 3a20 5465 7374  .---.title: Test

Environment

  • Obsidian version: 1.12.7 (installer 1.12.7)
  • OS: macOS 26.4 (Build 25E246), arm64
  • CLI enabled via Settings → General

Additional information

obsidian create is expected to produce an empty file, but it inserts a trailing newline character. This is invisible until you append content — at which point any frontmatter is silently broken.

Workaround: Strip the leading empty line after create + append:

sed -i '' '1{/^$/d;}' "<full file path>"

Related: CLI — Ability to manipulate frontmatter for a document — native frontmatter support in the CLI would also solve this, since you wouldn’t need the create + append pattern.

read obsidian help append

Also, to manipulate the frontmatter there are specific CLI functions. Manipulating the plaintext increases the chances of generating an invalid yaml.

Maybe reading the whole docs could help

1 Like

You could probably use property:set instead of append :blush:
(The following assume an Untitled.md note has been created at the root of the Sandbox vault before hand)

% obsidian vault="Obsidian Sandbox" property:set name=title value=Test type=text path="Untitled.md"
Set title: Test

And then, I guess you could append some other things, if needed (using the inline flag if/when necessary) :blush: