# Try reducing reboots with Claude Code

My laptop has reset itself under load before. In [an earlier post](https://blog.koorevaar.com/articles/self-hosted-runner-laptop-resets-under-load) I traced it to my self-hosted GitHub Actions runner, and limits on the job containers fixed that. Then it happened again, and this time the load came from Claude Code itself. This post covers what Claude did, what it said about it, and the limits I put on its container.

## What happened

I ran Claude Code without any resource limits. Its container could use every core and all the memory of the laptop. During a long session it ran the full test suite at full speed several times, the full browser check three times, and a local server with a browser next to that. It was in another full run when the laptop went down. It was the same pattern as the reset on 3 November.

After the reboot I asked Claude what had happened. It answered like this:

> About the reboot: this was very likely my doing again. Today I ran the full test suite at full speed several times, plus the full browser check three times and a local server with a browser, and I was in another full run when it went down, the same pattern as the reset on 3 November. Thanks for the limits; 4 CPUs and 8 GB is a good cap. From now on I'll run only the tests that matter at two parallel workers, leave the full browser check to GitHub's CI on the PR, and stop the local server as soon as I'm done. I've saved that in my notes.

I like this answer because it does two things. It names the cause without blaming the hardware, and it turns that into rules it can follow: only the tests that matter, two parallel workers, the full browser check on GitHub's CI instead of my laptop, and no local server left running. Claude saved those rules in its notes, so a later session starts with them.

There is a catch: it had saved rules like this to its notes on earlier occasions too, and the reboot still happened. Notes are good intentions. They do not stop a long session from running one full test run too many.

## Why a limit and not only a promise

A promise in the notes helps, but it is a habit, and I have seen habits slip: the notes were already there and the laptop reset anyway. A limit on the container is a fact: whatever Claude runs, it cannot take the whole machine. If a test run needs more than the cap, it gets slower or stops with an out-of-memory error. My laptop keeps running.

So I use both, but I only trust one of them. The notes steer Claude toward lighter runs, and the limits protect the laptop when the notes are not followed.

## The limits

For a container started with Docker Compose, I added this to `docker-compose.yml`:

```yaml
cpus: 4
mem_limit: 8g
memswap_limit: 8g
pids_limit: 2048
```

* `cpus: 4` caps the container at four cores, however many the laptop has.
* `mem_limit: 8g` caps memory at 8 GB.
* `memswap_limit: 8g`, equal to the memory limit, means no extra swap. A process that needs more is stopped instead of slowing down everything else.
* `pids_limit: 2048` caps the number of processes, so a runaway test or script cannot fork without end.

For Docker Sandboxes ([sbx](https://blog.koorevaar.com/articles/from-docker-compose-to-docker-sandboxes-claude-code-sbx)) the same idea goes in `sbxenv.yaml`:

```yaml
sandboxOptions:
  cpus: 4
  memory: 8g
```

The two that matter most are the same: CPU and memory.

## What I take from it

* An agent that runs tests for you will happily run all of them, in parallel, again and again. Without a limit, your machine pays for that.
* Ask Claude after a reset. It had the full picture of what it had run and in what order, and it recognised the pattern from the earlier reset.
* Do not rely on Claude's notes alone. It saved such rules before and the reboot still happened. Use the notes for behaviour and container limits for a hard cap.
* Move heavy checks to CI. The full browser check runs on GitHub on the pull request, not on my laptop.

If you want the longer story of the earlier resets and the other changes that helped (fewer parallel jobs and a lower maximum processor state), read [My laptop kept resetting under self-hosted GitHub Actions load: what stopped it](https://blog.koorevaar.com/articles/self-hosted-runner-laptop-resets-under-load).

---

*Co-authored with Claude.*

If this was useful, [you can buy me a coffee](https://ko-fi.com/p47k0).

New articles: [follow via RSS](https://blog.koorevaar.com/feed.xml).
