title: How to auto-update SSH agent environment variables when attaching to existing tmux sessions
body: <p>I am trying to find a nice way to restore the SSH agent when I reconnect a disconnected tmux session.</p>
  
  <p>The cause seems to be that the SSH agent session changes but the environment variable from the tmux session is not updated.</p>
  
  <p>How can I automate this, before attaching the session itself? Because the session I am attaching to does not always have a bash prompt, so I cannot afford to type something inside it. It has to be something to run before creating or attaching the tmux session.</p>
  
  <p>An example of the code I'm running is at <a href="https://gist.github.com/ssbarnea/8646491" rel="noreferrer">https://gist.github.com/ssbarnea/8646491</a> -- a small ssh wrapper that is using tmux to create persistem ssh connections. This works quite well, but sometimes the ssh agent stops working so I am no longer able to use it to connect to other hosts.</p>