claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

Feature Request: Roslyn Integration for 99% Token Reduction in Refactoring

Open b-straub opened this issue 6 months ago • 2 comments

Feature Request: IDE-Native Roslyn Refactoring Integration for Claude Code

Executive Summary

Integrate Microsoft Roslyn refactoring APIs directly into Claude Code and the Rider plugin to achieve 99.5% token reduction and professional-grade refactoring accuracy.

Current Problem

  • Inefficient Token Usage: Simple refactoring operations (e.g., renaming a property) consume 5,000-8,000 tokens due to manual file reading, searching, and editing
  • Error-Prone Manual Approach: Search-and-replace operations miss edge cases, break references, and can cause compilation errors
  • Poor User Experience: Multiple roundtrips for operations that IDEs handle in milliseconds
  • Accuracy Issues: Manual refactoring cannot match the semantic analysis of compiler-grade tools

Proposed Solution: Roslyn-Powered Refactoring

Core Implementation

Replace manual file manipulation with direct integration to Microsoft.CodeAnalysis.Workspaces APIs:

// Instead of: Read files → Search → Edit → Verify (5,000+ tokens)
// Use: Direct Roslyn refactoring (25 tokens)

var result = await Renamer.RenameSymbolAsync(
    solution, symbol, newName, options, cancellationToken);

Command Interface

{
  "action": "refactor_rename",
  "symbol_location": "Models/UserModel.cs:42:18",
  "new_name": "EmailAddress",
  "scope": "solution"
}

Expected Response

✅ Renamed UserEmail to EmailAddress in 23 locations across 12 files

Measurable Benefits

Token Efficiency

  • Current: 5,000-8,000 tokens per refactoring operation
  • Proposed: 25 tokens per operation
  • Savings: 99.5% token reduction

Performance Improvement

  • Speed: 80%+ faster than current manual approach
  • Accuracy: 99%+ success rate using battle-tested Roslyn engine
  • Reliability: Zero compilation errors from incomplete refactoring

Supported Operations

  1. Symbol Renaming (properties, methods, classes, variables)
  2. Method Signature Changes (parameters, return types, access modifiers)
  3. Type Refactoring (interface extraction, inheritance changes)
  4. Code Generation (constructors, property generation, interface implementation)

Technical Architecture

Rider Plugin Integration

  • Leverage existing Microsoft.CodeAnalysis.Workspaces APIs
  • Integrate with Rider's solution workspace
  • Provide progress feedback and error handling
  • Support background operations with cancellation

Claude Code Enhancement

  • Add refactoring command protocol
  • Implement semantic symbol resolution
  • Support cross-project and cross-solution operations
  • Maintain compatibility with existing workflows

Implementation Roadmap

Phase 1: Core Renaming (4 weeks)

  • Basic symbol renaming across solution
  • Property, method, and class support
  • Conflict detection and resolution

Phase 2: Advanced Refactoring (8 weeks)

  • Method signature changes
  • Interface extraction
  • Code generation operations

Phase 3: AI Integration (4 weeks)

  • Command protocol optimization
  • Intelligent operation suggestions
  • Batch refactoring capabilities

Business Impact

Cost Reduction

  • Token Costs: 99.5% reduction in refactoring-related token usage
  • Development Time: Significant reduction in AI-assisted refactoring time
  • Error Costs: Elimination of manual refactoring errors

Competitive Advantage

  • Professional Integration: True IDE-native capabilities vs. workaround approaches
  • Developer Trust: Reliable, accurate refactoring operations
  • Market Position: Leading AI development assistant with compiler-grade accuracy

Technical Requirements

Dependencies

  • Microsoft.CodeAnalysis.Workspaces.Common
  • Microsoft.CodeAnalysis.CSharp.Workspaces
  • Microsoft.CodeAnalysis.Features

Platform Support

  • Primary: JetBrains Rider plugin
  • Future: Visual Studio, VS Code extensions

Success Metrics

Quantitative

  • 90%+ reduction in tokens used for refactoring operations
  • 80%+ improvement in refactoring operation speed
  • 99%+ accuracy rate for refactoring operations
  • Support for 15+ common refactoring patterns

Qualitative

  • Developer satisfaction with refactoring reliability
  • Reduced support requests for refactoring issues
  • Increased adoption of Claude Code for complex refactoring tasks

Conclusion

This enhancement would transform Claude Code from an AI assistant that works "around" IDEs to one that truly leverages the power of modern development tools. The token savings alone justify the development investment, while the accuracy and performance improvements would establish Claude Code as the definitive AI development assistant.

The technology exists, the APIs are mature, and the benefits are measurable. This represents a clear opportunity to leapfrog competitors by providing truly professional-grade development assistance.


Research Document: Complete technical specification with prototype implementation plan available upon request.

Contact: This feature request is based on comprehensive research into Roslyn APIs and IDE integration patterns.

b-straub avatar Jun 19 '25 23:06 b-straub

We can kinda (explanation later) add support for this using MCP - I've done it.

The issue with adding MCP, is that Claude does not use it to rename symbols, find symbols/references etc. Even when I explicity add to CLAUDE.md, it falls back to using grep, search tools. Sometimes it uses the MCP, sometimes it does not.


OmniSharp + MCP Language Server

This guide walks you through installing and configuring OmniSharp (C# LSP) with the mcp-language-server proxy so you can use C# language features in Claude Code on Linux.

Prerequisites

  • A Linux environment (Ubuntu 22.04 or similar) with a user account.
  • Internet access to download Go, OmniSharp, and MCP tools.
  • A C# project or solution you wish to enable (.csproj/.sln).
  • Existing .NET SDK (≥ 6.0). .NET 8 is fully compatible.

1. Install Go 1.24.4

Download and extract Go into /usr/local:

wget https://go.dev/dl/go1.24.4.linux-amd64.tar.gz -O ~/go1.24.4.linux-amd64.tar.gz
sudo rm -rf /usr/local/go \
  && sudo tar -C /usr/local -xzf ~/go1.24.4.linux-amd64.tar.gz

2. Configure Go in your PATH

Append Go’s bin directories to your shell profile and reload:

echo 'export PATH=$PATH:/usr/local/go/bin:$(go env GOPATH)/bin' >> ~/.bashrc
source ~/.bashrc

Verify:

go version       # should show go1.24.4
which mcp-language-server || echo "Next: install mcp-language-server"

3. Install the MCP proxy

Fetch and install mcp-language-server into your Go workspace:

go install github.com/isaacphi/mcp-language-server@latest

Verify it’s on your PATH:

which mcp-language-server  # e.g. /home/you/go/bin/mcp-language-server

4. Confirm .NET SDK

Ensure you have a compatible .NET SDK (≥ 6.0). If you already see something like:

dotnet --version  # e.g. 8.0.116

you can skip installing older SDKs.

5. Download OmniSharp Roslyn (net6.0 build)

Get the latest Linux x64 archive from GitHub releases:

wget https://github.com/OmniSharp/omnisharp-roslyn/releases/latest/download/omnisharp-linux-x64-net6.0.zip \
  -O ~/omnisharp-linux-x64-net6.0.zip

6. Extract OmniSharp

Create a directory and unpack:

mkdir -p ~/omnisharp
unzip ~/omnisharp-linux-x64-net6.0.zip -d ~/omnisharp

You should now have ~/omnisharp/OmniSharp.dll and support files.

7. Verify OmniSharp LSP Mode

Test that OmniSharp listens on stdio (no visible logs unless verbose):

dotnet ~/omnisharp/OmniSharp.dll -lsp

– Omitting additional output is normal (server awaits LSP initialize). – Press Ctrl+C to exit.

8. Launch MCP Language Server Proxy

Start the proxy to wrap OmniSharp for your project:

mcp-language-server \
  --workspace /path/to/your/csharp/project \
  --lsp dotnet ~/omnisharp/OmniSharp.dll -lsp

If you see log registrations and diagnostics, it works. You can stop it with Ctrl+C.

9. Register the MCP Server in Claude Code

From any terminal, add a local-scoped MCP server named csharp:

claude mcp add csharp /home/you/go/bin/mcp-language-server \
  --workspace /path/to/your/csharp/project \
  --lsp dotnet ~/omnisharp/OmniSharp.dll -lsp

Alternatively, add via JSON:

claude mcp add-json csharp '{
  "type":"stdio",
  "command":"/home/you/go/bin/mcp-language-server",
  "args":[
    "--workspace","/path/to/your/csharp/project",
    "--lsp","dotnet","~/omnisharp/OmniSharp.dll","-lsp"
  ],
  "env":{}
}'

10. Testing & Troubleshooting

  1. List configured servers

    claude mcp list
    
  2. Request a definition In Claude Code REPL:

    /mcp view definition in Program.cs offset 123
    

JobaDiniz avatar Jun 27 '25 19:06 JobaDiniz

This approach might work, when you’re using OmniSharp as C# LSP, like VS Code before the C# DEV kit introduction. I tried Roslynator together with Claude, but refactoring a mid sized solution was unbelievably slow. An IDE provider like Jetbrains should provide a MCP that interacts with the IDE directly. Not sure if this not already exists, but didn’t investigate further. The reason is that Roslyn already has the entire solution and syntax tree in memory and can use the Roslyn build in refactoring support. Here I found something but didn’t investigate further:

https://github.com/JetBrains/mcp-jetbrains

b-straub avatar Jun 27 '25 20:06 b-straub

So I use claude Code with SerenaMCP, and editing by symbol and searching by symbol work great. The problem is the way that you get them to use the tools, is that serenaMCP dumps a huge prompt into claude, which is a bit of a waste of tokens. So definitely something you want to avoid unless you are actually going to make edits. But yes, I've had a ton of luck using the LSPs that serena integrated for python and C#. Rosalyn, and... I can't rembemr the pyhton one.

Coldaine avatar Jul 22 '25 05:07 Coldaine

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 04 '25 10:12 github-actions[bot]