Skip to content

bug: uncompact run never writes display cache — show-cache UserPromptSubmit hook is always a no-op for install users #42

@claude

Description

@claude

When hooks are installed via uncompact install, two hooks are registered:

  • Stopuncompact run (outputs context bomb to stdout)
  • UserPromptSubmituncompact show-cache (reads ${TMPDIR}/uncompact-display-{uid}.txt)

However, cmd/run.go only writes to stdout — it never writes to the display cache temp file. That file is exclusively populated by scripts/uncompact-hook.sh (the Claude plugin approach).

The result: every user of uncompact install has a permanently no-op UserPromptSubmit hook. The temp file never exists, so show-cache exits silently on every prompt. The hook wastes the slot and makes debugging confusing.

Root Cause

scripts/uncompact-hook.sh captures uncompact run output and writes it to the display cache atomically (mktemp + mv). The Go run command was never updated to do the same.

Fix

At the end of runHandler in cmd/run.go, after fmt.Print(output) (line 181), write output to the display cache file using the same UID-based path and a secure atomic write (CreateTemp + Rename):

func writeDisplayCache(content string) error {
    uid := os.Getuid()
    var id string
    if uid == -1 {
        if u, err := user.Current(); err == nil {
            id = u.Username
        } else {
            id = "windows"
        }
    } else {
        id = fmt.Sprintf("%d", uid)
    }
    cachePath := filepath.Join(os.TempDir(), fmt.Sprintf("uncompact-display-%s.txt", id))
    tmp, err := os.CreateTemp(filepath.Dir(cachePath), "uncompact-display-*.tmp")
    if err != nil {
        return err
    }
    if _, err := tmp.WriteString(content); err != nil {
        tmp.Close()
        os.Remove(tmp.Name())
        return err
    }
    tmp.Close()
    return os.Rename(tmp.Name(), cachePath)
}

The UID/path logic is already present in cmd/showcache.go and should be extracted into a shared helper to avoid drift.

Files

  • cmd/run.go line 181 — add display cache write after stdout emit
  • cmd/showcache.go — extract cache path helper shared with run.go

@claude please implement this

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions