LLMAP advanced context generation for AI coding

I use the open source and very capable Aider for AI code generation. Anyone who has tried AI code generation has heard of “context” – the information you send over to the LLM so that it can know what the code looks like that you want to modify.

Anyone using these tools eventually comes up against the dreaded token limit at some point – some sooner rather than later! The LLM can only keep so much context in memory at one time. This is annoying if you are trying to update a legacy codebase with multiple files and countless lines of code – who wants to try to pare this down to only the relevant parts, copy and paste into the window?

In Aider adding files to context is as simple as /add file.txt
To remove files just do /drop file.txt
If file.txt is 100 000 lines long you have to copy and paste the parts you want (up to 60 000 tokens), check how many you have left by running /tokens
But that is takes too long! It defeats the purpose of getting AI to do the reading and modifying for you (remember to review the diffs after!)

Meet LLMAP

llmap is “context extraction at scale”. The tool can search and sumarise vast amounts of code and ouput only the relevant parts which you can then add to your AI coding tool context – leaving out all irrelevant parts (usually most of it!)
Example from my own use case: I had an issue with a looping api request on ESP32 in my Magic Poi project – I had been concentrating on the battery monitor feature and the new feature broke some other functionality. So I did a diff with the last known working branch:
git diff origin/Battery_Monitor_Main_Merge > context_git_diff.txt

This diff is from way back though so it was too large for the context window (if you include all of the code I wanted to update) so I had to run it through llmap with a query:
echo context_git_diff.txt | llmap "list the changes made that affect the control flow of the application." > llmap_diff_context.txt

Now my new file llmap_diff_context.txt with only the relevant information could be added to the context – using /read-only since it’s not included in git nor do I want to edit it. I used /architect mode* to see what changes happened to cause the loop. Turns out it was a simple misplaced line of code and everything worked again!
*for me architect mode is configured to use DeepSeek R1 for thinking and V3 for editing – cheap and effective

LLMAP is easy to use – just install via pip. By the way, if you don’t have a DeepSeek api key, the update I recently submitted to add OpenRouter support has been merged but not yet published. You will have to download and install llmap manually to use OpenRouter – but it works.

Full credit to Johnathan Ellis for creating and sharing this great tool. You gotta love Open Source!

Leave a Reply

Your email address will not be published. Required fields are marked *