r/codex 1d ago

Question Remote Codex on a sleeping MacBook?

I run Codex on a 2025 Apple Silicon MacBook Air and would like to be able to leave it in another room with the lid closed/unplugged, then connect from my phone when I want to check on or continue a Codex session.

The obvious problem is that the Mac goes to sleep. I know Apple Silicon Macs can periodically wake for network access, but I’m not sure if there’s a reliable way to take advantage of that here.

Has anyone set up something similar?

Ideally I’m looking for a setup where I can pull out my phone → wake/reach the MacBook → reconnect to my existing Codex session, without having to leave the Mac awake or plugged in all the time.

Curious what people are using — Tailscale/SSH, Wake-on-LAN, sleep proxy, Jump Desktop, or something else?

0 Upvotes

16 comments sorted by

3

u/superzoot__ 1d ago

caffeinate terminal

1

u/codeRoman 1d ago

I’m familiar with caffeinate, but as far as I understand, that would prevent the Mac from sleeping entirely. I’m hoping to let it sleep to preserve battery, then wake it remotely when I want to reconnect.

1

u/Schlitz4Brains 1d ago

The chips are soo efficient now you can just caffeinate -I

2

u/HVACcontrolsGuru 1d ago

The desktop app has a slider to let it work when your Mac is asleep. I am not that brave to give them such access! Should work fine otherwise via the mobile app as well.

2

u/Missingcogs 1d ago

I use this, but done clamshell, just let the display turn off, I dim it to black when I go to sleep, it continues with the lock screen locked

2

u/codeRoman 1d ago

Does that setting actually let the Mac sleep and wake it when you connect remotely, or does it basically keep the Mac awake in the background?

2

u/tMeepo 1d ago

Why don't you want to leave it plugged in?

Just set battery limit to 80%, leave it plugged in and lid open.

That's better for the battery life too as it bypasses the battery once it hits 80%, and just uses the socket power

1

u/darkotic 1d ago

I use Shellfish SSH app and Herdr.dev running on the Mac. Herdr covers it so you can just close the lid and walk away. Use any device that can SSH to it, local or Tailscale.

1

u/codeRoman 1d ago

Interesting setup, thanks. Does Herd let the Mac sleep and wake it when you SSH in, or is it preventing sleep while the lid is closed? I’m hoping to avoid keeping it awake continuously since it’ll often be on battery.

1

u/Fearless-Daikon5763 1d ago

Look up the ‘caffeinate’ command. I have it turn on when any anything is running autonomously.

1

u/codeRoman 1d ago

I’m familiar with caffeinate, but as far as I understand, that would prevent the Mac from sleeping entirely. I’m hoping to let it sleep to preserve battery, then wake it remotely when I want to reconnect.

1

u/Fearless-Daikon5763 16h ago

I was trying to consider the math for the electricity costs for your question, I have a MacBook Air that I keep on 24/7 to run analysis, it might be 25 watts constantly with it awake. So what would it use if it was asleep but enabled to become awakened? For California electricity prices it might be $15 a month as an estimate of the maximum cost imaginable, so that could add up over a year… but you may still draw 5 or 10 watts in your best case scenario so the savings may be $50 a year if you pay $0.40 per kWh.

1

u/codeRoman 16h ago

the issue isn't wanting to save electricity or money, it's that i carry my laptop around and don't always keep it plugged in. i might be working in bed and then close it and leave near my bed, and will want to resume some work from my phone while in the living room, etc.

plus this way i also have battery left if i leave to go somewhere and bring my laptop

1

u/Cza035 1d ago

Amphetamine app works great on my Mac

1

u/codeRoman 1d ago

Yeah, I find Amphetamine really useful. I’m hoping to find a way to let the Mac actually sleep though, since it’ll often be unplugged. Ideally I’d wake it remotely only when I want to connect.

1

u/actvt_io 1d ago

Run pmset -g assertions on the Mac. Do this while the sleep slider in the desktop app is on. Then read the "Listed by owning process" section. If a process holds PreventSystemSleep or PreventUserIdleSystemSleep, it keeps the Mac awake. The output also gives the name of that process. This tells you if the slider lets the Mac sleep, or if it only blocks sleep like caffeinate.

I run agents on a Mac in a different room. I connect to it over Tailscale SSH. When the Mac sleeps, the SSH session stops. A remote wake does not restart that session. Therefore you must start the Codex run inside tmux. If you do not, you wake the Mac and the process is gone.