Copy for AI
A Rails gem that adds a "Copy for AI" button to development error pages, allowing you to copy error details in formats optimized for AI agent consumption.
Features
- Adds a styled button to Rails development error pages
- Multiple output formats: TOON (default), Markdown, or Plaintext
- Extracts comprehensive error information:
- Error type and message
- Source code with file and line number
- Application stack trace
- Full stack trace
- Available routes (for routing errors)
- Format preference saved in localStorage
- Zero configuration required
- Only active in development environment
Installation
Add this line to your application's Gemfile:
group :development do
gem 'copy_for_ai'
end
And then execute:
bundle install
That's it! The gem automatically hooks into Rails and adds the button to error pages.
Usage
- When your Rails app encounters an error in development, you'll see the standard Rails error page
- Look for the "Copy for AI" button next to the trace toggle links
- Select your preferred format from the dropdown (TOON, MD, or TXT)
- Click the button to copy all error details to your clipboard
- Paste into your AI assistant of choice
Output Formats
TOON (Default)
TOON (Token-Oriented Object Notation) is a compact, human-readable format designed for LLM prompts. It reduces token usage while remaining easy to parse.
error_type: Routing Error
error_message: "No route matches [GET] \\"/asdf\\""
rails_root: /Users/dev/myapp
application_trace:
app/controllers/users_controller.rb:15:in `show'
full_trace:
app/controllers/users_controller.rb:15:in `show'
actionpack (7.0.0) lib/action_controller/metal/basic_implicit_render.rb:6
Markdown
Rich formatting with headers and code blocks:
# Rails Error: Routing Error
## Error Message
No route matches [GET] "/asdf"
**Rails.root:** `/Users/dev/myapp`
## Application Trace
\`\`\`
app/controllers/users_controller.rb:15:in `show'
\`\`\`
Plaintext
Simple text format for maximum compatibility:
RAILS ERROR: Routing Error
==================================================
ERROR MESSAGE:
No route matches [GET] "/asdf"
RAILS ROOT: /Users/dev/myapp
APPLICATION TRACE:
------------------------------
app/controllers/users_controller.rb:15:in `show'
Why TOON?
TOON format offers significant token savings compared to Markdown while remaining human-readable and easy for LLMs to parse. This means:
- Lower API costs when using paid LLM APIs
- More context can fit in the same token window
- Faster responses due to reduced input size
Learn more at toonformat.dev.
Requirements
- Ruby >= 2.7.0
- Rails 7.0+ or Rails 8.0+
Tested with:
- Rails 7.0, 7.1, 7.2
- Rails 8.0
Development
After checking out the repo, run bundle install to install dependencies.
Run the test suite:
bundle exec rspec
To install this gem onto your local machine, run:
bundle exec rake install
Contributing
Bug reports and pull requests are welcome on GitHub.
License
The gem is available as open source under the terms of the MIT License.