comint-preoutput-filter-functions is a variable defined in `comint.el'.
Its value is

  • This variable's value is permanent if it is given a local binding.
  • This variable may be risky if used as a file-local variable.

List of functions to call before inserting Comint output into the buffer.
Each function gets one argument, a string containing the text received
from the subprocess. It should return the string to insert, perhaps
the same string that was received, or perhaps a modified or transformed

The functions on the list are called sequentially, and each one is
given the string returned by the previous one. The string returned by
the last function is the text that is actually inserted in the
redirection buffer.

You can use `add-hook' to add functions to this list
either globally or locally.