aigent-os

Claude Code harness and alternative to context compaction: at 80% context it writes a verified capsule, runs /clear and resumes with persistent memory in git.

View the Project on GitHub wrg32786/aigent-os

How do I make Claude Code run /clear automatically at a context threshold?

Claude Code itself only compacts automatically; /clear is manual. aigent-os adds the missing loop: at a threshold (80% by default) it gets a capsule and an exact acknowledgement from Claude, sends one /clear, waits for the new session’s SessionStart receipt, and resumes from the capsule.

How aigent-os does it

The aigent launcher runs Claude Code under a local runner (daemons/pty-runner.mjs, using node-pty). Each piece has one job:

The rules are strict on purpose. The acknowledgement has to be an exact line in a text block of Claude’s own reply, so talking about clearing doesn’t count. An acknowledgement only covers its own cycle. If operator input interrupts a prepared clear, the runner stops at HOLD:clear-stalled-after-ack with a visible notice instead of guessing. There’s no automatic retry.

Change the threshold with AIGENT_PRESSURE_THRESHOLD_PCT. Turn automatic input off per seat with AUTO_CLEAR_OFF=1 or the runtime/auto-clear-off marker. If node-pty can’t load (or you install with --no-deps), Claude still starts and the launcher tells you automatic clear is unavailable.

Install

Full install (needs Claude Code, Node.js 18+ with npm, and bash; on Windows use Git Bash):

git clone https://github.com/wrg32786/aigent-os.git && cd aigent-os && bash install.sh --dry-run

The dry run prints the planned changes and writes nothing. When it looks right, run bash install.sh, open a new terminal and run aigent.

Just want the manual capsule commands? Install the context-capsule plugin inside Claude Code:

/plugin marketplace add wrg32786/aigent-os
/plugin install context-capsule@aigent-os

Limits

Full list: the Known limits section of the v1.1.0 release notes.

FAQ

Is there a Claude Code auto clear setting?

Not in Claude Code itself; it only compacts automatically. aigent-os adds an auto clear loop: capsule, exact acknowledgement, one /clear, fresh session check, resume.

What threshold does it use?

80% by default, configurable with the AIGENT_PRESSURE_THRESHOLD_PCT environment variable.

What if Claude never confirms the capsule?

Then there is no clear. No acknowledgement means no clear, and one acknowledgement buys one clear.

More