Writing a ledger-cli Language Server Protocol with claude


Thoughts on using claude code to write a ledger-cli Language Server Protocol in Rust

ledger-cli is a command line accounting tool for double entry accounting. The ledger format has a defined grammar, vim plugins, VS code plugins, etc. but no Language Server Protocol implementation.

Filling the gap in the plain text accounting world felt like an apt use case to kick the tires on claude code. A few sessions and 257155 opus-4.5 tokens later, claude had written a working ledger-cli LSP implementation.

Total commodity price calculated by the LSP

Key observations:

  • The hardest part of the entire process was halting development everytime I hit the session limit on the Claude Pro ($20/mo) plan
  • Claude developed this over a few days and it would have taken me weeks/months by hand (prohibitively expensive for the value I would get out of the LSP)
  • I don’t know Rust. I did not learn Rust during this project and I can’t evaluate the code quality. But it works and it’s performant

My prompts were straightforward – 1) come up with a plan 2) what features are we missing 3) review the code. This pattern was repeated across seven sessions (usually running up against the Pro session limit) until I reached enough features for my use case.

Hey claude. You are an expert in rust and writing Language Server Protocol (LSP) servers. What we want to do is create a no code plan on how to implement a LSP for the “ledger-cli” domain specific language. The documentation for the ledger-cli language is given in ledger.html. Please come up with a plan on how we should extend the tower-lsp language server to support the ledger-cli syntax. Ask as many clarifying questions as necessary

Claude you are very familiar with ledger-cli and Rust. This directory contains a language service (LSP) for the ledger-cli language. Evalute the existing features and come up with some other features we should add or extend into this LSP that are specifically useful for double entry accounting. We do not want to make claims about account balances since the ledger software is quite complex. Instead we want to make sure the editing experience is good.

Claude you are an expert in rust and well versed in language servers. Please review this implementation of ledger-lsp, a ledger language server in rust.

The initial design decision I made before prompting claude was that the LSP would be in rust since tower-lsp appeared fairly mature. During the implementation another key decision was to steer claude away from writing an error-prone regex based syntax parser to using tree-sitter – a surprisingly difficult ask. At every turn, claude wanted to revert to regex. Similarily, claude staunchly believed this LSP should be keeping track of balances across files, i.e. move all of of the ledger logic into the LSP. Nearly every session required steering the LLM towards supporting the editing experience and not trying to replace ledger. Despite the required steering, claude came up with some novel ideas I would not have thought of. For example, a warning if entries in a file were out of chronological order.

Overall, a few nights of coaching an LLM resulted in a useful tool in a language I’m unfamiliar with and my workflow for editing ledger files has noticeably improved. Several months ago I would think very carefully about whether I needed a tool before investing my time in to developing it. Today, I can cut a check to Anthropic and spend a few hours guiding an LLM – xkcd 1319 may no longer be relevant.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *