
Research
2025 Report: Destructive Malware in Open Source Packages
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.
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
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.

Research
Destructive malware is rising across open source registries, using delays and kill switches to wipe code, break builds, and disrupt CI/CD.

Security News
Socket CTO Ahmad Nassri shares practical AI coding techniques, tools, and team workflows, plus what still feels noisy and why shipping remains human-led.

Research
/Security News
A five-month operation turned 27 npm packages into durable hosting for browser-run lures that mimic document-sharing portals and Microsoft sign-in, targeting 25 organizations across manufacturing, industrial automation, plastics, and healthcare for credential theft.