How I Reuse Non-Modular Code Across Projects

We all lie about code reuse. We pretend we build generic libraries that slot perfectly into any new project. What actually happens is you open your old project on a second monitor and manually copy the logic. You realise you're just reusing the know-how, but the code base gets duplicated. Then you make improvements in the new repository and you will never backport them. The code inevitably drifts.

The shared package trap

I'm a fan of modular architectures and package registries. They solve real problems but at the cost of abstraction. When you're moving fast across a few related repositories, forcing everything into a shared library just slows you down. You first need to think about architecture for the shared library before you can think about architecture for the actual application that you're going to build.

Reusing code that was never written to be modular has always been a headache. Claude Code changes this dynamic entirely. Instead of building a perfectly decoupled system, you can use AI to bridge the gap between two similar code bases.

I build custom web crawler agents both to identify new venues for Venueful and monitor market changes in Tenderflow. They serve different purposes and are not the exact same code base. But fundamental concepts like queue handling and bypassing agent blocks are identical. When I improve the queue system in one crawler, I need it in the others.

Porting logic with Claude Code

Instead of publishing an internal package, I use a brute-force migration method. You copy the source project into a dedicated folder inside your target project. Then you tell Claude Code to merge the functionality.

Follow these requirements to set it up:

  • Create a temporary reference folder in your target project directory
  • Copy the relevant files from the old project into this folder
  • Run your prompt to extract and adapt the logic

Set it up:

mkdir ./reference_code
cp -r ../old-crawler/src/ ./reference_code/

Now the old logic is sitting right next to your active code base. You don't need to mess with git submodules or local package linking. The files are just there. When you fire up Claude Code, you do not have to explain how the old system worked. Claude Code reads the raw files directly.

You just need to give it strict boundaries. If you ask it vaguely to merge the code, you risk breaking your current architecture. Tell it exactly where to look and what conventions to follow so it adapts to your new environment.

Run the migration with a prompt something like this:

Read the queue handling and anti-bot logic inside the ./reference_code folder.
Implement this exact functionality into my current the current project.
Adapt the code to match the existing types and variable naming conventions in my current project.
Don't import from the reference folder and don't modify it.

Claude Code looks at the messy, tightly coupled logic in the old code base and writes a native implementation for your new project. You get the new features without re-implementing everything from scratch. Delete the temporary folder when the migration is complete.

True code reuse

The software world has chased the dream of frictionless code reuse for decades. It always failed. You either built heavy internal packages that slowed you down or you gave up and duplicated everything manually. Claude Code finally makes code reuse a reality like it's never been before.

You don't need a perfect architecture any more to share logic across your work. You just need a temporary folder and a prompt. Build your features fast, keep iterating on your core logic, and let the AI handle the messy translation layer when your next project actually needs it.

Need help to reuse code?

Egil Fujikawa Nes

I help companies creating a software architecture that work in a AI centric workflow. Based on my experience I can design a solution that fits your actual requirements not a generic approch to software architecture.