Too smart for simple tasks
Some tasks like: "loop all the files in that folder, read the file, rename vars and funcs to be more readable" caused the agent to try to do a so good job that "exploded" the context, and the ouput was nothing. The agent just tried to rewrite the architecture. Some kind of disambiguation question would help the agent to understand better the intention of the user.
Henry, in my personal experience with LLM, I find it more economical and reliable to have them write a script to perform the complex task, than to do it directly. That way, the LLM doesn't need to ingest all your code in memory bleeding your tokens along the way.
Whenever possible, ask it to create a script to perform the task. This is only good for things that doesn't require code analysis. So not good for integrating new features. Refactoring is best with scripts as in the context you explained.
Tips and Tricks
- Install tree-sitter-cli on the system where you use Claude Code, so it is accessible directly from a Shell. Ask it to create a script that use tree-sitter to create a CTS document of your code in Markdown format (this is the code tree structure and nesting of your components). it contains the functions name and signatures, without the implementation code. It creates the dependency trees as well. You can build a graph of the inter-dependency of your components, and you can use it as a Repomap that you can inject to your prompt when you start a session and give the LLM the full context of your code.
This is a low token size document that give the overview of all your project. The LLM has full context of the structure of your code and where to find what it needs for a task.
Ex.: of script generated by Claude Code: repo-mapper-enhanced.js.txt
-
With the CTS, it becomes easier to ask it to look at the name of your objects and to rename to be more meaningful to the context of each object. It is better also to prepare another prompt document that explain your code convention. Like use 'I' prefix to any interface object name, use camel case (or whatever you want to use). If you don't want to show Claude attribution in the commit, you can ask for it there too, if you build microservices you can tell it to be compliant with 12-factors standards, to follow UX best practices. Just keep it short enough that it doesn't become a 100 lines documents. 20-30 lines concise instruction is best.
-
Because of the memory context limitations I would suggest to consider 1 change/commit = 1 Claude Code session. You exit and you come back and load your init prompts.
-
I'm exploring this design pattern to work with LLM, I create a .llm_context in every strategic locations (the beginning of a logical component) that contain the repomap for this object + change logs + full context of last work dedicated to the component. I ask the LLM to read the .llm_context if I need to work on the module.
-
I also create a collection of LLM personality for different tasks. So most of my code convention are put in those personality, but it also allows me to declutter large standards instructions that would encompass different type of tasks, like Planning, Building, Reviewing, Documenting.
I also use Ollama to help me to create efficient prompts (not wasting my tokens for menial tasks), and improve significantly the output of Claude Code. One of my request was to allow Claude Code to integrate other LLM like Ollama framework in order to streamline such strategy.
This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.