CLI & API

Fileclass exposes a public plugin API and ships a standalone fileclass CLI (with an interactive TUI) so you can inspect, validate and edit typed frontmatter from the terminal — reusing the plugin’s own index, Bases queries and validation engine, so results have full fidelity.

Both drive the running Obsidian app through Obsidian’s own CLI (obsidian eval). Obsidian must be running with the Fileclass plugin enabled.

⚠️ These tools write to your notes. The API, the CLI and the TUI edit real frontmatter in your live vault — including bulk edits across many notes at once (setValueWhere / fileclass set-where). Writes go straight to disk and are not undoable from Fileclass. Handle them with care, prefer a dry run before a bulk change, and keep regular backups of your vault (Git, Obsidian Sync, or a file-level backup) — good practice for any tool that automates edits to your files.

Public API

The plugin publishes a stable, JSON-serializable surface on its instance — app.plugins.plugins.fileclass.api — reachable from obsidian eval "…" and from the fileclass CLI. Everything is plain JSON (paths, field names, plain values — never TFile or field objects with methods); mutations return { ok, message } and never throw for a domain error.

MethodPurpose
vaultInfo()vault name + absolute path
listFileClasses()every fileClass (extends, field count, icon, hasBase)
getSchema(fileClass)options + resolved fields (with ancestry)
explain(path)a note’s fileClasses, ancestry, and resolved field values
getFields(path) / getValue(path, field)fields on a note / one value
allowedValues(path, field)resolved allowed values for a choice field
fileCandidates(path, field)link candidates for a File/Media field
listNotes(fileClass, { columns?, where?, limit? })rows for a fileClass
baseTable(fileClass)the fileClass’s base view as columns/rows
openSchema(fileClass)open the schema editor in the Obsidian window
validate(scope?)schema violations for a fileClass / path / folder / vault
setValue(path, field, value)validated single write
clearValue(path, field)remove a field’s key
insertMissing(path)add missing fields to a note
setValueWhere(fileClass, field, value, where?)validated bulk write
previewValueWhere(scope, field, value) / applyValueWhere(scope, field, value)dry-run, then apply, a bulk edit over a fileClass narrowed by a condition and/or a base view
applyValueToPaths(paths, field, value)the same edit on an explicit list of notes
noteDestinations(fileClass)1.2 — the class’s creation destinations ({ name?, folder?, template? }), in declared order; null for an unknown class
createNote({ fileClass, name, destination?, seeds?, open? })1.2 — create a note of a class, without any picker

setValue and setValueWhere validate before writing and refuse an invalid value; setValueWhere also skips notes already at the target value (no churn) and reports { changed, skipped, errors }. Bases-dependent methods degrade gracefully (return null / []) when Bases is unavailable.

The API is versioned (api.version, currently 1.2); breaking changes bump it. The plugin driving the CLI must be recent enough to expose plugin.api.

Creating a note (1.2)

createNote is the Create a note with a class command without its pickers: the same creation, template, fields and log, with the choices passed in.

const api = app.plugins.plugins.fileclass.api;
await api.noteDestinations("Person");
// → [{ name: "Professional", folder: "People/Work", template: "Templates/Pro.md" }, { name: "Artist", … }]

await api.createNote({ fileClass: "Person", name: "John Doe", destination: "artist" });
// → { ok: true, path: "People/Artists/John Doe.md" }

await api.createNote({
  fileClass: "GuitarSong",
  name: "Highway to Hell",
  seeds: [
    { field: "artists", linkTo: ["AC-DC"] },   // a link, built by Fileclass from the new note
    { field: "genre", value: "Hard rock" },    // a literal; a list stays a list
  ],
  open: false,
});
// → { ok: true, path: "Songs/Highway to Hell.md" }   — artists: ["[[AC-DC]]"]
  • destination — matched on the destination’s name, case-insensitively. Omitted: the only destination, or the first declared. An unknown name is refused, and the message lists the class’s destinations. A class without destinations creates the note in Obsidian’s default folder, like the command.
  • name — cleaned like the command does (characters a file name cannot hold are removed); empty once cleaned, it is refused.
  • An existing note is refused, where the command numbers the new one (John Doe 1): if a note of that name (in any letter case) is already in the destination folder, the result is ok: false with the existing note’s path. Nothing is created or modified.
  • template — applied as by the command, Templater’s renaming included: path is the final path. A template that fails does not fail the creation.
  • seeds — applied in order, after the template, overwriting what it set on that field. linkTo takes a path or a note name ([[…]] and an alias are accepted) and is resolved like an Obsidian link. Values are not validated — the class’s validation reports them afterwards. A seed on a field the class does not have, or a link that resolves to no note, is skipped. So is a seed of the wrong shape (not an object, no field, a linkTo that is not a string or a list of strings): the call never throws for what it was sent.
  • What could not be applied (a skipped seed, a failed template, a template whose properties are not on line 1) comes back in warnings; the note is created anyway.
  • open — true by default: the note opens, then the fields modal if Open the fields after creating a note is on. With false, nothing opens. No other window ever appears: the call never waits for the user. The fields modal opens, like every Obsidian modal, in the window that has focus — usually the note’s, but a popped-out window such as Settings holds the focus while it is the last one used, and the modal then appears there.
  • The schema log gets the command’s schema.note-created line, with via: "api".

⚠️ Mutating methods write to disk. setValue, clearValue, insertMissing and setValueWhere change note frontmatter in the live vault; createNote creates a file. setValueWhere can touch many notes in one call — scope its where filter carefully. There is no built-in undo; back up your vault before scripting writes.

Installing the CLI

The CLI lives in its own repository: https://github.com/mdelobelle/fileclass-cli (it is a standalone Node tool, not part of the plugin bundle Obsidian downloads).

git clone https://github.com/mdelobelle/fileclass-cli
cd fileclass-cli
npm install
npm run build

Then expose the fileclass command. If your Node lives in a system location, npm link needs a writable global prefix — pick one that avoids sudo:

  • Shell alias (quickest): echo "alias fileclass='node $(pwd)/dist/cli.js'" >> ~/.zshrc
  • User-owned npm prefix, then npm link: npm config set prefix ~/.npm-global (and add its bin to PATH).
  • Symlink into a bin dir on your PATH: ln -sf "$(pwd)/dist/cli.js" ~/.local/bin/fileclass.

Or just run it directly: node dist/cli.js <command>.

CLI commands

fileclass tui                              # interactive browse + edit (TUI)
fileclass fileclasses                      # every fileClass
fileclass schema Book                      # a fileClass's options + fields
fileclass explain "Books/Dune.md"          # a note's fileClasses + resolved fields
fileclass list Book --columns title,author --where "status is unread" --limit 20
fileclass get "Books/Dune.md" status
fileclass set "Books/Dune.md" status read  # validated single write

# data quality (exit code 1 if any violation — CI-friendly)
fileclass validate --fileclass Book

# bulk edit (dry-run unless --apply)
fileclass set-where Book status "to read" --where "status isEmpty" --apply

Add --json to any command for machine-readable output. validate exits non-zero when it finds a violation, so it drops straight into a CI or pre-commit check.

⚠️ set and set-where modify your notes. set writes a single value; set-where edits every matching note. set-where is a dry run by default — inspect the reported changes first, then re-run with --apply. Keep a backup before applying bulk edits.

Interactive TUI

fileclass tui opens an ink-based terminal UI. From a home menu you can browse fileClasses → notes → fields and edit a value with typed input — choice pickers for Select/Cycle, candidate pickers with filtering for File/Media fields, and text input for the rest. It also shows each note’s validation status and lets you open a fileClass’s base or switch vaults. It talks to the same live API as the CLI, so every edit is validated exactly as it would be in the app.

⚠️ TUI edits are saved immediately. Confirming a value in the TUI writes it to the note’s frontmatter right away — there is no separate save step and no undo. As with the CLI and API, keep regular backups of your vault.

Choosing the vault

With several vaults open, pick which one commands run against. Every command prints the target vault to stderr (vault: <name>). Precedence:

--vault <name>   >   FILECLASS_VAULT (env)   >   `fileclass use` default   >   active vault
fileclass vault                 # which vault am I talking to?
fileclass use Obsidian-Dev      # persist a default (survives sessions)
fileclass use --clear           # unset it
fileclass list Book --vault Work   # one-off override

Configuration

Variable / filePurpose
OBSIDIAN_BINpath to the obsidian binary (default: obsidian on PATH).
FILECLASS_VAULTtarget vault for the shell session.
FILECLASS_QUIEThide the vault: stderr line.
~/.config/fileclass/config.jsonthe persisted fileclass use default.