Conditionally map keys depending on the application being used
Use a private.xml like this with Karabiner:

&lt;?xml version="1.0"?&gt;
&lt;root&gt;
  &lt;appdef&gt;
    &lt;appname&gt;TERMINAL&lt;/appname&gt;
    &lt;equal&gt;com.apple.Terminal&lt;/equal&gt;
  &lt;/appdef&gt;
  &lt;item&gt;
    &lt;name&gt;onlyterminal&lt;/name&gt;
    &lt;identifier&gt;onlyterminal&lt;/identifier&gt;
    &lt;only&gt;TERMINAL&lt;/only&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::COMMAND_L, KeyCode::OPTION_L&lt;/autogen&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::COMMAND_R, KeyCode::OPTION_R&lt;/autogen&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::OPTION_L, KeyCode::COMMAND_L&lt;/autogen&gt;
    &lt;autogen&gt;__KeyToKey__ KeyCode::OPTION_R, KeyCode::COMMAND_R&lt;/autogen&gt;
  &lt;/item&gt;
&lt;/root&gt;