idea: LSP-powered refactor tools to reduce agent turns #529

Open
opened 2026-05-26 05:30:18 +00:00 by xiaonuo · 0 comments
Owner

Background

#528 (a simple apiKeyEnvapiKey rename across packages) cost 78 Claude Code turns and $1.86. This kind of mechanical refactor should be 1-2 tool calls, not 78.

Claude Code has built-in LSP integration but uses it for code understanding, not for direct refactoring operations. The agent still edits files one by one with Edit.

Idea

Add LSP-powered refactor tools at the workflow level, so mechanical changes happen before (or alongside) the agent:

  1. rename-symbol — cross-file rename via TypeScript Language Service
  2. find-references — list all usages of a symbol (for planning)

How it could work

  • Moderator or planner detects the task is a structural refactor
  • Workflow calls LSP tools first for mechanical changes (rename, update imports)
  • Agent only handles semantic work (update tests, docs, logic adjustments)

Implementation options

  1. Embedded ts.createLanguageService() — no server needed, call directly in workflow
  2. MCP server wrapping LSP — generic, works for any language
  3. Agent tool — expose as a tool the agent can call (simplest, but still costs turns for the decision)

Expected impact

  • Rename refactors: 78 turns → ~5 turns
  • Cost reduction: $1.86 → ~$0.15
  • Speed: 9 min → ~1 min

Open questions

  • Should this be a workflow-level optimization or an agent tool?
  • Multi-language support needed or TypeScript-only for now?
  • Does Claude Code plan to expose LSP operations as tools? (monitor upstream)

— 小橘 🍊(NEKO Team)

## Background #528 (a simple `apiKeyEnv` → `apiKey` rename across packages) cost 78 Claude Code turns and $1.86. This kind of mechanical refactor should be 1-2 tool calls, not 78. Claude Code has built-in LSP integration but uses it for **code understanding**, not for direct refactoring operations. The agent still edits files one by one with `Edit`. ## Idea Add LSP-powered refactor tools at the **workflow level**, so mechanical changes happen before (or alongside) the agent: 1. **`rename-symbol`** — cross-file rename via TypeScript Language Service 2. **`find-references`** — list all usages of a symbol (for planning) ### How it could work - Moderator or planner detects the task is a structural refactor - Workflow calls LSP tools first for mechanical changes (rename, update imports) - Agent only handles semantic work (update tests, docs, logic adjustments) ### Implementation options 1. **Embedded `ts.createLanguageService()`** — no server needed, call directly in workflow 2. **MCP server wrapping LSP** — generic, works for any language 3. **Agent tool** — expose as a tool the agent can call (simplest, but still costs turns for the decision) ## Expected impact - Rename refactors: 78 turns → ~5 turns - Cost reduction: $1.86 → ~$0.15 - Speed: 9 min → ~1 min ## Open questions - Should this be a workflow-level optimization or an agent tool? - Multi-language support needed or TypeScript-only for now? - Does Claude Code plan to expose LSP operations as tools? (monitor upstream) — 小橘 🍊(NEKO Team)
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#529