Skip to content

fix(tui): delete copy-to-file temp files when the TUI exits - #2692

Merged
cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2648-clean-copy-temp-files
Oct 12, 2026
Merged

cliffhall merged 1 commit into
v2/mainfrom
v2/fix/2648-clean-copy-temp-files

Conversation

@cliffhall

Copy link
Copy Markdown
Member

Closes #2648

Problem

The TUI's OSC 52 fallback (W, #2421) writes the copied value to $TMPDIR/mcp-inspector-copy-XXXXXX/value.txt and never removed it. On the Auth tab that value is the full access token, so tokens accumulated in the temp directory until the OS cleaned it.

Change

  • clients/tui/src/utils/clipboard.ts: writeCopyFile records each directory it creates (before writing, so a failed write still gets cleaned up) and, on first use, registers a single process.on("exit", removeCopyFiles) listener. removeCopyFiles removes them synchronously and best-effort — one failing directory doesn't stop the rest or crash the exit. Every way out of the TUI ends in process.exit (tui.tsx calls it after Ink unmounts), so this covers Esc and Ctrl+C. A kill by an unhandled signal still skips exit listeners; the file stays in its 0700 directory with mode 0600, as before.
  • useCopyKeys: the status line now says the file is temporary — Saved access token to …/value.txt (deleted when the TUI exits) — so the user knows to copy it elsewhere if they want to keep it.
  • clients/tui/README.md: documents the same.

Verification

  • New unit tests cover removing every created directory, registering the exit listener once, cleaning up after a failed write, and continuing when a removal throws. The useCopyKeys test asserts the new status text.
  • Checked against a real process: writeCopyFile followed by process.exit(0) printed the path, and that directory no longer existed afterward.
  • npm run local:gate passed.

No screenshot: the only UI change is the status-line text quoted above.

🤖 Generated with Claude Code

The W fallback writes the copied value (possibly an access token) to
$TMPDIR/mcp-inspector-copy-*/value.txt and never removed it. Track every
directory writeCopyFile creates and remove them synchronously from a
process exit listener; every TUI exit path ends in process.exit. The
status line now says the file is deleted on exit, and the README notes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: cliffhall <[email protected]>
@cliffhall cliffhall added the v2 Issues and PRs for v2 label Oct 12, 2026
@cliffhall cliffhall linked an issue Oct 12, 2026 that may be closed by this pull request
@cliffhall
cliffhall requested a balanced review from Copilot October 12, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The cleanup is correctly scoped, synchronous at exit, resilient to failures, and adequately tested.

0 open findings

What changed in this PR

Ensures sensitive TUI copy-fallback files are removed on process exit and clearly communicates their temporary lifetime.

Changes:

  • Tracks and synchronously removes generated copy directories at exit.
  • Updates status messaging and documentation.
  • Adds cleanup and failure-path tests.
File Description
clients/​tui/​src/​utils/​clipboard.ts Adds best-effort exit cleanup.
clients/​tui/​src/​hooks/​useCopyKeys.ts Clarifies temporary-file status.
clients/​tui/​README.md Documents cleanup behavior.
clients/​tui/​__tests__/​useCopyKeys.test.tsx Verifies updated status text.
clients/​tui/​__tests__/​clipboard.test.ts Tests cleanup and failure handling.

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@cliffhall

Copy link
Copy Markdown
Member Author

Copilot review loop closed: round 1 was clean (0 findings, no inline or suppressed comments), so no further round was requested.

@cliffhall
cliffhall merged commit 5dff990 into v2/main Oct 12, 2026
8 checks passed
@cliffhall
cliffhall deleted the v2/fix/2648-clean-copy-temp-files branch October 12, 2026 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2 Issues and PRs for v2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI copy-to-file fallback leaves its temp files behind

2 participants