claudecode.nvim icon indicating copy to clipboard operation
claudecode.nvim copied to clipboard

[FEATURE] terminal context sharing

Open cperalt opened this issue 8 months ago • 1 comments

Feature Description

Add a way to send terminal output as context to the Claude Code session, similar to how Cursor IDE surfaces terminal output as attachable context in a prompt.

Use Case

A common workflow: run tests or a build in a terminal pane, see an error, then want Claude to help fix it. Today the only option is to manually copy the output and paste it into the Claude session — bypassing the structured file-reference context that ClaudeCodeAdd provides.

A command like ClaudeCodeAddTerminal that accepts a file path would let any terminal emulator (tmux, wezterm, kitty splits, etc.) pipe captured output directly into Claude's context using the same IPC mechanism already used by ClaudeCodeAdd. This would bring parity with Cursor's terminal context feature for Neovim users.

Proposed Solution

Expose a command that reads terminal content from a file:

:ClaudeCodeAddTerminal /path/to/captured-output.txt

The capture mechanism (how content gets into that file) is left to the user's tooling, keeping the plugin terminal-agnostic. Users on tmux, wezterm, or any other terminal can each wire up their own capture script.

Alternatives Considered

Using ClaudeCodeAdd with a temp file — this is the current workaround (see below). It works but relies on an implicit convention of writing to a temp file rather than a dedicated command with clear semantics.

Full tmux integration in the plugin — the plugin could natively integrate with tmux capture-pane, but this would make it tmux-specific and exclude users on other terminal emulators.

Additional Context

Workaround (tmux-specific): a tmux copy-mode binding that pipes the visual selection through a script, which writes it to a temp file and triggers ClaudeCodeAdd in the Neovim pane.

tmux-claude-add.sh:

#!/bin/bash
cat > /tmp/tmux-claude-context.txt

NVIM_PANE=$(tmux list-panes -F '#{pane_index}:#{pane_current_command}' | grep -i nvim | cut
 -d: -f1 | head -1)
if [ -n "$NVIM_PANE" ]; then
  tmux send-keys -t "$NVIM_PANE" ":ClaudeCodeAdd /tmp/tmux-claude-context.txt" Enter
fi

tmux.conf:
bind-key -T copy-mode-vi 'A' send -X copy-pipe-and-cancel
"~/.dotfiles/scripts/tmux-claude-add.sh"

Select any text in a terminal pane with tmux copy mode, press A, and it lands in Claude's context immediately. Works well but requires each user to implement the capture and wiring themselves. A dedicated ClaudeCodeAddTerminal command would make this pattern accessible without terminal-specific scripting.

cperalt avatar Mar 27 '26 07:03 cperalt

A dedicated command makes sense if it also gives terminal-context provenance a stable shape instead of just reusing the generic file path path.

The metadata I would want on the receiving side:

  • source terminal/session label, if known
  • capture range or output cursor
  • content hash of the captured file
  • cwd at capture time
  • whether Claude accepted the context item before the user prompt was sent

That gives users a way to tell file was created apart from Claude got the intended terminal context.

Adjacent pattern: Faryo's handoff path treats notes/files as a handoff package and injects a reference back into the same live tmux-backed session. The public redacted GIF shows both text handoff and attachment handoff landing in the active session; not the same Neovim plugin use case, but the receipt shape is similar: https://github.com/Snailflyer/faryo/releases/download/v1.0.7/faryo-public-redacted-same-session-handoff-walkthrough-20260528-0120.gif

Snailflyer avatar May 28 '26 01:05 Snailflyer

Thanks for the detailed writeup and working tmux snippet. That makes the intent clear.

If I understand you correctly, your goal is to use :ClaudeCodeAddTerminal <file> to pipe terminal output into Claude's context, keeping the capture process terminal-agnostic for clarity.

Expose a command that reads terminal content from a file:

:ClaudeCodeAddTerminal /path/to/captured-output.txt

The capture mechanism (how content gets into that file) is left to the user's tooling, keeping the plugin terminal-agnostic. Users on tmux, wezterm, or any other terminal can each wire up their own capture script.

Currently, :ClaudeCodeAdd <file> sends an at_mentioned notification with the file path, and Claude then reads that file from disk. Thus, using :ClaudeCodeAdd /tmp/captured.txt works exactly like :ClaudeCodeAddTerminal /tmp/captured.txt, as your tmux script already demonstrates.

If you want clearer naming, you can define your own

command:vim.api.nvim_create_user_command("ClaudeCodeAddTerminal", function(opts)
  require("claudecode").send_at_mention(vim.fn.expand(opts.args), nil, nil, "ClaudeCodeAddTerminal")
end, { nargs = 1, complete = "file", desc = "Send captured terminal output to Claude" })

Call :ClaudeCodeAddTerminal /tmp/tmux-claude-context.txt in your tmux binding for your workflow. Optionally, extend it to capture the current Neovim terminal output when no path is given.

Does the current :ClaudeCodeAdd workflow (or the new command example) cover your needs, or is something missing for your workflow? Would a documented "terminal context" example in the README simplify discoverability for you?


The metadata I would want on the receiving side:

  • source terminal/session label, if known
  • capture range or output cursor
  • content hash of the captured file
  • cwd at capture time
  • whether Claude accepted the context item before the user prompt was sent

That makes sense, but some might not agree with all of these or want more or less information. I'm trying to understand where the added benefit lies in having this in-tree vs. a custom config + docs.

ThomasK33 avatar Jun 03 '26 13:06 ThomasK33