Keeping long AI agent sessions alive on a codespace
Short answer: Two separate timers end long sessions. The network drops an idle SSH connection, which the keepalive the extension writes prevents (ServerAliveInterval 30, ServerAliveCountMax 10). GitHub stops an inactive codespace after its idle timeout, which you raise in your Codespaces settings on GitHub.
Agents in Cursor or Antigravity can work for a long stretch without any input from you. Two separate timers can end that work early, and they need different fixes.
Why does the network drop an idle connection?
Routers, VPNs and corporate proxies close TCP connections that carry no traffic for a while. An agent that is thinking, or waiting on a long build, can look idle from the network's point of view. SSH keepalive sends a small packet at a fixed interval so the connection never looks idle.
The extension writes these lines into each codespace host block:
ServerAliveInterval 30 ServerAliveCountMax 10
That is a probe every 30 seconds, and the client gives up only after 10 unanswered probes, roughly five minutes of real silence. Both values are settings (serverAliveInterval, serverAliveCountMax). Run Sync SSH Config after changing them.
Why does GitHub stop an inactive codespace?
Independently of SSH, GitHub stops a codespace after a period of inactivity. That timeout is a GitHub setting, not an SSH one, and the extension does not change it. You can raise it in your Codespaces settings on GitHub. A longer timeout also means more billed compute if you forget a codespace, so pick a value you are comfortable paying for.
What should I check before a long run?
- Keep the default keepalive, or shorten the interval on flaky networks.
- Set a GitHub idle timeout that covers your longest agent run.
- Watch the usage card in the Cloud Hub so a long run does not surprise you at the end of the month.
- If a session still drops, use Reconnect to Last Codespace; the codespace keeps your files.
Frequently asked questions
What keepalive does the extension write?
ServerAliveInterval 30 and ServerAliveCountMax 10: a probe every 30 seconds, and the client gives up only after 10 unanswered probes, roughly five minutes of real silence.
Does the extension change GitHub's idle timeout?
No. The idle timeout is a GitHub setting. You can raise it in your Codespaces settings on GitHub.
What if a session still drops?
Use Reconnect to Last Codespace. The codespace keeps your files.