Export Claude Code conversations to markdown or JSON with flexible modes and formats.
- Multiple Export Modes: Extract user prompts, assistant outputs, or full conversations
- Multiple Formats: Export to Markdown, JSON, or both simultaneously
-
Dual Directory Support: Automatically handles both
~/.claude
and~/.config/claude
- Interactive Mode: User-friendly prompts with smart defaults and timeouts
- Enhanced Statistics: Message counts, timestamps, and session metadata
- Smart Organization: Timestamp-based directories for multi-format exports
- Flexible CLI: Rich command-line options with shortcuts
- Programmatic API: Full-featured library for Node.js integration
- Cross-Platform: Works on macOS, Linux, and Windows
- Installation
- Quick Start
- Usage
- Export Modes
- Export Formats
- Output Examples
- Configuration
- Troubleshooting
- Contributing
- License
npm install -g claude-code-exporter
npm install claude-code-exporter
npx claude-code-exporter /path/to/project
Export with interactive prompts:
claude-prompts
Export full conversations:
claude-prompts --full /path/to/project
Export to JSON format:
claude-prompts --json /path/to/project
Export everything (all modes and formats):
claude-prompts --full --all-formats /path/to/project
claude-prompts [options] [project-path] [output-dir]
-
project-path
- Path to your project (default: current directory) -
output-dir
- Output directory for exported files (default:./claude-prompts
)
-
-h, --help
- Show help message -
-v, --version
- Show version number -
-V, --verbose
- Enable verbose output for debugging -
-q, --quiet
- Suppress all output except errors -
--list
- List available sessions without exporting
-
-p, --prompts
- Export user prompts only (default) -
-o, --outputs
- Export assistant outputs only -
-f, --full
- Export full conversations
-
-m, --markdown
- Export as Markdown (default) -
-j, --json
- Export as JSON -
--all-formats
- Export in both Markdown and JSON
-
--no-interactive
- Disable interactive prompts, use defaults -
--claude-home DIR
- Specify Claude home directory -
--timeout SECONDS
- Timeout for interactive prompts (default: 10)
# Interactive mode (prompts for all options)
claude-prompts
# Export user prompts (default)
claude-prompts /path/to/project
# Export full conversations
claude-prompts --full /path/to/project
# Export only assistant outputs as JSON
claude-prompts --outputs --json /path/to/project
# Export everything in both formats
claude-prompts --full --all-formats /path/to/project ./exports
# List sessions without exporting
claude-prompts --list /path/to/project
# Non-interactive with specific Claude home
claude-prompts --no-interactive --claude-home ~/.config/claude /path/to/project
# Quiet mode for scripts
claude-prompts --quiet --full /path/to/project
When run without mode or format flags, the tool enters interactive mode:
Choose a mode:
1) Prompts Only
2) Outputs Only
3) Full Conversation
Defaulting to: 1) Prompts Only
What do you want to export? [1-3]: _
Choose a format:
1) Markdown
2) JSON
3) Both: Markdown and JSON
Defaulting to: 1) Markdown
What format do you want? [1-3]: _
Interactive features:
- Smart defaults (Prompts Only, Markdown)
- 10-second timeout (auto-selects default)
- Multiple Claude home directory handling
- Clear visual feedback
const ClaudePromptExporter = require('claude-code-exporter');
// Basic usage
const exporter = new ClaudePromptExporter('/path/to/project');
const result = await exporter.export('./output');
// Advanced usage with all options
const exporter = new ClaudePromptExporter('/path/to/project', {
exportMode: ClaudePromptExporter.ExportMode.FULL_CONVERSATION,
exportFormat: ClaudePromptExporter.ExportFormat.BOTH,
verbose: true,
interactive: false,
timeout: 5000,
claudeHome: '/custom/claude/home'
});
// Export with specific mode/format
const result = await exporter.export('./output');
console.log(`Exported ${result.sessionsExported} sessions`);
console.log(`Total messages: ${result.totalMessages}`);
console.log(`User messages: ${result.totalUserMessages}`);
console.log(`Assistant messages: ${result.totalAssistantMessages}`);
// Or use specific methods
const sessions = exporter.extractMessages();
const homes = exporter._detectClaudeHomes();
Exports only user messages, filtering out:
- System messages
- Tool results
- Assistant responses
Best for: Creating prompt libraries, analyzing your questions
Exports only assistant responses, excluding:
- User prompts
- System messages
- Tool results
Best for: Collecting code examples, building documentation
Exports complete conversations including:
- User prompts
- Assistant responses
- Context and flow
Best for: Documentation, learning from interactions, debugging
Human-readable format with:
- Session metadata
- Formatted timestamps
- Syntax highlighting for code
- Clear message separation
Structured data including:
- Complete metadata
- Message arrays with roles
- Timestamps and indices
- Statistics object
When exporting both formats:
- Creates timestamp-based directories
- Organizes files by session
- Maintains consistent naming
claude-prompts/
├── 2d002199-ca50-464e-ab59-d2165df9e248-untitled-prompts.md
├── 33c13f1c-928d-4128-86a2-28b241f47949-react-hooks-full.md
└── 73d2983f-16f9-4267-9611-3b55f790562e-api-design-outputs.json
claude-prompts/
├── 20250623-143022-react-hooks/
│ ├── prompts-20250623-143022-react-hooks-33c13f1c.md
│ ├── prompts-20250623-143022-react-hooks-33c13f1c.json
└── 20250623-143156-api-design/
├── full-20250623-143156-api-design-73d2983f.md
└── full-20250623-143156-api-design-73d2983f.json
✓ 2d002199-ca50-464e-ab59-d2165df9e248: 143 messages (56 user, 87 assistant) last 6/23/2025, 5:27:48 PM
✓ 33c13f1c-928d-4128-86a2-28b241f47949: 177 messages (89 user, 88 assistant) last 6/23/2025, 6:45:12 PM
✓ 73d2983f-16f9-4267-9611-3b55f790562e: 235 messages (112 user, 123 assistant) last 6/24/2025, 9:15:33 AM
Exported 3 sessions (555 total messages) to ./claude-prompts/
- Node.js: Version 14.0.0 or higher
-
Claude Code: Must be installed with sessions stored in:
-
~/.claude/projects/
(original location) -
~/.config/claude/projects/
(XDG Base Directory compliant)
-
- Operating System: macOS, Linux, or Windows
-
CLAUDE_HOME
- Override the Claude home directory location -
HOME
(macOS/Linux) orUSERPROFILE
(Windows) - Used to locate the Claude home directory
-
--claude-home
CLI option (highest priority) -
CLAUDE_HOME
environment variable - Interactive selection (when both directories exist)
- Automatic detection (when one directory exists)
- Error (when no directory found)
When both ~/.claude
and ~/.config/claude
exist:
- Interactive mode: Prompts for selection with smart default
- Non-interactive mode: Uses
~/.config/claude
(newer standard) - Override: Use
--claude-home
orCLAUDE_HOME
environment variable
- Verify project path matches Claude Code usage
- Check sessions exist in Claude directories
- Use
--verbose
for detailed path matching info
- Some sessions may not contain the requested message type
- Try
--full
to see all messages - Use
--list
to preview session contents
# Verbose output for troubleshooting
claude-prompts --verbose /path/to/project
# List sessions with details
claude-prompts --list --verbose /path/to/project
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
# Clone the repository
git clone https://github.com/developerisnow/claude-code-exporter.git
cd claude-code-exporter
# Install dependencies
npm install
# Run tests
npm test
# Test CLI locally
./bin/claude-prompts /path/to/test/project
This project is licensed under the MIT License - see the LICENSE file for details.
- Built for the Claude Code community
- Inspired by the need to document AI-assisted development
- Thanks to all contributors and users
Made with ❤️ for developers