:warning: Listen is looking for new maintainers. Please contact me if you're interested.


Gem Version Build Status Dependency Status Code Climate Coverage Status

The Listen gem listens to file modifications and notifies you about the changes.


Please note that: - Specs suite on JRuby and Rubinius aren't reliable on Travis CI, but should work. - Windows and *BSD adapter aren't continuously and automaticaly tested. - *BSD is broken and not supported any more, see: #220

Pending features

Pull request or help is very welcome for these.


The simplest way to install Listen is to use Bundler.

gem 'listen', '~> 2.0'


Call Listen.to with either a single directory or multiple directories, then define the "changes" callback in a block.

listener = Listen.to('dir/to/listen', 'dir/to/listen2') do |modified, added, removed|
  puts "modified absolute path: #{modified}"
  puts "added absolute path: #{added}"
  puts "removed absolute path: #{removed}"
listener.start # not blocking

Pause / unpause / stop

Listeners can also be easily paused/unpaused:

listener = Listen.to('dir/path/to/listen') { |modified, added, removed| # ... }

listener.paused? # => false
listener.processing? # => true

listener.pause   # stops processing changes (but keeps on collecting them)
listener.paused? # => true
listener.processing? # => false

listener.unpause # resumes processing changes ("start" would do the same)
listener.stop    # stop both listening to changes and processing them

Note: While paused, Listen keeps on collecting changes in the background - to clear them, call "stop"

Note: You should keep track of all started listeners and stop them properly on finish.

Ignore / ignore!

Listen ignores some directories and extensions by default (See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer), you can add ignoring patterns with the ignore option/method or overwrite default with ignore! option/method.

listener = Listen.to('dir/path/to/listen', ignore: /\.txt/) { |modified, added, removed| # ... }
listener.ignore! /\.pkg/ # overwrite all patterns and only ignore pkg extension.
listener.ignore /\.rb/   # ignore rb extension in addition of pkg.

Note: Ignoring regexp patterns are evaluated against relative paths.


Listen catches all files (less the ignored once) by default, if you want to only listen to a specific type of file (ie: just rb extension) you should use the only option/method.

listener = Listen.to('dir/path/to/listen', only: /\.rb$/) { |modified, added, removed| # ... }
listener.only /_spec\.rb$/ # overwrite all existing only patterns.

Note: ':only' regexp patterns are evaluated only against relative file paths.

Changes callback

Changes to the listened-to directories gets reported back to the user in a callback. The registered callback gets invoked, when there are changes, with three parameters: modified, added and removed paths, in that particular order. Paths are always returned in their absolute form.


listener = Listen.to('path/to/app') do |modified, added, removed|
  # This block will be called when there are changes.

or ...

# Create a callback
callback = Proc.new do |modified, added, removed|
  # This proc will be called when there are changes.
listener = Listen.to('dir', &callback)


All the following options can be set through the Listen.to after the directory path(s) params.

ignore: [%r{/foo/bar}, /\.pid$/, /\.coffee$/]   # Ignore a list of paths
                                                # default: See DEFAULT_IGNORED_DIRECTORIES and DEFAULT_IGNORED_EXTENSIONS in Listen::Silencer

ignore!: %r{/foo/bar}                           # Same as ignore options, but overwrite default ignored paths.

only: %r{.rb$}                                  # Only listen to specific files
                                                # default: none

latency: 0.5                                    # Set the delay (**in seconds**) between checking for changes
                                                # default: 0.25 sec (1.0 sec for polling)

wait_for_delay: 4                               # Set the delay (**in seconds**) between calls to the callback when changes exist
                                                # default: 0.10 sec

force_polling: true                             # Force the use of the polling adapter
                                                # default: none

polling_fallback_message: 'custom message'      # Set a custom polling fallback message (or disable it with false)
                                                # default: "Listen will be polling for changes. Learn more at https://github.com/guard/listen#polling-fallback."

debug: true                                     # Enable Celluloid logger
                                                # default: false

Also, setting the environment variable LISTEN_GEM_DEBUGGING=1 does the same as debug: true above.

Listen adapters

The Listen gem has a set of adapters to notify it when there are changes. There are 4 OS-specific adapters to support Darwin, Linux, *BSD and Windows. These adapters are fast as they use some system-calls to implement the notifying function.

There is also a polling adapter which is a cross-platform adapter and it will work on any system. This adapter is slower than the rest of the adapters.

The Darwin and Linux adapters are dependencies of the Listen gem so they work out of the box. For other adapters a specific gem will have to be added to your Gemfile, please read below.

The Listen gem will choose the best adapter automatically, if present. If you want to force the use of the polling adapter, use the :force_polling option while initializing the listener.

On Windows

If your are on Windows, you can try to use the wdm instead of polling. Please add the following to your Gemfile:

require 'rbconfig'
gem 'wdm', '>= 0.1.0' if RbConfig::CONFIG['target_os'] =~ /mswin|mingw|cygwin/i


NOTE: *BSD currently is BROKEN with no plans to fix it or support it (see: #220)

If your are on *BSD you can try to use the rb-kqueue instead of polling. Please add the following to your Gemfile:

require 'rbconfig'
gem 'rb-kqueue', '>= 0.2'
if RbConfig::CONFIG['target_os'] =~ /bsd|dragonfly/i
  gem 'rb-kqueue', '>= 0.2'

  # Base versions have known conflicts/bugs
  # Even master branches may not work...
  gem 'ffi', github: 'carpetsmoker/ffi', ref: 'ac63e07f7'
  gem 'celluloid', github: 'celluloid/celluloid', ref: '7fdef04'

Issues and troubleshooting

Sometimes OS-specific adapters don't work. :'(

Here are some things you could try to avoid forcing polling.

If your application keeps using the polling-adapter and you can't figure out why, feel free to open an issue (and be sure to give all the details).

Also, if you have problems related to receiving the wrong events, too many events or none at all, be sure set the environment variable LISTEN_GEM_DEBUGGING=1 and include the output when reporting a new issue.

If the listener works and then stops listening at some point and no errors are shown with LISTEN_GEM_DEBUGGING=1, set LISTEN_GEM_DEBUGGING=2 for full logging.

Listen traps SIGINT signal to properly finalize listeners. If you plan on trapping this signal yourself - make sure to call Listen.stop in signal handler.


If Listen seems slow or unresponsive, make sure you're not using the Polling adapter (you should see a warning upon startup if you are).

Also, if the directories you're watching contain many files, make sure you're:

When in doubt, LISTEN_GEM_DEBUGGING=2 can help discover the actual events and time they happened.

Forwarding file events over TCP

Listen is capable of forwarding file events over the network using a messaging protocol. This can be useful for virtualized development environments when file events are unavailable, as is the case with Vagrant.

To broadcast events over TCP programmatically, use the forward_to option with an address - just a port or a hostname/port combination:

listener = Listen.to 'path/to/app', forward_to: '' do |modified, added, removed|
  # After broadcasting the changes to any connected recipients,
  # this block will still be called

As a convenience, the listen script is supplied which listens to a directory and forwards the events to a network address

listen -f ""
listen -v -d "/projects/my_project" -f ""

To connect to a broadcasting listener as a recipient, specify its address using Listen.on:

listener = Listen.on '' do |modified, added, removed|
  # This block will be called

Security considerations

Since file events potentially expose sensitive information, care must be taken when specifying the broadcaster address. It is recommended to always specify a hostname and make sure it is as specific as possible to reduce any undesirable eavesdropping.


Pull requests are very welcome! Please try to follow these simple rules if applicable:

For questions please join us in our Google group or on #guard (irc.freenode.net).



Thibaud Guillaume-Gentil (@thibaudgg)