
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
code2prompt
Advanced tools
NodeJS Class for transforming a given codebase directory into an LLM prompt
Generate LLM prompts from your codebase easily with code2prompt, a Node.js package designed to help you create structured documentation or coding challenge prompts directly from your project's source code.
Install code2prompt using npm:
npm install code2prompt
Or using yarn:
yarn add code2prompt
Here's a simple example on how to use code2prompt to generate a prompt from your codebase:
const Code2Prompt = require('code2prompt');
!async function(){
const options = {
path: "/path/to/your/codebase",
extensions: ["js", "ts"], // Specify the extensions to filter for
//template: 'templates/default.hbs',
template: 'templates/write-readme.hbs',
ignore: ["**/node_modules/**"], // Specify patterns to ignore
OPENAI_KEY: 'YOUR_OPENAI API KEY', // (optional) needed for 'request'
ANTHROPIC_KEY: 'YOUR_ANTHROPIC API KEY', // (optional) needed for 'request'
GROQ_KEY: 'YOUR_GROQ API KEY', // (optional) needed for 'request'
};
const code2Prompt = new Code2Prompt(options);
const prompt = await code2Prompt.generateContextPrompt();
console.log(prompt);
// make request to LLM API
setModelPreferences(["OPENAI", "ANTHROPIC", "GROQ"]); // define priority order for requests
const generateReadme = await code2Prompt.request("Generate a readme file from the given codebase",z.object({
readme: z.string().describe('The generated contents of the readme file'),
}));
// generatedReadme = { data: { readme: 'Generated readme.md content' }, usage:{ totalTokens, promptTokens, completionTokens } }
console.log('Generated readme.md',generateReadme.data.readme);
// some templates (like write-readme) contain a 'schema' md code block with the return schema for the prompt, so you can call it as is and it'll work
const generateReadme2 = await code2Prompt.request();
}();
code2prompt uses Handlebars templates to format the output. You can specify a custom template path in the options to use your own Handlebars template. Here's a basic template example:
Project Path: {{absolute_code_path}}
Source Tree:
{{source_tree}}
{{#each files}}
{{#if code}}
`{{path}}`:
{{code}}
{{/if}}
{{/each}}
Contributions to code2prompt are welcome! Please feel free to submit issues, pull requests, or suggest features.
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
NodeJS Class for transforming a given codebase directory into an LLM prompt
The npm package code2prompt receives a total of 13 weekly downloads. As such, code2prompt popularity was classified as not popular.
We found that code2prompt demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.