Ephemeral State In Tmp

Use when about to write a state, cursor, marker, scratch, or progress file for a cron loop, monitor task, polling job, recurring schedule, or any session-scoped/ephemeral data — directs the file to /tmp/<name>.json instead of ~/.claude/ or other config dirs.

amitkot 7fe3970 1.4 KB Updated

File contents

Session-only state files belong in /tmp

When you need to write a state file whose lifetime equals or is shorter than the current session, cron job, or monitor task — write it under /tmp/, not ~/.claude/ or any other config dir.

Why

The session/cron/task dies or expires; whatever you wrote stays. A file in /tmp self-cleans on reboot and matches the lifetime correctly. A file in ~/.claude/ becomes orphan state cluttering the user's settings dir with no automatic cleanup, and the user has to find and delete it manually.

Examples

  • Cron-loop cursor tracking the last observed run id → /tmp/<feature>-state.json, not ~/.claude/.<feature>-state.json
  • Monitor scratch tracker → /tmp/<task>-progress.json
  • Polling-state file read/written by a recurring task → /tmp/poll-cursor.json

When ~/.claude/ IS right

Only for state that should survive across sessions: durable preferences, memory entries indexed via MEMORY.md, settings that persist beyond the lifetime of any single task. If the file is read by a session-only cron, it's not durable — it goes in /tmp.

amitkot/claude-code-tools/tree/main/code-habits/skills/ephemeral-state-in-tmp commit 7fe397005e

Frequently asked questions

npx skillmds@latest add amitkot/ephemeral-state-in-tmp