Craft-C — C Code Improvement Coach
Don't just write code. Craft better code.
Craft-C is a Visual Studio Code extension designed to help C programmers write cleaner, simpler, safer, and more readable code. It analyzes your C programs and provides improvement suggestions one at a time, helping you understand not only what to change, but also why the change matters.
Rather than automatically rewriting your entire program, Craft-C puts you in control of your learning process.
✨ Features
- Smart Code Analysis: Identify potential improvements in your C programs.
- One-by-One Suggestions: Review individual findings at your own pace.
- Before & After Comparison: Understand how a proposed change affects your code.
- Educational Explanations: Learn the reasoning behind each recommendation.
- Simplification: Discover opportunities to reduce unnecessary repetition and complexity.
- Code Quality: Improve readability, maintainability, and coding practices.
- Bug Awareness: Identify recognizable patterns that may indicate programming errors.
- Safe Fixes: Apply supported changes only after reviewing them.
- Interactive Interface: Navigate, skip, review, and apply suggestions.
- Session Summary: Track findings reviewed, fixes applied, and suggestions skipped.
🚀 Getting Started
Prerequisites
- Visual Studio Code
- Basic knowledge of C programming
- Node.js and npm if you need to install development dependencies or run packaging tools
A C compiler is not required for the extension's basic source-analysis features. Compilation and runtime testing are separate activities.
Installation for Development
- Clone or download the Craft-C project.
- Open the project folder in VS Code.
- Ensure that
package.json and extension.js are present.
- Install any development dependencies specified by the project.
- Press
F5 to launch the Extension Development Host.
- Open a C source file in the new VS Code window.
- Open the Command Palette using
Ctrl + Shift + P.
- Search for Craft-C: Analyze & Improve My Code.
- Run the command to start your analysis session.
Note: These instructions assume the extension manifest and commands have been implemented as specified in the project.
🧠 How It Works
- Analyze: Craft-C examines the active C source file using its available analysis rules.
- Discover: It identifies recognizable patterns that may offer opportunities for improvement.
- Explain: Each finding provides context, a suggested improvement where appropriate, and an educational explanation.
- Review: You decide whether to apply the change, skip it, or inspect the relevant code.
- Learn: Review the session summary to understand which improvements you explored.
💡 Example
Before
#include <stdio.h>
int main(void) {
int n = 10;
if (n == 1) {
printf("Valid");
} else if (n == 2) {
printf("Valid");
}
return 0;
}
Possible improvement
#include <stdio.h>
int main(void) {
int n = 10;
if (n == 1 || n == 2) {
printf("Valid");
}
return 0;
}
What you learn: When multiple conditions perform the same action, combining those conditions can reduce repetition and make the logic easier to follow.
The example illustrates an improvement that an appropriate analysis rule could identify. Actual detection depends on the rules implemented in the installed version.
🎯 Improvement Categories
Craft-C is designed to support suggestions in the following areas:
| Category |
Purpose |
| Simplification |
Reduce unnecessary repetition and complexity |
| Conditionals |
Improve if, else if, and Boolean logic |
| Variables |
Identify redundant assignments and unnecessary variables |
| Loops |
Recognize potential loop improvements |
| Functions |
Encourage reusable and maintainable code |
| Arrays & Strings |
Flag recognizable indexing and string-handling risks |
| Pointers & Memory |
Identify suspicious pointer and memory patterns |
| Input & Output |
Review common printf() and scanf() usage |
| Readability |
Improve naming, formatting, and code structure |
| Efficiency |
Identify justified optimization opportunities |
| Best Practices |
Encourage reliable, maintainable C programming |
The availability and accuracy of each category depend on the analysis rules implemented in the current release.
🛡️ Safe Code Editing
Craft-C is designed to keep you in control of your source code.
- Review suggestions before applying them.
- Apply fixes only when a supported replacement is available.
- Reject stale suggestions when the underlying source has changed.
- Prefer small, localized edits over rewriting entire files.
- Treat uncertain findings as recommendations rather than guaranteed fixes.
Shorter code is not always better code. Craft-C prioritizes correctness, clarity, and maintainability over reducing line count.
⚙️ Technology Stack
- JavaScript — Extension implementation
- Visual Studio Code Extension API — Editor integration and commands
- VS Code Webview API — Interactive user interface
- HTML & CSS — Interface structure and styling
- Rule-based analysis — Detecting supported C code patterns
The core analysis is designed to work without requiring an external AI API. Advanced AI-assisted analysis may be added separately in a future version.
📁 Project Structure
craft-c/
├── extension.js
├── package.json
├── README.md
└── .gitignore
Additional files may be introduced as the project grows, including automated tests, configuration, and packaging metadata.
🧪 Testing
Before using Craft-C on important projects, test it with small programs covering:
- Basic input and output
- Conditional statements
- Loops and nested loops
- Functions
- Arrays and strings
- Variables and assignments
- Potentially unsafe input patterns
- Comments and string literals containing code-like text
- Source changes made after analysis
Verify that suggestions are relevant, source locations are accurate, and applying a fix does not unintentionally modify unrelated code.
⚠️ Limitations
Craft-C's recommendations depend on the capabilities of its implemented analysis engine.
- Text-based analysis cannot reliably understand every valid C program.
- Some findings may be uncertain or context-dependent.
- Performance improvements should be validated rather than assumed.
- Static analysis does not replace compilation, testing, or debugging.
- Advanced pointer, memory, and control-flow analysis may require a proper C parser or compiler integration.
- AI-assisted features, if introduced, may require separate configuration and explicit permission to transmit source code.
Always review proposed changes and test your program after applying them.
🗺️ Roadmap
Potential future improvements include:
- [ ] Expanded C analysis rules
- [ ] More accurate syntax-aware analysis
- [ ] Advanced control-flow and data-flow checks
- [ ] Improved before-and-after code comparison
- [ ] Persistent learning statistics
- [ ] Customizable analysis categories
- [ ] Optional AI-powered explanations
- [ ] Automated tests for analysis rules
- [ ] Extension packaging and Marketplace publication
Roadmap items are planned possibilities and are not necessarily implemented in the current release.
🤝 Contributing
Contributions, suggestions, and bug reports are welcome.
If you contribute:
- Keep analysis rules modular.
- Include examples demonstrating the issue or improvement.
- Test both valid matches and likely false positives.
- Avoid automatic transformations when correctness cannot be established.
- Document new features and limitations.
📄 License
Choose and include an appropriate open-source license before distributing the project. If you select the MIT License, add a corresponding LICENSE file containing the license text and copyright information.
👨💻 Author
Aryan Pandey
Project: Craft-C
Built to help C programmers learn, improve, and develop better coding habits.
Craft-C — Don't just write code. Craft better code.