Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Code2prompt – Generate LLM prompts from your codebase (github.com/mufeedvh)
4 points by mufeedvh on March 11, 2024 | hide | past | favorite | 7 comments
I made code2prompt, a CLI tool to generate LLM prompts from your codebase with support for prompt templating and token counting.

I initially wrote this for personal use to utilize Claude 3.0's 200K context window and it has proven to be pretty useful so I decided to open-source it. Let me know what you think.




I don't get it; what is this for? What is the use case?


For small codebases, you can run this tool on the entire directory and it would generate a well-formatted Markdown prompt detailing the source tree structure, and all the code. You can then upload this document to either GPT or Claude models with higher context windows and ask it to:

- Rewrite the code to another language.

- Find bugs/security vulnerabilities.

- Document the code.

- Implement new features.

You can customize the prompt template to achieve any of the desired use cases. It essentially traverses a codebase and creates a prompt with all source files combined. In short, it automates copy-pasting multiple source files into your prompt and formatting them along with letting you know how many tokens your code consumes.


This would be good to have in the README.md, I've submitted a PR with your comment here: https://github.com/mufeedvh/code2prompt/pull/1 :)

I could see this tool being useful for a few of my use cases, thank you.


Merged, thank you! :)


What do you mean my small codebase. I hope not the normal todo repos or basic apps. Can this be run on production codebase like a java application having dozens of microservices inside it.


Yes, this just depends on the model you're using. Small-medium size codebases would fit inside Claude's 200K context window and Gemini 1.5 has a 1M context window which would essentially fit 99% of codebases.

For reference:

- The Flask web framework for Python: 131880 tokens

- The Spring Framework for Java: 11070559 tokens


Ah, now I get it, thanks, makes sense.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: