Adding a base directories class/module to the standard library

Hey folks,

During a recent discussion on Discord, I raised the idea of having an alternative to directories-rs in Crystal. @straight-shoota suggested that we discuss it further here and possibly include the newly added module in the standard library.


  • Consistent behavior across different operating systems. Configuration, cache, data, etc., would be accessed through a unified API without worrying about platform-specific nuances. This might benefit the compiler and Shards as well.
  • Promotion of best practices, whereas a Crystal developer might typically opt for a lazy solution, such as storing this data alongside the binary (which is not idiomatic on Linux and other operating systems).
  • It is relatively easy to implement, and almost no maintenance should be required.


  • Assuming this is going to be added, we would need to decide which directories are to be included. The bare minimum might be what’s described in the XDG Base Directory Specification.

What are the thoughts?


We can probably take a lot of inspiration from the dirs-dev implementations (including directories-rs). Their authors seem to have figured out a practical API and behaviour.

I’m a bit surprised though that the XDG_* environment variables seem to be only honored on Linux. I figure they should work on any operating system (if defined by the user).

I’d even suggest to add this to the standard library. It provides functionality that could probably be useful for most CLI applications.


I find that odd too. It’s a freedesktop specification part of, and not tied to Linux in any way. Maybe they just don’t care or forgot about UNIX in general and *BSD in particular.

XDG_* has always felt like it just arrived too late to the party and has struggled for adoption.

Regardless, I think this is a great idea and would love to see it in stdlib.

1 Like