A utility for extracting code blocks from Claude AI responses and creating a complete project structure automatically.
When working with Claude AI, it often provides extensive code examples across multiple files. Instead of manually creating each file and copying the code, this tool:
- Automatically identifies file paths in Claude's responses
- Extracts all code blocks into their proper files
- Creates a complete project structure with proper directories
- Adds supporting files like README.md, requirements.txt, and .gitignore
- Optionally sets up GitHub repository files and initializes git
- Creates a ZIP archive for easy sharing
This tool works with a variety of programming languages and file formats:
- Python
- JavaScript/TypeScript
- Java
- C/C++
- Go
- Ruby
- Rust
- HTML/CSS
- Bash/Shell scripts
- JSON/YAML
- Markdown
- SQL
- And more!
- Ensure you have Python 3.x installed
- Set up the virtual environment:
python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
- Copy your entire conversation with Claude that contains code into a text file
- Run the script on that file:
python claude_to_files.py --file your_claude_conversation.txt --output-dir my_project
Run the script in interactive mode and paste the Claude response directly:
python claude_to_files.py --interactive
Add the --github
flag to create GitHub-specific files and get instructions for publishing:
python claude_to_files.py --file your_claude_conversation.txt --github
Add the --init-git
flag to automatically initialize a git repository:
python claude_to_files.py --file your_claude_conversation.txt --github --init-git
The tool recognizes various ways Claude might introduce code files:
File: path/to/file.py
Let's create 'path/to/file.py':
Create a file named 'path/to/file.py':
Create 'path/to/file.py':
And various code block formats:
- Markdown code blocks (
python,
javascript, etc.) - Claude's pythonCopy format
--file
: Path to the file containing Claude's response--output-dir
: Directory to create the project in (default: claude_project)--zip-name
: Name of the ZIP file to create (default: claude_project.zip)--interactive
: Run in interactive mode--github
: Create GitHub-specific files and provide publishing instructions--init-git
: Initialize git repository in the project directory
- Create a new repository at https://github.com/new
- Initialize and push your local repository:
cd claude_project git init git add . git commit -m "Initial commit from Claude AI code" git branch -M main git remote add origin https://github.com/yourusername/your-repo-name.git git push -u origin main
Use the --init-git
flag to have the script initialize the git repository for you:
python claude_to_files.py --file your_claude_conversation.txt --github --init-git
Then just add your remote and push:
cd claude_project
git remote add origin https://github.com/yourusername/your-repo-name.git
git push -u origin main
Let's say Claude gives you code for a multi-language project with multiple files. Instead of creating each file manually:
- Save Claude's response to
claude_response.txt
or copy it to your clipboard - Run:
python claude_to_files.py --file claude_response.txt --github --init-git
- The tool will:
- Extract all code files
- Create the proper directory structure
- Add supporting files
- Initialize a git repository
- Generate a ZIP archive
Check out the examples directory for:
- Sample Claude responses
- Testing scripts
- Usage examples
This project is licensed under the MIT License - see the LICENSE file for details.