Haskell World logo Haskell WorldWrite code, build worlds
Developer Tools

Haskell ghcid Setup for Instant Feedback on Every Save

You save a file, switch to a terminal, type the build command, wait twenty seconds, and read a wall of errors that scrolled past the top of the screen.

A developer's desk with a laptop showing a code editor on the left and a terminal window with green compiler output on the right, next to a mug of coffee

You save a file, switch to a terminal, type the build command, wait twenty seconds, and read a wall of errors that scrolled past the top of the screen. Do that two hundred times a day and the build loop, not the type checker, becomes the slowest part of writing Haskell. A Haskell ghcid setup fixes that loop with one small tool that watches your files and shows the first error the moment you save.

ghcid is short for "GHCi daemon". It starts a GHCi session, loads your project, and reloads it every time a source file changes. Because GHCi only type checks and skips most code generation, a reload on a mid-sized project usually takes under two seconds, compared with fifteen to forty seconds for a full cabal build. This guide covers installing it, configuring it for cabal and stack projects, running tests on every save, and the situations where it is the wrong tool.

Installing Haskell ghcid and running it the first time

ghcid is a normal Hackage package, so install it the same way you install other executables. With cabal, run cabal install ghcid. With stack, run stack install ghcid. Both place a binary in your local bin directory, which is ~/.cabal/bin or ~/.local/bin on Linux and macOS. Check that the folder is on your PATH by running ghcid -h and confirming the help text prints.

From the root of a cabal project, the minimal command is:

ghcid -c "cabal repl"

For stack, swap in ghcid -c "stack ghci". The -c flag tells ghcid which command starts the REPL.

The terminal clears and shows either "All good" with a module count, or the first errors in your code. Leave that window open beside your editor. Save a file, and within a second or two the window refreshes.

Making ghcid fit your project

Typing the full command every morning gets old. ghcid reads default arguments from a file named .ghcid in the project root, one argument set per file. A typical one for a cabal project with a library and a test suite contains a single line such as:

-c "cabal repl lib:myapp" -o ghcid.txt

The -o flag writes the current output to a file as well as the terminal. Add ghcid.txt to your .gitignore so it never ends up in a commit.

Choosing which component to load

Projects with several components need a target. cabal repl lib:myapp loads only the library, which is fastest. cabal repl test:spec loads the test suite and, through it, the library modules it imports. Loading 300 modules when you only touch 12 of them adds seconds to every reload for no benefit.

Speeding up reloads with GHC flags

You can pass GHC options through the repl command. Adding -fno-code skips code generation entirely, which can cut reload time by half on modules heavy with Template Haskell. The catch is that you cannot run anything in that session, so use it for pure type checking and drop it when you want tests to run.

Running tests on every save

The feature that turns ghcid from a nice extra into a daily habit is the -T flag. It takes a GHCi expression and runs it after every successful reload. For an hspec suite, that looks like:

ghcid -c "cabal repl test:spec" -T "Main.main"

Now every save type checks the code and, if it compiles, runs the whole suite. For a suite of 400 fast unit tests, the round trip from keystroke to green or red is often under five seconds. If your suite is slower, narrow it. hspec accepts a match filter, so -T ":main -m Parser" runs only the specs whose description contains "Parser".

By default ghcid refuses to run tests while warnings exist. That is sensible for a clean codebase but annoying in the middle of a refactor. Add -W to let tests run even when the code still has warnings.

The same trick gives a live preview for small scripts. I point -T at a function that prints the result of my Data.Map lookups on a sample file and watch the output change as I edit.

Where the common advice gets ghcid wrong

A popular claim in forum threads is that the Haskell Language Server has made ghcid obsolete. I disagree, for a practical reason: they fail in different ways. HLS does a lot more work, including completions, hover types, and code actions, and on large projects that work regularly stalls or eats several gigabytes of memory. When it does, you lose all feedback at once. ghcid does one job, holds a single GHCi process, and uses a fraction of the memory. On a 2019 laptop with 8 GB of RAM, a project of 150 modules that made HLS sluggish ran under ghcid with about 1.2 GB in use.

The better setup for most people is both. Keep HLS for navigation and inline types, and keep ghcid running in a terminal as the source of truth for "does this compile and do the tests pass". When HLS shows something odd, the ghcid window tells you within two seconds whether the problem is your code or the language server.

The other advice worth questioning is to run ghcid on the entire project at all times. On big codebases that turns a two second reload into a fifteen second one, and the tool stops feeling instant. Scope it to the component you are working on and widen it only before you push.

Troubleshooting a ghcid session

Most problems fall into a handful of patterns:

  • It never reloads. ghcid watches files that GHCi loaded. A new module that nothing imports yet will not be watched. Import it somewhere, or restart ghcid.
  • Changes to the cabal file are ignored. Adding a dependency requires a restart of the GHCi process. ghcid has a restart option that takes a file path, and pointing it at your .cabal file makes it restart automatically when you add a package.
  • It reports errors that cabal build does not. Check that both use the same flags and the same GHC. A mismatch in default extensions between the cabal file and a ghci config file is a frequent culprit.

A daily workflow that sticks

Here is the arrangement that has lasted longest for me. The editor takes two thirds of the screen. A terminal on the right runs ghcid with the test suite filtered to the module I am editing. A second terminal below it holds a plain GHCi for experiments, as described in using GHCi as your daily Haskell workflow. Before pushing, I widen the ghcid target to the full test suite and wait for one green run, then let CI do the slow full build.

The payoff is attention more than seconds. When feedback arrives before your eyes leave the code, you fix the error while you still remember why you wrote the line.

Frequently asked questions

Does ghcid work with stack and cabal?

Yes. Pass stack ghci or cabal repl through the -c flag, and add a component name if your project has more than one. ghcid only needs a command that starts a GHCi prompt, so it also works with Nix shells that wrap either tool.

Is ghcid faster than cabal build?

For the edit and check loop, usually yes, by a factor of five to ten on mid-sized projects. GHCi reloads only the modules that changed and their dependents, and it skips optimisation. It does not replace a full build before release, because optimised code and linking only happen in the real build.

Can I use ghcid inside VS Code or Neovim?

You can run it in the editor's built-in terminal, which is what most people do. Small plugins can also read the -o output file and show errors inline.

SR
Sonja Reiter

Sonja Reiter contributed to three major open source projects and started writing documentation when she noticed most tooling guides were written by people who had never taught anyone to use them. She covers build tools, package ecosystems, and the invisible quality-of-life differences between development setups.

More posts by Sonja

More in Developer Tools

01doorganico 084goad 3hot8 4465456 after5internprogram ahandfulofblessings ahmadpc ahomcybersecurity allodialresources annodex antiquesandperiodcollectibles aotc asianworldkashmir beedlectrics bloggertemplatefree bluefeatheragency bodyweightsolution campaign08blog carfixadvisor catstreetcollective cbstvsports cnfanspurchasing committeeof500yearsofdignityandresistance covertopsdjs cs-kaiyuangame cuestacomunicaciontotal cxoutlet dancebetgame deskgearhub destinyvillastay detectmagazine di33 diamondsteelbuildings donmo dyanadropship emarsysfinance emimattl escapechan eskitarih evautoplay everythingweddings-orlando farmzone feedviewerapp foxstudiosscratch gamevui123 gleasongrade greetingsday hacklabasu iw-kaiyun jagoanproperti jilidskripsi joltbusinessfinance juegodepokergratis juegospucca kaeru-festival latestmehndidesigns lestanzediottaviano litemagazines localcommunityhero lustrsazan mariashebets menswheels newwebstechs1 nikkit ootheday oxigenvpn plurfitness prefetial probudgetcarpetcleaning psychicmrsmartin pyaten qvantor rejoignezlogis rexzbot riselayouts ruchin rwxqsgd5 sakaltime shibiaowang shop-bot skrtips spotlesshaven strcoding tetapatrium topselller uneplanteartificielle vipertechcr webtech1223411 wo-kygaming yamaha-mekar yeknava yoybuysheets zenunwa yamaha-mekar jilidskripsi ankertoto ankertoto ankertoto