diff --git a/src/ChangeLog b/src/ChangeLog
index 5052b35..7aa5243 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -49,6 +49,8 @@ Version 4.1.0 (??/??/20??):
     '%+p' expands to the PID of the frontend (display).
   * '%S' in caption/hardstatus string expands to the session name.
   * '%P' in the caption string evaluates to true if the region is in copy mode.
+  * '%E' in the caption string evaluates to true if the session has seen the
+    escape character.
 
   Window List:
   * Nested views when there are window groups (with 'windowlist -g').
diff --git a/src/doc/screen.1 b/src/doc/screen.1
index bbf7975..d1333a2 100644
--- a/src/doc/screen.1
+++ b/src/doc/screen.1
@@ -3325,6 +3325,8 @@ current time HH:MM in 12h format
 day number
 .IP D
 weekday name
+.IP E
+sets %? to true if the session has seen an escape character
 .IP f
 flags of the window
 .IP F
diff --git a/src/doc/screen.texinfo b/src/doc/screen.texinfo
index 6142de0..fdaf75a 100644
--- a/src/doc/screen.texinfo
+++ b/src/doc/screen.texinfo
@@ -5213,6 +5213,8 @@ current time @code{HH:MM} in 12h format
 day number
 @item D
 weekday name
+@item E
+sets %? to true if the session has seen an escape character
 @item f
 flags of the window. @xref{Windows}, for meanings of the various flags.
 @item F
diff --git a/src/process.c b/src/process.c
index 70bb4fa..e7049a7 100644
--- a/src/process.c
+++ b/src/process.c
@@ -902,12 +902,19 @@ int ilen;
 	  if (slen)
 	    DoProcess(fore, &ibuf, &slen, 0);
 	  if (--ilen == 0)
+	  {
 	    D_ESCseen = ktab;
+	    WindowChanged(fore, 'E');
+	  }
 	}
       if (ilen <= 0)
         return;
       ktabp = D_ESCseen ? D_ESCseen : ktab;
-      D_ESCseen = 0;
+      if (D_ESCseen)
+        {
+          D_ESCseen = 0;
+          WindowChanged(fore, 'E');
+        }
       ch = (unsigned char)*s;
 
       /* 
@@ -1820,10 +1827,18 @@ int key;
 	    }
 	  if (D_ESCseen != ktab || ktabp != ktab)
 	    {
-	      D_ESCseen = ktabp;
+	      if (D_ESCseen != ktabp)
+	        {
+	          D_ESCseen = ktabp;
+	          WindowChanged(fore, 'E');
+	        }
 	      break;
 	    }
-	  D_ESCseen = 0;
+	  if (D_ESCseen)
+	    {
+	      D_ESCseen = 0;
+	      WindowChanged(fore, 'E');
+	    }
 	}
       /* FALLTHROUGH */
     case RC_OTHER:
@@ -6358,6 +6373,7 @@ int i;
       if (act->nr != RC_ILLEGAL)
 	{
 	  D_ESCseen = 0;
+	  WindowChanged(fore, 'E');
           DoAction(act, i + 256);
 	  return 0;
 	}
@@ -6383,7 +6399,11 @@ int i;
 
   if (discard && (!act || act->nr != RC_COMMAND))
     {
-      D_ESCseen = 0;
+      if (D_ESCseen)
+        {
+          D_ESCseen = 0;
+          WindowChanged(fore, 'E');
+        }
       return 0;
     }
   D_mapdefault = 0;
diff --git a/src/screen.c b/src/screen.c
index 212bee2..07a8e9f 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -2833,6 +2833,13 @@ int rec;
 		qmflag = 1;
 	    }
 	  break;
+	case 'E':
+	  p--;
+	  if (display && D_ESCseen)
+	    {
+	      qmflag = 1;
+	    }
+	  break;
 	case '>':
 	  truncpos = p - winmsg_buf;
 	  truncper = num > 100 ? 100 : num;
