gfroy.com

Keeping Claude Code on track

TL;DR

When Claude does something weird, ask where it got it from: usually from your own code. When it misbehaves, tell it why, so it remembers. Where you can, enforce the rule with a tool, so it can’t break it. Keep conversations short.

How it works

Claude decides how to write code in your project from three things:

Keeping Claude on track means keeping those three clean.

My take

Gotchas

Example

You: Why did you use field injection with @Autowired here? Where did you get that from?

Claude: I followed OrderService and InvoiceService, which both inject their dependencies that way.

Fix those two classes (or let Claude do it), then: “Use constructor injection, because it makes dependencies explicit and the class testable without Spring. Remember that.”

Claude saves that as a memory, and every later conversation in this project follows it. How Claude Code remembers shows what that looks like.

Better still, make it fail the build, with an ArchUnit test:

@AnalyzeClasses(packages = "com.example")
class CodingRulesTest {

    @ArchTest
    static final ArchRule noFieldInjection = GeneralCodingRules.NO_CLASSES_SHOULD_USE_FIELD_INJECTION;
}

Now field injection can’t come back, from Claude or from a colleague.