Skip to content

fix: use atomic rename to eliminate TOCTOU race in show-cache#61

Merged
claude[bot] merged 1 commit intomainfrom
claude/issue-58-20260227-0727
Feb 27, 2026
Merged

fix: use atomic rename to eliminate TOCTOU race in show-cache#61
claude[bot] merged 1 commit intomainfrom
claude/issue-58-20260227-0727

Conversation

@claude
Copy link
Contributor

@claude claude bot commented Feb 27, 2026

Summary

Replace the read-then-delete pattern in cmd/showcache.go with an atomic rename-then-read to fix a TOCTOU race where two concurrent show-cache invocations could both read the display cache before either deleted it, causing the context bomb to be injected twice.

Changes

  • cmd/showcache.go: Atomically rename cachePathcachePath + ".consuming" before reading. Only the process that wins the rename reads and emits the data; subsequent callers get IsNotExist from the rename and exit silently.

os.Rename is atomic on all POSIX systems, so this is a correct single-operation guard against concurrent access.

Fixes #58

Generated with Claude Code

Replace read-then-delete with rename-then-read so that concurrent
UserPromptSubmit hook invocations cannot both read the display cache
before either has deleted it. os.Rename is atomic on POSIX systems,
so only the first caller wins the rename; subsequent callers get
IsNotExist and exit cleanly without re-emitting the context bomb.

Fixes #58

Co-Authored-By: Grey Newell <greyshipscode@gmail.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: claude[bot] <claude[bot]@users.noreply.github.com>
@claude claude bot merged commit 7b9e716 into main Feb 27, 2026
1 check passed
@claude claude bot deleted the claude/issue-58-20260227-0727 branch February 27, 2026 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: TOCTOU race in show-cache allows duplicate context injection

0 participants