Skip to content

feat: visible_only mode, toggle command, neo-tree reveal improvements#18

Closed
kam-hak wants to merge 1 commit intoCannon07:mainfrom
kam-hak:main
Closed

feat: visible_only mode, toggle command, neo-tree reveal improvements#18
kam-hak wants to merge 1 commit intoCannon07:mainfrom
kam-hak:main

Conversation

@kam-hak
Copy link
Copy Markdown
Contributor

@kam-hak kam-hak commented Apr 2, 2026

Problem

No control over which files diffs were viewed in. Often, I have a 'focus' set of files (with diffs I want to review in context), alongside non-logic changes (e.g. updating vars to pass context). Every file edit opens a diff tab — even files you've never opened. A 10-file refactor means 10 diff panes. Additionally, neo-tree's reveal() triggers interactive "File not in cwd?" prompts when editing files outside nvim's working directory.

Changes

  • diff.visible_only (false) — only show diff preview for files open in a visible nvim window; auto-approve others silently
  • :ClaudePreviewToggleVisibleOnly — session toggle for visible_only
  • neo_tree.reveal (true) — set to false to disable neo-tree file reveal
  • neo_tree.reveal_root ("cwd") — set to "git" to pass the git root (or file's parent dir as fallback) as neo-tree's dir param, preventing CWD prompts
  • Batched RPC — all config + visibility queries in a single M.hook_context() call instead of 4 separate --remote-expr spawns
  • Close-diff guard — PostToolUse hook only cleans up when a diff is actually open; removed post-close reveal to avoid stale CWD prompts
  • vim.uv.fs_realpath() for canonical path resolution; case-insensitive only on macOS

All defaults match existing upstream behavior — fully backwards compatible.

Example config

require("claude-preview").setup({
  diff = { layout = "inline", visible_only = true },
  neo_tree = { reveal_root = "git" },
})

Test plan

  • Default config (no options set) — behavior unchanged from upstream
  • visible_only: true — edit a file open in nvim → diff shown, approve prompt; edit a file not open → auto-approved, no diff
  • :ClaudePreviewToggleVisibleOnly — flips visible_only for the session, notifies
  • neo_tree.reveal: false — no neo-tree reveal calls, no CWD prompts
  • neo_tree.reveal_root: "git" — reveal works for files outside nvim's cwd; files outside any git repo fall back to parent dir
  • Close-diff hook: no neo-tree reveal or CWD prompt when no diff was shown
  • Linux (case-sensitive fs) — path comparison is exact, no :lower()

- Add diff.visible_only config (default false) — only show diff for
  files open in a visible nvim window; auto-approve others
- Add :ClaudePreviewToggleVisibleOnly command for session toggle
- Add neo_tree.reveal config (default true) — disable to skip reveal
- Add neo_tree.reveal_root config ("cwd"|"git") — pass dir param to
  neo-tree reveal instead of changing nvim's cwd
- Batch all config + visibility queries into single M.hook_context() RPC
- Use vim.uv.fs_realpath() for canonical path resolution
- Guard close-diff hook: only clean up when a diff is actually open
- Remove post-close reveal to avoid stale CWD prompts
@kam-hak kam-hak changed the title feat: visible_only mode, neo_tree.reveal + reveal_root config feat: visible_only mode, toggle command, neo-tree reveal improvements Apr 2, 2026
@Cannon07
Copy link
Copy Markdown
Owner

Cannon07 commented Apr 4, 2026

Thanks for the PR! The config design is well thought out — safe defaults that preserve existing behavior with opt-in flags.

A few things to address before merging:

  1. Fix: Keep "ask" when Neovim is not running
    The current upstream behavior returns "ask" when Neovim isn't available, so the user still gets a CLI review prompt. This PR changes it to "allow" (silent auto-approve).
    This is a breaking change to the default behavior. If Neovim crashes or the socket becomes stale, edits would be silently approved. Please revert this to keep "ask" as the fallback.

  2. Request: Split into smaller PRs
    This PR bundles 3 logically independent changes. Splitting them would make review easier and allow the non-controversial ones to merge quickly:

  • PR A: Close-diff guard (smallest, could merge first)

    • PostToolUse only cleans up when a diff is actually open
    • Defensive bug fix, straightforward to review
  • PR B: Neo-tree reveal improvements

    • neo_tree.reveal config flag to disable reveal entirely
    • neo_tree.reveal_root = "git" for cross-CWD file support
    • reveal(filepath, dir) signature change
  • PR C: visible_only mode

    • diff.visible_only config + :ClaudePreviewToggleVisibleOnly command
    • hook_context() function for batched RPC
    • Auto-approve logic for non-visible files
    • Largest change, most discussion-worthy
  1. Note: OpenCode plugin parity
    Currently only the Claude Code shell scripts are updated. The OpenCode plugin (opencode-plugin/index.ts) also calls reveal() and has the same diff/close lifecycle — it would need corresponding changes for feature parity. This could be a follow-up PR.

Looking forward to the updated PRs!

@kam-hak
Copy link
Copy Markdown
Contributor Author

kam-hak commented Apr 4, 2026

Great. Thanks for the review, and for this addon. Its exactly what I was looking for.


Split into separate PRs per your feedback:

Also fixed the "ask" fallback — see the note in #24 about permissionDecision removal. Closing this one.

@kam-hak kam-hak closed this Apr 4, 2026
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.

2 participants