Skip to main content
This page documents all Tauri commands available in Scratch. Commands are organized by category and invoked from the frontend using invoke() from @tauri-apps/api/core.

Note Management

Commands for creating, reading, updating, and deleting notes.

list_notes

Returns all notes in the configured notes folder. Parameters: None Returns:
notes
NoteMetadata[]
Array of note metadata objects
Notes:
  • Walks the notes folder recursively (max depth 10)
  • Excludes .git, .scratch, .obsidian, .trash, and assets directories
  • Results are sorted: pinned notes first (by date), then unpinned notes (by date descending)
  • Updates internal notes cache

read_note

Reads the full content of a note by ID. Parameters:
id
string
required
Note ID (relative path without .md extension)
Returns:
note
Note
id
string
Note ID
title
string
Extracted title
content
string
Full markdown content
path
string
Absolute file system path
modified
number
Unix timestamp
Errors:
  • "Notes folder not set" - No notes folder configured
  • "Note not found" - File doesn’t exist
  • "Invalid note ID: ..." - ID contains path traversal or invalid characters

save_note

Saves note content. Creates new note if id is null, or updates existing note. Handles automatic renaming when title changes. Parameters:
id
string | null
required
Note ID to update, or null to create new note
content
string
required
Full markdown content to save
Returns:
note
Note
Updated note object with potentially new ID if renamed
Behavior:
  • Extracts title from content (first # Heading)
  • Sanitizes title to create filename
  • For existing notes: renames file if title changed (preserves subfolder location)
  • For new notes: creates in root folder
  • Handles filename collisions with -1, -2 suffixes
  • Updates search index
  • Deletes old file after successful write (for renames)

delete_note

Deletes a note by ID. Parameters:
id
string
required
Note ID to delete
Returns: null on success Behavior:
  • Removes file from disk
  • Updates search index
  • Removes from notes cache

create_note

Creates a new note with template-based name. Parameters: None Returns:
note
Note
Newly created note
Behavior:
  • Uses defaultNoteName setting as template (default: "Untitled")
  • Supports template tags:
    • {timestamp} - Unix timestamp
    • {date} - YYYY-MM-DD
    • {year} - YYYY
    • {month} - MM
    • {day} - DD
    • {time} - HH-MM-SS (dashes for filename safety)
    • {counter} - Auto-incrementing number
  • Sanitizes filename
  • Handles collisions with counter suffix
  • Creates parent directories for nested templates (e.g., {year}/{month}/{day})
  • Initializes content with # Title\n\n

Configuration

Commands for managing app and folder-level settings.

get_notes_folder

Returns the currently configured notes folder path. Parameters: None Returns:
path
string | null
Absolute path to notes folder, or null if not configured

set_notes_folder

Sets the notes folder path and initializes folder structure. Parameters:
path
string
required
Absolute path to notes folder (supports legacy file:// URIs)
Returns: null on success Behavior:
  • Normalizes path (handles file:// URIs from older versions)
  • Creates folder if it doesn’t exist
  • Creates assets/ subfolder for images
  • Creates .scratch/ subfolder for settings
  • Verifies write access
  • Loads per-folder settings from .scratch/settings.json
  • Updates app config in {APP_DATA}/config.json
  • Adds folder to asset protocol scope (for image serving)
  • Initializes and rebuilds search index

get_settings

Returns per-folder settings. Parameters: None Returns:
settings
Settings
See Settings Reference for full schema

update_settings

Updates per-folder settings. Parameters:
settings
Settings
required
Complete settings object (see Settings Reference)
Returns: null on success Behavior:
  • Replaces entire settings object in memory
  • Saves to .scratch/settings.json in notes folder

Commands for full-text search using Tantivy.

search_notes

Searches notes using full-text search with fallback. Parameters:
query
string
required
Search query
Returns:
results
SearchResult[]
Array of search results (max 20)
Behavior:
  • Uses Tantivy full-text search (searches title and content)
  • Falls back to prefix query (query*) if parsing fails
  • Falls back to substring search if Tantivy returns no results or errors
  • Fallback: title matches score 50, content matches score 10
  • Results sorted by score descending

rebuild_search_index

Rebuilds the Tantivy search index from scratch. Parameters: None Returns: null on success Behavior:
  • Deletes all documents from index
  • Walks notes folder and re-indexes all .md files
  • Index stored in {APP_DATA}/search_index/

File Watching

Commands for monitoring external file changes.

start_file_watcher

Starts watching the notes folder for file changes. Parameters: None Returns: null on success Behavior:
  • Uses notify crate with recursive watching
  • Debounces events per file (500ms)
  • Emits "file-change" events with payload:
    {
      kind: "created" | "modified" | "deleted",
      path: string,  // absolute path
      changed_ids: string[]  // array of note IDs
    }
    
  • Updates search index automatically
  • Cleans up debounce map (removes entries older than 5 seconds)

Git Operations

Commands for Git integration.

git_is_available

Checks if Git CLI is installed. Parameters: None Returns:
available
boolean
True if git --version succeeds

git_get_status

Returns Git repository status. Parameters: None Returns:
status
GitStatus
isRepo
boolean
Whether folder is a Git repo
hasRemote
boolean
Whether ‘origin’ remote exists
hasUpstream
boolean
Whether current branch tracks upstream
remoteUrl
string | null
URL of ‘origin’ remote
changedCount
number
Number of changed files
aheadCount
number
Commits ahead of upstream (-1 if no upstream)
behindCount
number
Commits behind upstream (-1 if no upstream)
currentBranch
string | null
Current branch name
error
string | null
Error message if any

git_init_repo

Initializes a Git repository. Parameters: None Returns: null on success Runs: git init

git_commit

Stages all changes and creates a commit. Parameters:
message
string
required
Commit message
Returns:
result
GitResult
success
boolean
Whether operation succeeded
message
string | null
Success message
error
string | null
Error message if failed
Runs: git add -A && git commit -m "message"

git_push

Pushes to remote. Parameters: None Returns: GitResult Runs: git push with timeouts (10s connect, 10s low-speed)

git_fetch

Fetches from remote. Parameters: None Returns: GitResult Runs: git fetch --quiet with timeouts

git_pull

Pulls from remote. Parameters: None Returns: GitResult Runs: git pull with pull.rebase=false and timeouts Behavior:
  • Parses “Already up to date” message
  • Provides user-friendly error messages for:
    • Authentication failures
    • Network issues
    • Merge conflicts
    • Diverged histories

git_add_remote

Adds ‘origin’ remote. Parameters:
url
string
required
Remote URL (must start with https://, http://, or git@)
Returns: GitResult Runs: git remote add origin <url>

git_push_with_upstream

Pushes and sets upstream tracking. Parameters: None Returns: GitResult Runs: git push -u origin <current-branch>

AI Integration

Commands for AI-assisted editing via CLI tools.

ai_check_claude_cli

Checks if Claude CLI is installed. Parameters: None Returns:
available
boolean
True if claude command is found in PATH
Notes:
  • Expands PATH to include common Node.js version managers (nvm, fnm, volta, mise)
  • Checks ~/.local/bin, /usr/local/bin, /opt/homebrew/bin

ai_check_codex_cli

Checks if Codex CLI is installed. Parameters: None Returns:
available
boolean
True if codex command is found in PATH

ai_execute_claude

Executes Claude CLI to edit a file. Parameters:
file_path
string
required
Absolute path to markdown file
prompt
string
required
User prompt for AI
Returns:
result
AiExecutionResult
success
boolean
Whether execution succeeded
output
string
Standard output from CLI
error
string | null
Error message if failed
Runs: claude <file_path> --dangerously-skip-permissions --print Behavior:
  • Writes prompt to stdin
  • 5-minute timeout
  • Kills process on timeout
  • Expands PATH to find CLI in Node version managers

ai_execute_codex

Executes Codex CLI to edit a file. Parameters:
file_path
string
required
Absolute path to markdown file
prompt
string
required
User prompt for AI
Returns: AiExecutionResult Runs: codex exec --skip-git-repo-check --dangerously-bypass-approvals-and-sandbox - Behavior:
  • Wraps prompt with instructions to edit only the specified file
  • Same timeout and PATH expansion as Claude CLI

Utilities

Miscellaneous helper commands.

copy_to_clipboard

Copies text to system clipboard. Parameters:
text
string
required
Text to copy
Returns: null on success

copy_image_to_assets

Copies an image file to the notes folder’s assets/ directory. Parameters:
source_path
string
required
Absolute path to source image file
Returns:
path
string
Relative path to copied image (e.g., "assets/image.png")
Behavior:
  • Preserves original filename (sanitized)
  • Handles collisions with -1, -2 suffixes
  • Maintains file extension

save_clipboard_image

Saves a base64-encoded image from clipboard to assets folder. Parameters:
base64_data
string
required
Base64-encoded image data (without data URI prefix)
Returns:
path
string
Relative path to saved image (e.g., "assets/screenshot-1234567890.png")
Behavior:
  • Generates filename: screenshot-<timestamp>.png
  • Handles collisions with counter suffix
  • Guards against empty data

open_folder_dialog

Opens a native folder picker dialog. Parameters:
default_path
string | null
Default directory to open
Returns:
path
string | null
Selected folder path, or null if cancelled

open_in_file_manager

Opens a directory in the system file manager. Parameters:
path
string
required
Absolute path to directory
Returns: null on success Platform Commands:
  • macOS: open <path>
  • Windows: explorer <path>
  • Linux: xdg-open <path>

open_url_safe

Opens a URL in the default browser (with scheme validation). Parameters:
url
string
required
URL to open
Returns: null on success Behavior:
  • Only allows http://, https://, and mailto: schemes
  • Rejects other schemes (e.g., file://, javascript:) for security

Preview Mode

Commands for editing standalone markdown files outside the notes folder.

read_file_direct

Reads a markdown file directly by path. Parameters:
path
string
required
Absolute path to markdown file
Returns:
file
FileContent
path
string
Original path
content
string
File content
title
string
Extracted title
modified
number
Unix timestamp
Security:
  • Only allows .md and .markdown extensions
  • Resolves symlinks to canonical path

save_file_direct

Saves content to a markdown file directly by path. Parameters:
path
string
required
Absolute path to existing markdown file
content
string
required
Content to save
Returns: FileContent Security:
  • File must already exist
  • Only allows .md and .markdown extensions

import_file_to_folder

Imports a markdown file from preview mode into the notes folder. Parameters:
path
string
required
Absolute path to source markdown file
Returns: NoteMetadata Behavior:
  • Derives note ID from title (falls back to filename)
  • Copies content atomically (create + write)
  • Handles filename collisions
  • Updates search index
  • Emits "select-note" event to main window
  • Focuses main window

open_file_preview

Opens a markdown file in preview mode. Parameters:
path
string
required
Absolute path to markdown file
Returns: null on success Behavior:
  • If file is inside notes folder: selects it in main window
  • Otherwise: creates a new preview window
  • Preview windows use hashed labels (preview-<hash>)
  • Focuses existing window if already open

preview_note_name

Previews the filename that would be generated from a template. Parameters:
template
string
required
Template string with tags
Returns:
preview
string
Generated filename (with {counter} replaced by 1)
Notes:
  • Expands template tags (see create_note for supported tags)
  • Sanitizes result
  • Useful for settings UI to show real-time preview

write_file

Writes raw bytes to a file path. Parameters:
path
string
required
Absolute path to file
contents
number[]
required
Array of bytes to write
Returns: null on success Note: Used internally for exporting PDFs and other binary formats.

Build docs developers (and LLMs) love