AI-KB is a command-line tool that generates AI-friendly knowledge bases from your codebase. It scans your project files based on specified patterns and creates markdown files that can be easily consumed by AI models like Claude for context-aware code understanding and assistance.
- Configurable file inclusion and exclusion patterns
- Global ignore patterns for common non-code directories and files
- Explicit include patterns to override global ignores
- Whitespace optimization to reduce file size while preserving context
- Special handling for whitespace-sensitive languages (e.g., Python)
- Environment-based debug logging
You don't need to install AI-KB permanently. You can run it directly using npx:
npx ai-kb@latest
This command will download and execute the latest version of AI-KB.
- Create a
.ai-kb-config
file in your project root with the following format:
[section-name]
src/**/*.js
**/*.tsx
+node_modules/specific-package/**/*.js # Explicitly include specific ignored paths
- src/**/some.js
[another-section]
src/**/*.js
**/*.tsx
- src/**/some.js
Each section can contain:
- Include patterns (normal glob patterns)
- Explicit include patterns (prefixed with +) to override global ignores
- Exclude patterns (prefixed with -)
- Run the tool:
npx ai-kb@latest
Patterns are processed in the following order:
Explicit includes (+ prefix) override global ignores for specific paths Normal includes match files while respecting global ignores Excludes (- prefix) remove files from the final set
For example, to include a specific package from node_modules while keeping the general node_modules ignore:
[section]
+node_modules/important-package/**/*.js # This package will be included
**/*.js # Other .js files (excluding node_modules)
To run the application in debug mode and see additional logging information, use the -v
flag when starting the application:
npx ai-kb -v
This will provide detailed logging information about the file matching process, which can be helpful for troubleshooting or understanding how the tool processes your codebase.
The tool generates markdown files named ai-kb-<section-name>.md
for each section defined in your config file. These files contain the content of the matched source files, optimized for AI consumption.
The tool supports the following command line options:
-v
: Enable verbose debug logging--tree
: Generate a directory tree structure at the beginning of each output file
When using the --tree
option, the generated markdown will include a visual representation of your project's directory structure before the file contents. This can be helpful for:
- Understanding the overall project organization
- Documenting the project structure
- Making it easier to navigate through the codebase
Example tree output:
# Directory Structure
├── src/
│ ├── components/
│ │ ├── Button.js
│ │ └── Input.js
│ ├── utils/
│ │ └── helpers.js
│ └── index.js
├── tests/
│ └── unit/
│ └── helpers.test.js
└── package.json
The tree structure respects the same ignore patterns defined in your .ai-kb-config
file and the global ignore patterns.
The tool uses sensible defaults, but you can customize its behavior:
- Global ignore patterns
- Whitespace-sensitive file extensions
- Whitespace removal rules
For advanced customization, you can fork the repository and modify the source code.
Contributions are welcome! Please feel free to submit a Pull Request to the GitHub repository.
This project is licensed under the MIT License.
If you encounter any issues or have questions, please file an issue on the GitHub repository.
This tool processes your source code locally. No code is sent to external servers. However, the generated markdown files may contain sensitive information from your codebase. Handle these files with appropriate care.