Quanta

← Back to Briefings

Pair Programming on Legacy Java with Claude Code

Coding agents at scaleEN231 reads

A legacy Java service rarely explains itself in one file. Business rules hide in utility classes, transaction boundaries, database mappings, and tests that describe yesterday’s requirements. Claude Code can help connect those pieces, but productive pairing starts with a narrow task and evidence. This walkthrough uses an illustrative invoice service where a confirmed business rule requires decimal half-up rounding to two places.

01 · Step 1: Define the invoice rounding change

Start with a small, observable requirement: an invoice total of 10.005 must become 10.01 at the final rounding boundary. Confirm that rule with the service owner before treating it as correct. Currency rules and rounding stages vary, and an apparently obvious fix can change accounting behavior.

Give Claude Code a bounded assignment: Trace how the invoice total is calculated and rounded. Identify the relevant code and tests. Propose a minimal fix, preserving the public API and existing transaction behavior. Wait to edit until the investigation is complete.

02 · Step 2: Establish the Java build baseline

Open a clean working branch and inspect the repository instructions, build files, Java version, and test configuration. Ask Claude Code to identify whether the project uses Maven or Gradle, whether it has a wrapper, and which module owns invoice calculation.

Run the relevant existing tests before editing. In a Maven repository with a wrapper, that might be ./mvnw test, with module selection added for a larger build. Record failures already present. If integration tests need a database or another service, distinguish those requirements from unit tests that run locally.

03 · Step 3: Trace the calculation through its callers

Ask Claude Code to follow the calculation from its entry point to the rounding operation, citing file paths and methods. Have it inspect callers, persistence mappings, and nearby tests. A method named calculateTotal may return an intermediate value that another layer rounds later.

Request an explanation of the current behavior for the example input. Watch for conversion through double, premature rounding of line items, or a rounding mode that conflicts with the confirmed rule. Treat the explanation as a hypothesis until the code and a runnable test support it.

04 · Step 4: Write a regression test that exposes the defect

Have Claude Code add a test using the project’s existing test framework and conventions. Construct decimal inputs from strings where appropriate so the test represents the intended decimal value. Run it against the unchanged implementation and confirm that it fails for the expected reason.

Keep the assertion tied to the service contract. BigDecimal equality includes scale, so decide whether the contract requires exactly two decimal places or only numerical equivalence. Include nearby cases that distinguish the intended rounding rule, especially negative amounts if the service supports credits.

05 · Step 5: Make and inspect the smallest correct patch

Now authorize the implementation. Ask Claude Code to change the rounding boundary established during investigation and avoid unrelated cleanup. Preserve intermediate precision where the business rule requires it. Do not accept a repository-wide replacement of rounding operations without examining their separate purposes.

Review the diff together. Ask why each changed line is necessary and whether the patch affects serialized values, persisted amounts, or callers. Run the regression test, the affected module’s tests, and the repository’s required checks. Expand testing when the dependency path or failures justify it.

06 · Step 6: Keep repeated pairing sessions economical

Repository exploration and repeated test-driven edits can generate substantial API usage. Quanta fits teams that want pay-as-you-go access through one balance across supported models and tools, including Claude Code, Codex, and Gemini CLI. Claude Sonnet 5.5 is one model option to consider for this workflow.

Open a Quanta account, then follow its current Claude Code setup instructions for authentication and routing. Quanta’s API base address is https://api.quantarelay.com; use the documented configuration for your client. Every call is metered on real tokens, with cache writes and cache reads priced separately. Keep requests focused and check usage as sessions grow.

07 · Step 7: Leave a reviewable explanation of the fix

Ask Claude Code to draft a change description covering the incorrect rounding behavior, the corrected example, and the checks actually completed. Verify that description against the diff and test output. A reviewer should be able to understand the business rule, reproduce the regression, and assess the patch without reading your pairing conversation.