Skip to main content

Claude Prompt for AI Coding on Legacy Codebases

Configure AI assistants for legacy code: architecture map, pattern dictionary, characterization tests, dependency mapping, and incremental modernization.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt
Help me configure an AI coding assistant to work effectively with a legacy Java 8 codebase that is 12 years old. The codebase uses manual JDBC queries, JSP views, singleton services, XML configuration and has 12% test coverage. It was originally built by 3 developers and has only outdated Javadoc from 2015. Follow these steps: 1) Create a context document that maps the legacy architecture — identify the entry points, core business logic modules, data access layer, and integration points so the AI understands the system structure despite missing documentation. 2) Design a pattern dictionary prompt that catalogs the recurring code patterns in the codebase (e.g., how errors are handled, how database queries are constructed, how authentication works) and teaches the AI to follow these existing conventions rather than suggesting modern replacements that would be inconsistent. 3) Build a safe modification workflow where the AI first generates characterization tests for any function before suggesting changes, ensuring we capture existing behavior including timezone-dependent date parsing, custom serialization for legacy API clients. 4) Create a dependency mapping prompt that traces how a change in one module ripples through the system, identifying all call sites, database triggers, and scheduled jobs that might be affected. 5) Design incremental modernization prompts that suggest small, safe improvements — one function at a time — that gradually introduce Spring Boot, JPA repositories, structured logging without requiring a full rewrite. 6) Generate a technical debt inventory prompt that scans for TODO comments, suppressed warnings, copy-pasted code blocks, hardcoded credentials and produces a prioritized list with estimated effort and risk for each item. 7) Create a knowledge extraction workflow where the AI reads legacy code and generates explanatory comments, decision records, and architectural notes for the team wiki.

What this prompt does

This prompt configures an AI coding assistant to work safely in a legacy [language] codebase that is [codebase_age] old, uses [legacy_patterns], has [test_coverage] coverage, was built by [original_team_size] developers, and [documentation_status]. It produces a seven-step setup that teaches the AI the system's existing conventions rather than letting it suggest modern replacements that would break consistency.

The structure works because it prioritizes understanding and safety over speed. A context document maps entry points, core logic, the data layer, and integrations so the AI grasps the system despite missing docs. A pattern dictionary catalogs how the codebase already handles errors, queries, and auth, so suggestions match existing style. Before any change, the AI writes characterization tests that capture current behavior including [known_quirks]. A dependency-mapping step traces how a change ripples through call sites and scheduled jobs, incremental prompts introduce [target_patterns] one function at a time, and a debt inventory scans for [debt_indicators] and ranks items by effort and risk.

When to use it

  • You are extending a legacy codebase with thin tests and stale documentation.
  • You want the AI to follow existing conventions, not replace them inconsistently.
  • You need characterization tests before touching behavior with [known_quirks].
  • You want to trace the blast radius of a change before making it.
  • You are modernizing toward [target_patterns] incrementally, without a rewrite.
  • You need a prioritized technical-debt inventory based on [debt_indicators].

Example output

Expect a configuration kit rather than a single document. It includes an architecture context document that maps entry points, core business logic, the data-access layer, and integration points so the AI understands the system despite missing docs. A pattern dictionary teaches the AI the existing conventions for errors, queries, and auth, and a safe-modification workflow writes characterization tests capturing [known_quirks] before any change. From there you get a dependency-mapping prompt that surfaces affected call sites, triggers, and scheduled jobs, incremental modernization prompts that introduce [target_patterns] one function at a time, a prioritized debt inventory built from [debt_indicators] with effort and risk estimates, and a knowledge-extraction workflow that generates explanatory comments and architectural notes for the team wiki.

Pro tips

  • Invest in the pattern dictionary — teaching the AI your existing [legacy_patterns] matters more than letting it propose modern rewrites that fracture consistency.
  • List [known_quirks] explicitly so characterization tests lock in behavior like timezone-dependent parsing before you change anything.
  • Always run the dependency-mapping step before a change in low-coverage code; the call sites it surfaces are where silent breakage hides.
  • Modernize one function at a time toward [target_patterns]; resist the urge to let the AI rewrite a whole module.
  • Tune [debt_indicators] to your real signals (suppressed warnings, hardcoded credentials) so the inventory ranks what actually hurts.
  • Capture the AI's explanatory notes into your wiki as you go; on a [codebase_age]-old system that institutional knowledge is the scarcest resource.

Frequently Asked Questions

Why teach the AI old patterns instead of letting it modernize?
In a legacy codebase, consistency is a safety property. If the assistant swaps in modern idioms ad hoc, it fragments error handling, queries, and auth, making the system harder to reason about. The pattern dictionary keeps suggestions consistent so changes stay predictable and reviewable.
How does it protect against breaking hidden behavior?
Before suggesting any change, the workflow has the AI generate characterization tests that capture the function's current behavior, including documented `[known_quirks]` like timezone-dependent date parsing. With coverage as low as the codebase's real percentage, these tests are the only net that catches regressions.
Can it tell me what a change will affect?
Yes. The dependency-mapping step traces how a change in one module ripples through call sites, database triggers, and scheduled jobs. In a system with thin tests and stale docs, this blast-radius view is what stops a small edit from quietly breaking something downstream.
Does it force a full rewrite to modern patterns?
No. The modernization prompts are deliberately incremental, introducing `[target_patterns]` one small, safe function at a time rather than requiring a rewrite. This lets you improve the codebase gradually while keeping it shippable throughout.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in AI Coding Assistants

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support