Skip to content

Instantly share code, notes, and snippets.

@Codeklopper
Last active April 21, 2026 08:51
Show Gist options
  • Select an option

  • Save Codeklopper/04aea8f8e49e6ca9a6e567e7d3d41d87 to your computer and use it in GitHub Desktop.

Select an option

Save Codeklopper/04aea8f8e49e6ca9a6e567e7d3d41d87 to your computer and use it in GitHub Desktop.
Trigger Claude Code session start using a systemd timer

Trigger Claude Code session start using a systemd timer

This will start a Claude Code session, so you can optmize the 5 hour token limit window. It will start at the scheduled time or as soon as you log in to your machine.

Tested on Ubuntu 24.04 with nvm.

Step 1: create service and timer

Create the 2 files from this gist in:

  • ~/.config/systemd/user/wake-claude.service
  • ~/.config/systemd/user/wake-claude.timer

Now adjust the files:

  • wake-claude.service: Replace {USER} with your username
  • wake-clauude.timer: Adjust the schedule to your prereference

Step 2: Reload daemon, test and enable timer

  • systemctl --user daemon-reload
  • systemctl --user enable wake-claude.timer

To run the service without timer: systemctl --user start wake-claude.service

Step 3: Monitor usage

journalctl --user -xeu wake-claude.service journalctl --user -xeu wake-claude.timer

#~/.config/systemd/user/wake-claude.timer
[Unit]
Description=Wake up Claude Code. Do this again after 5 hours, when the Claude Max limit resets
[Service]
Type=oneshot
RemainAfterExit=yes
Environment="HOME=/home/{USER}"
# Fires at the scheduled moment defined in wake-claude.timer (or catch-up boot time)
ExecStart=/bin/bash -c 'source /home/{USER}/.nvm/nvm.sh && claude --print --model=sonnet "Hello"'
# follow-up – sleep exactly 5 h and 2 minutes, then call it again. Added 2 extra minutes to be sure the 5h session is expired
ExecStartPost=/bin/bash -c 'sleep 5h 2m && source&& source /home/{USER}/.nvm/nvm.sh && claude --print --model=sonnet "Hello again"'
[Unit]
Description=Run wake-claude.service every day at 06:59 (catch-up if missed)
[Timer]
OnCalendar=*-*-* 06:59
# run once at boot if the 06:59 run was missed
Persistent=true
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment