Skip to content

hledger add: non-interactive mode for automation and AI agents #2568

@machulav

Description

@machulav

The hledger add command is interactive-only — it prompts for input and requires confirmation, which makes it great for humans but unusable for automation, scripts, and AI agents that need to add transactions programmatically via CLI.

Current workaround

Directly appending formatted journal text to the file + validating with hledger check. This works, but bypassing hledger add means losing its built-in validation, duplicate detection, and account-name checking in favor of reimplementing them externally.

Proposal

A non-interactive mode accepting a JSON transaction on stdin:

echo '{
  "date": "2024-03-25",
  "description": "Grocery Store",
  "postings": [
    { "account": "expenses:food", "amount": "$42.50" },
    { "account": "assets:checking" }
  ]
}' | hledger add --json

Or via argument:

hledger add --json '{"date":"2024-03-25","description":"Grocery Store","postings":[{"account":"expenses:food","amount":"$42.50"},{"account":"assets:checking"}]}'

Draft CLI help changes:

Flags:
     --no-new-accounts      don't allow creating new accounts
     --json                 read transaction as JSON from stdin or argument
                            (non-interactive mode, for automation/scripting)

Draft manual addition (under add):

Non-interactive mode

With --json, hledger add accepts a JSON-formatted transaction instead of
prompting interactively. The transaction is validated, checked for duplicates,
and appended to the journal — same as interactive mode, but suitable for
scripts and automation tools. If validation fails, hledger exits with a
non-zero status and prints the error to stderr.

Context

AI agents and automation tools are increasingly integrating with hledger (see #2547, #2510, hledger-mcp). A non-interactive add would make programmatic integration much simpler — no need to reimplement validation logic.

Related: #1026, #1322, #259, #844

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-WISHSome kind of improvement request or proposal.add

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions