Tabbit
ResourcesBlogModels
Tabbit LogoTabbit

Tabbit — The AI Browser that Works for You

Topics

  • AI Browser Resources
  • Agentic Browser Resources
  • Browser Downloads and Install Guides
  • Browser Comparisons
  • AI Browser Alternatives
  • Browser Productivity Resources

Popular Guides

  • AI Browser
  • Agentic Browser Download
  • Best AI Browser 2026: Top 9 Tested & Ranked
  • AI Browser Download
  • Free AI Browser
  • Best AI Browser 2026
  • AI Browser Comparison 2026
  • AI Browser for Windows
  • AI Browser for Mac
  • Chrome Alternative 2026

Events

  • Tabbit Skill Competition
  • KPOP SBTI Fandom Personality Test
  • Tabbit Campus Creator Program
  • fifi's Picks: AI Skills for Research Papers
  • User Survey

About

  • Tabbit Blog
  • Press & Media
Prompt guide
CommunityClaude Sonnet 4.6

Claude Sonnet 4.6 Enterprise Legacy Code Refactoring and Multi-Step Migration Prompt

Original source

Anthropic Community & Developer Cookbook

AuthorAnthropic Cookbook Contributors

Source date2026-03-12

Tabbit curation2026-08-20

Read original

One-sentence takeaway

Provides a structured XML prompt template that guides Claude Sonnet 4.6 through phased dependency analysis, decoupled refactoring, type completion, and test assurance for high-risk legacy code, preventing large-scale breaking changes.

Use cases

  • Suitable tasks: Incremental migration from JavaScript to TypeScript, refactoring complex monolithic controllers into the Service-Repository pattern, and upgrading legacy ORM/API stacks.

  • Unsuitable tasks: "Black box" full rewrites with no baseline tests or specifications.

  • Applicable model versions: Claude Sonnet 4.6 (claude-sonnet-4-6).

  • Applicable clients, agents, or APIs: Claude API, Cursor, Claude Code, and IDE plugins.

  • Recommended reasoning tier and parameters: Recommended effort=high; set temperature=0.1 for consistent output.

Ready-to-use content

<role>
You are a rigorous system refactoring expert. Your core goal is to modularize and type-enhance legacy code while guaranteeing 100% compatibility with existing business behavior.
</role>

<context>
  <legacy_code>
  {{PASTE_LEGACY_CODE_HERE}}
  </legacy_code>
  <target_architecture_standards>
  - Follow TypeScript 5.x strict mode; `any` is forbidden.
  - Follow the Single Responsibility Principle (SRP); decouple business logic from the data access layer.
  - All external dependencies must use constructor Dependency Injection.
  </target_architecture_standards>
</context>

<workflow_instructions>
You must strictly think and output in the following four phases:

### Phase 1: Reverse contract and boundary analysis
1. List all publicly exposed functions, parameter signatures, and return types of this legacy module.
2. Identify hidden implicit side effects (global variable modifications, uncaught async exceptions, environment dependencies).
3. Map core business logic branches and exception-handling branches.

### Phase 2: Refactoring plan and test baseline design
1. Draft an incremental evolution plan so every step can compile and test independently.
2. Write a unit test case checklist that covers all branches (including edge cases and exception cases).

### Phase 3: Refactored code implementation
1. Output the refactored target module code with thorough JSDoc / type annotations.
2. Place data model definitions, interface abstractions, and concrete implementations in standard module structures separately.

### Phase 4: Self-check and regression assurance checklist
Verify each item below:
- [ ] Are the public contracts of the original API fully preserved?
- [ ] Have all implicit type-conversion risks been eliminated?
- [ ] Have all boundary null cases and network exceptions been handled?
</workflow_instructions>

<output_format>
Organize your output strictly in the following format:
1. Reverse Contract Analysis
2. Test Baseline Design
3. Refactored Source Code (wrap in the appropriate language code block)
4. Migration Risks and Acceptance Checklist
</output_format>

Test/workflow steps

  1. Input preparation: Paste the legacy code to be refactored into the legacy_code tag.

  2. Baseline test confirmation: Before refactoring, require the model to generate character-level compatibility tests based on Phase 1 and Phase 2.

  3. Chunked output: Require the model to output refactored code and run local test commands for verification.

  4. Compile and regression check: Run npm test and npm run typecheck in the terminal and confirm all pass.

Original evidence and data

  • Case test feedback: In migration experiments across 20 different open-source libraries (Express/Koa/NestJS legacy modules), Sonnet 4.6 using this prompt achieved a 94.2% one-shot test pass rate, 31 percentage points higher than unstructured free prompting.

  • Model behavior: Under strict constraints, Sonnet 4.6 shows strong boundary awareness and rarely adds unsolicited feature extensions.

Scope and limitations

  • Modules involving cross-process communication or complex distributed locks still require an architect to manually review the concurrency model.

  • If the original code has serious defects or undefined behavior, the self-check phase in the prompt will mark items as "items pending confirmation," requiring the developer to clarify business expectations.

Source excerpt or observation (short compliant paraphrase only)

Anthropic prompt engineering advice: "Giving Claude clear criteria to verify its work before submitting significantly improves reliability in refactoring tasks." (quoted from the official prompt guide)

Curated by Tabbit

Prompt material is summarized from public sources and Tabbit editorial notes. Check the original licensing and intended use before copying it.

Claude Sonnet 4.6

Use in Tabbit

Claude Sonnet 4.6

Related prompts

MediaClaude Platform Docs / Prompting best practices

Clear Instructions, XML Context, and Self-Checking for Claude Sonnet 4.6

MediaClaude Platform Docs / Effort and Prompting best practices

Claude Sonnet 4.6: Effort and Tool-Triggering Configuration

MediaAnthropic Platform Docs / Computer Use API Reference2026-02-17

Claude Sonnet 4.6: Computer Use Tool Definitions and Automated Closed-Loop Workflow

MediaAnthropic Platform Docs / Context Management & Compaction2026-02-17

Claude Sonnet 4.6: 1M Long Context and Context Compaction Architecture Configuration

Claude Sonnet 4.6

Related reviews

MediaAnthropic News / Introducing Sonnet 4.62026-02-17

Claude Sonnet 4.6 Official Release: Coding, Computer Use, and Agent Benchmarks

MediaBenchLM2026-08-17

BenchLM's Public Evidence Ledger for Claude Sonnet 4.6

MediaIDP Leaderboard

IDP Leaderboard: Sonnet 4.6 Matches Opus 4.6 on Real-World Document Understanding

MediaArtificial Analysis

Artificial Analysis: Sonnet 4.6 Non-Reasoning Intelligence Index 37