Starting form ant's solution and digging inside the Karabiner.app package to see how it works, I found a way to make it work using only Karabiner :
Simply edit your Karabiner private.xml (found in ~/Library/Application Support/Karabiner/private.xml
)
to the following :
<?xml version="1.0"?>
<root>
<appdef>
<appname>TERMINAL</appname>
<equal>com.apple.Terminal</equal>
</appdef>
<item>
<name>Option-Left to Meta in Terminal</name>
<only>TERMINAL</only>
<identifier>private.optionltometa</identifier>
<autogen>__KeyToKey__ KeyCode::OPTION_L, KeyCode::VK_MODIFIER_EXTRA1</autogen>
<include path="/Applications/Karabiner.app/Contents/Resources/include/checkbox/apps/terminal/meta_modifier_key.xml">
<replacementdef>
<replacementname>BEFORE</replacementname>
<replacementvalue>KeyCode::ESCAPE</replacementvalue>
</replacementdef>
<replacementdef>
<replacementname>AFTER</replacementname>
<replacementvalue></replacementvalue>
</replacementdef>
</include>
</item>
</root>
Then launch Karabiner and press the Reload XML button in the Change Key tab (I'm using version 10.22.0, maybe the tab names have changed in newer versions)
The advantage of this method is that it does not disable your left option key when you are not using Terminal, as the solution using Seil does.