@sh1so6/pi-cache-ttl-main

Pi extension: 1-hour Anthropic prompt cache for the main session only (subagents untouched)

Packages

Package details

extension

Install @sh1so6/pi-cache-ttl-main from npm and Pi will load the resources declared by the package manifest.

$ pi install npm:@sh1so6/pi-cache-ttl-main
Package
@sh1so6/pi-cache-ttl-main
Version
0.1.3
Published
Nov 12, 2026
Downloads
462/mo · 462/wk
Author
sh1so6
License
MIT
Types
extension
Size
15.9 KB
Dependencies
0 dependencies · 1 peer
Pi manifest JSON
{
  "extensions": [
    "./index.ts"
  ]
}

Security note

Pi packages can execute code and influence agent behavior. Review the source before installing third-party packages.

README

@sh1so6/pi-cache-ttl-main

English | 日本語

Pi extension. Makes the Anthropic prompt cache last 1 hour (ttl 1h) for the main session only. Subagents are left untouched. This stops the cache from expiring while you wait 5–60 minutes for background subagents, which would otherwise force a ~150k-token rewrite every time.

pi install npm:@sh1so6/pi-cache-ttl-main
  • Command: /cache-ttl (on/off, write count, cacheWrite / cacheWrite1h of the latest turn)
  • Config (optional): ~/.pi/agent/cache-ttl-main.json { "enabled": true }
  • The before-expiry trigger of @sh1so6/pi-context-relay relies on the 1h cache (cacheWrite1h > 0) this extension enables.
  • Main/subagent detection uses ctx.mode (tui / rpc = main, print / json = subagent; hasUI only when no mode is reported) and never the session name: a worker#<8hex> session that a person resumes is main and gets the 1h cache. This relies on pi-subagents binding children without a UI context (Pi then reports mode print; checked against pi-subagents 0.23.2 / Pi 1.5.1). If a future pi-subagents gives children a UI context or mode: "tui", they would be treated as main (the regression tests in index.test.mjs pin the current rule). RPC reporting hasUI: true was verified on Pi 1.5.1 only (not 1.5.2); the mode-based rule does not depend on it.
  • See the header comment of index.ts for details and limitations.