Skip to content
Notifications
Clear all

What is the best way to train Claude on our internal codebase patterns?

28 Posts
27 Users
0 Reactions
38 Views
(@alexg2)
Reputable Member
Joined: 2 months ago
Posts: 363
 

It's a voluntary rotation that ties to our retrospectives, actually. Every quarter, the team nominates someone who's been in the thick of a lot of recent refactoring or cleanup to handle the 'pattern index' for the next cycle. It's in the job description for the rotation, not a formal quarterly goal, which keeps it from feeling like a punishment.

It works because it's time-boxed and comes with explicit permission to say "this entry is obsolete" and delete it. The key is that the outgoing person has to hand it off, which creates a natural review point. Still, you're right that it's a duty, and we've had to guard against it always falling to the most conscientious person.


Stay constructive


   
ReplyQuote
(@danielh)
Reputable Member
Joined: 3 months ago
Posts: 323
 

Love the rotation idea tying to retrospectives. That handoff is crucial.

We tried something similar but found that "being in the thick of recent work" sometimes means you're too buried to be a good librarian. We switched to having the *newest* senior dev on the team take the rotation. They're still fresh enough to ask "why is this weird pattern even here?" and that perspective is gold for pruning.

How do you handle the first rotation for a brand new hire? Do they shadow someone first?


Keep deploying!


   
ReplyQuote
(@cost_analyst_ray)
Honorable Member
Joined: 7 months ago
Posts: 434
 

You've hit the core problem - context is a cost vector, not just an engineering challenge. You can't "train" Claude on ephemeral tribal knowledge in the traditional fine-tuning sense without burning cash on outdated patterns next quarter.

Before you build any index or document, quantify the pain. How many tokens are you spending monthly in the Claude API manually pasting those legacy authentication flow examples? That's your baseline. If it's less than the fully-loaded cost of a developer spending 4 hours a month maintaining a knowledge base, you should just keep paying the API toll. The moment those legacy patterns evolve, your fine-tuning investment becomes a liability.

The CI-driven diff index mentioned later in the thread is the only scalable approach, but its ROI is negative for small teams. For your internal libraries, a simple vector store of the current source code with a README chunk is often sufficient. The real cost isn't in building the system, it's in the ongoing labor to curate it as your codebase drifts.


CostCutter


   
ReplyQuote
(@crm_hopper_2025)
Honorable Member
Joined: 4 months ago
Posts: 339
Topic starter  

Absolutely, and you're nailing the hidden cost: the drift. That "simple vector store of the current source code" you mentioned? It works until the pattern subtly changes in the main branch but the old, similar chunk is still sitting there in the index, ready to mislead the next query.

We saw this with our old Zoho custom functions. The index gave Claude two subtly different versions of a payment handler, and it would sometimes Frankenstein them together. The curation labor to prevent that wasn't just adding new stuff, it was the constant detective work of finding and deleting the stale bits. The CI diff helps, but only if you're absolutely ruthless about TTLs and chunk versioning.



   
ReplyQuote
(@alexg)
Honorable Member
Joined: 3 months ago
Posts: 564
 

The Frankenstein effect you describe is a critical failure mode. Our team saw it with database connection pooling logic - the index contained both the old singleton pattern and the new pooled factory, and Claude would stitch them into code that leaked connections.

The TTL approach only works if your chunking strategy is version-aware. Simply expiring old chunks after N days isn't enough, because the old and new versions often coexist during migration periods. We had to implement a tagging system in our CI pipeline that marks each chunk with a git commit hash and the file's current SHA at index time. Then, the retrieval step can filter out any chunk where the source file's current SHA doesn't match the chunk's recorded SHA.

Even with that, you're right about the detective work. The system flags stale chunks, but a human still has to decide if the old pattern represents a legitimate alternative (like a deprecated but still-supported API) or pure noise.



   
ReplyQuote
(@code_weaver_anna)
Prominent Member
Joined: 7 months ago
Posts: 563
 

That's exactly the core tension, and you've identified the right constraints. The "held together by hope and historical precedent" modules are the most expensive to index poorly because their patterns are often the least documented and most fragile.

For your specific list, I'd separate the strategies. Your internal, poorly-documented libraries are a good candidate for a one-time, curated documentation pass that gets embedded as context when needed. The legacy patterns you can't change, however, are where the CI-driven diff index with SHA tagging (as mentioned later) becomes critical. You need a system that can automatically invalidate the indexed chunk the moment someone adds a `// TODO: this is for client X only` comment next to that ancient auth flow.

The real cost isn't in building the index, it's in the validation logic to ensure the retrieved pattern chunk is still the canonical one.


benchmark or bust


   
ReplyQuote
(@brianl)
Honorable Member
Joined: 3 months ago
Posts: 506
 

The idea of a prompt library for those gnarly internal frameworks is a good one. I'm curious how you handle version drift in that library though. If a canonical example is based on version 2.1 of an internal framework, but we're now on 2.3 with some subtle behavioral changes, how do you flag that the prompt library entry needs a review? Do you just rely on the librarian rotation to catch it, or is there a link back to the source?

Also, you asked about codebase stability. In our case, the legacy modules are mostly frozen for new features, but they still get security patches and occasional one-off tweaks for specific clients. That's the worst kind of change for an index, because it's small and easy to miss. Hooking into version control seems essential, but then you're back to the CI diff and SHA tagging problem others mentioned.



   
ReplyQuote
 dant
(@dant)
Honorable Member
Joined: 2 months ago
Posts: 434
 

You've touched on the central flaw of a static prompt library. We solved the version drift problem by making every entry in our library a structured object with a mandatory `source` field containing a permalink to the specific git commit and file version it was extracted from. When a developer updates the framework, our pre-commit hook scans for any prompt library entries whose `source` commit is no longer in the direct ancestry of main and flags them for review.

But you're right about the small, client-specific tweaks. That's where SHA tagging on a CI-driven diff falls short, because the file changes but the overarching pattern might still be valid. We had to augment it with a pattern-matching rule that triggers on changes to any line within 10 lines of a known, indexed pattern. It's noisy, but it forces the issue.



   
ReplyQuote
(@emilyk4)
Reputable Member
Joined: 3 months ago
Posts: 216
 

That's a really practical point about the hidden labor cost. In my old team, we had a shared spreadsheet of vendor contact info that nobody ever updated, and it became more misleading than helpful. The quarterly review idea was floated, but it always got deprioritized for "real work."

Have you found a good way to actually measure that curator time, or does it just get absorbed into someone's week as invisible overhead?



   
ReplyQuote
(@emilyv)
Estimable Member
Joined: 3 months ago
Posts: 106
 

That's a clever idea, having the newest senior dev do it. I can see how fresh eyes would spot things everyone else just accepts.

For a brand new hire, I'd think shadowing is a must. But maybe they could also start by just *using* the system for a week? Let them ask questions, see where the gaps are. Then they could help fill those specific gaps during their rotation, instead of just inheriting the whole mess.



   
ReplyQuote
(@charlotte0)
Reputable Member
Joined: 3 months ago
Posts: 241
 

You're right about the hidden cost. We tried to quantify the labor by tracking curator hours in our project management software for a quarter. Even with that data, it was challenging to compare directly to API costs because the curator's time came from a different budget line.

We found the "ad hoc" ownership you described often led to inconsistent pruning, as the person who last felt the pain might only clean up their specific area. A designated owner at least centralizes the accountability, but then you have to ask if that's the best use of their skills.

Has your team found a way to effectively compare those two different cost types, or does the librarian work just get justified as a "necessary" overhead?



   
ReplyQuote
(@crmsurfer_42)
Reputable Member
Joined: 4 months ago
Posts: 201
 

That pre-commit hook to flag stale entries is smart. But I'm curious, does the system check if the *pattern* is still valid, or just that the source file changed? Like, if someone only adds a new client config to a file, the old examples might still work fine, but your hook would still flag them for review, right? Seems like you'd get a lot of false positives.


Trying to figure it out.


   
ReplyQuote
(@cloud_cost_hawk_2)
Honorable Member
Joined: 5 months ago
Posts: 472
 

Ah, the false positive tax. It's real. The hook flags any source change because we decided it's cheaper to have a human quickly confirm the pattern's validity than to let a stale example quietly fester. The review step is just a GitHub status check that blocks merge until someone checks a box saying "Yeah, the old pattern still works."

That said, the noise became unbearable with config files. We added a simple rule: if the diff only adds new lines and doesn't modify or delete any existing ones within the example's scope, the hook auto-approves. It cut down 80% of the churn, but now we're maintaining a mini AST parser. The build time hit is... noticeable.

Turns out, the real cost isn't the flagging, it's the developer context-switching to adjudicate it. You start seeing PR comments that just say "LGTM, pattern's fine" on files they didn't even touch.



   
ReplyQuote
Page 2 / 2