Skip to content

Add copy button to chat messages and improve tool usage guidance#2071

Open
gary149 wants to merge 6 commits intohuggingface:mainfrom
gary149:claude/add-copy-button-Spz6z
Open

Add copy button to chat messages and improve tool usage guidance#2071
gary149 wants to merge 6 commits intohuggingface:mainfrom
gary149:claude/add-copy-button-Spz6z

Conversation

@gary149
Copy link
Collaborator

@gary149 gary149 commented Jan 23, 2026

Summary

This PR enhances the chat interface with a copy-to-clipboard feature for messages and refines the AI's tool usage behavior by providing clearer guidance on when to use available tools.

Key Changes

  • Chat Message Copy Button: Added a "Copy" button to chat messages that appears on hover, allowing users to easily copy message content to their clipboard. The button uses the Carbon copy icon and matches the styling of existing message action buttons.

  • Tool Usage Guidance: Updated the tool prompt instructions to:

    • Reword the tool availability message for clarity ("You have access to these tools" instead of "You can use the following tools if helpful")
    • Add explicit guidance to discourage unnecessary tool usage for simple tasks like writing, editing, or knowledge-based questions
    • Encourage direct responses when tools aren't needed

Implementation Details

  • The copy button is conditionally rendered alongside the edit button with the same visibility logic (hidden by default, shown on group/element hover)
  • Uses the native navigator.clipboard.writeText() API for copying
  • Message content is trimmed before copying to remove excess whitespace
  • Tool prompt changes are minimal and focused on improving AI decision-making around tool selection

claude and others added 5 commits January 19, 2026 09:13
Add explicit guidance to the system prompt that instructs the model to:
- Prefer direct answers over tool calls for simple tasks
- Only use tools when genuinely needed
- Stop making additional calls when enough info is gathered
- Categorize tools (generative vs search) with specific usage rules

This addresses the issue where models would make excessive tool calls
for simple requests like spelling checks or prompt edits.
Replace complex categorization logic with a single clear instruction:
"Only use a tool if you cannot answer without it."

This follows Anthropic's recommended approach of using simple, direct
instructions rather than elaborate rule systems.
Adds a copy button to the left of the edit button for user messages.
Both buttons have identical styling.
Match the codebase pattern from CopyToClipBoardBtn that handles
older/insecure browsers with a textarea fallback.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c1d3f08147

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +476 to +478
onclick={() => {
navigator.clipboard.writeText(message.content.trim());
}}

Choose a reason for hiding this comment

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

P2 Badge Guard clipboard access to avoid runtime errors

Clicking the new Copy button always calls navigator.clipboard.writeText(...) without checking for availability or handling rejections. In non-secure contexts (e.g., HTTP), older browsers, or locked-down environments where navigator.clipboard is undefined or access is denied, this throws a runtime error or unhandled promise rejection on click, which breaks the UX for those users. Consider checking for navigator.clipboard and handling failures (e.g., fallback to document.execCommand or a user-facing error).

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants