diff --git a/addons/tab_completion/tab_completion.rb b/addons/tab_completion/tab_completion.rb
index <HASH>..<HASH> 100644
--- a/addons/tab_completion/tab_completion.rb
+++ b/addons/tab_completion/tab_completion.rb
@@ -36,20 +36,24 @@ class TabCompletion < Addon
   # +pre_word_context+ is the "lib/" if the user hits tab after typing "ls lib/"
   # because the current word will be set to ""
   def pre_word_context
-    # Work our way backwards thru the text because we can stop as soon as
-    # see a word break character rather than having to keep track of them.
-    i = @before_text.length
-    str = ""
-    loop do
-      i -= 1
-      ch = @before_text[i]
-      if ch =~ filtered_work_break_characters_rgx && (i>0 && @before_text[i-1] != '\\')
-        break
-      else
-        str << ch
+    if @before_text.length == 0
+      ""
+    else
+      # Work our way backwards thru the text because we can stop as soon as
+      # see a word break character rather than having to keep track of them.
+      i = @before_text.length
+      str = ""
+      loop do
+        i -= 1
+        ch = @before_text[i]
+        if ch =~ filtered_work_break_characters_rgx && (i>0 && @before_text[i-1] != '\\')
+          break
+        else
+          str << ch
+        end
       end
+      str.reverse
     end
-    str.reverse
   end
 
   def get_filename_completion_matches
Update pre_word_context for tab completion to be an empty string if there is no before_text to choose from.

Resolves issue hitting tab when nothing has been input into the REPL.