Slash Commands Reference
All commands in DSPy Code start with /. This page lists every command with examples.
Project Commands
/init
Initialize or scan your DSPy project.
What it does:
- Creates
dspy_config.yamlif it doesn't exist - Scans your project code
- Indexes your installed DSPy version
- Shows entertaining jokes while indexing!
When to use:
- Starting a new project
- After installing new packages
- When you want to refresh the code index
Example Output
đ Building Codebase Knowledge Base
What's being indexed:
âĸ Your installed DSPy
âĸ Your project code
âĸ GEPA optimizer (if installed)
đ¤ Teaching the AI to read your code...
â Index built successfully!
đĄ You can now ask questions about:
âĸ DSPy concepts
âĸ Your project code
âĸ Code examples
/status
Show your current session status.
What it shows:
- Generated code in context
- Training data (if any)
- Conversation message count
- Connected model status
- Available commands
Use This When
- You're not sure if code was generated
- You want to see what's in your session
- You forgot if you saved your code
Example:
Output:
đ Session Status
â Generated Code: module
Lines: 45
Characters: 1234
Available commands: /save, /validate, /run
đŦ Conversation: 6 messages
đ¤ Connected Model: llama3.1:8b (ollama)
đĄ Next Steps:
/save <filename>.py - Save your code
/validate - Check for issues
/run - Test execution
/clear
Clear conversation history and start fresh.
What it does:
- Clears all conversation messages
- Removes generated code from context
- Gives you a clean slate
This Cannot Be Undone
Make sure to save any code you want to keep before clearing!
Code Generation Commands
/create
Interactive wizard for creating DSPy components.
What it does:
- Asks you questions about what you want to build
- Guides you through the process
- Generates complete code
Or just describe what you want:
Natural Language Works!
You don't need to use /create. Just describe what you want in plain English!
/demo
See example DSPy programs in action.
What it shows:
- Complete working examples
- Different DSPy patterns
- Code you can learn from
Run a specific demo:
/examples
Browse DSPy templates and patterns.
What you'll see:
- Signature templates
- Module patterns
- Complete program templates
- Industry-specific examples
Generate from a template:
Model Connection Commands
/model
Interactively select and connect to a model.
Basic usage:
You will be prompted to choose:
- Local models via Ollama (auto-detected from your Ollama installation)
- Cloud providers: OpenAI, Anthropic, Gemini (you then type the model name, e.g.
gpt-5-nano,claude-sonnet-4.5,gemini-2.5-flash)
Shortcuts:
/model ollama # Only show local Ollama models and pick one by number
/model cloud # Pick a cloud provider, then type the model name
/connect
Directly connect to a specific model if you already know the name.
Ollama (Local):
OpenAI:
Anthropic Claude:
Google Gemini:
API Keys
For cloud providers, set your API key first:
/disconnect
Disconnect from the current model.
When to use:
- Switching to a different model
- Working offline with templates
- Troubleshooting connection issues
Code Management Commands
/save
Save generated code to a file.
Where it saves:
- Default:
generated/directory - Creates directory if it doesn't exist
- Won't overwrite without confirmation
Always Save!
After generating code you like, save it immediately. Use /status to check if you have code to save.
/validate
Check your code for issues and best practices.
Validates last generated code
Validates a specific file
What it checks:
- Signature correctness
- Module structure
- Best practices
- Common mistakes
- Security issues
Quality Assurance
Always validate before running. It catches issues early!
/run
Execute your DSPy program safely.
Runs last generated code
Runs a specific file
Safety features:
- Runs in a sandbox
- Timeout protection
- Error handling
- Safe execution
Sandbox Execution
Your code runs in a safe sandbox. Some operations (like file I/O) may be restricted.
/test
Run tests on your code.
What it does:
- Runs unit tests
- Checks functionality
- Reports results
Optimization Commands
/optimize
Generate GEPA optimization code.
Be Aware of Optimization Cost
GEPA optimization can issue many LLM calls, especially when using cloud providers (OpenAI, Anthropic, Gemini). Make sure you understand your API pricing and quotas before running /optimize, and prefer small budgets when starting out. For local models, we recommend at least 32 GB RAM for comfortable optimization runs.
What it creates:
- Complete GEPA optimization script
- Metric with feedback
- Training data loaders
- Configuration
Options:
Real GEPA
This generates code that uses REAL GEPA optimization from your installed DSPy version!
/eval
Generate evaluation code for your program.
What it creates:
- Evaluation metrics
- Test harness
- Reporting code
Help Commands
/help
Show all available commands.
What you'll see:
- Complete command list
- Usage examples
- Tips and tricks
/intro
Complete guide to DSPy Code.
Perfect for:
- New users
- Learning all features
- Understanding workflows
/explain
Get explanations of DSPy concepts.
Topics you can ask about:
- Signatures
- Modules
- Predictors
- Optimizers
- GEPA
- Metrics
Session Commands
/session save
Save your current session.
What it saves:
- Conversation history
- Generated code
- Session context
/session load
Load a saved session.
Restores:
- All conversation messages
- Generated code
- Session state
/sessions
List all saved sessions.
/session delete
Delete a saved session.
Data Commands
/save-data
Save generated training data.
When to use:
- After generating training examples
- Before optimization
- For backup
MCP Commands
/mcp-add
Add an MCP server.
/mcp-connect
Connect to an MCP server.
/mcp-disconnect
Disconnect from an MCP server.
/mcp-list
List all MCP servers.
/mcp-tools
List tools from an MCP server.
Utility Commands
/history
Show conversation history.
Show all messages:
/refresh-index
Rebuild the codebase index.
When to use:
- After updating DSPy
- After adding new code
- If index seems stale
/index-status
Check the status of your codebase index.
Shows:
- Index age
- Number of files indexed
- Cache size
- Staleness warning
/exit
Exit DSPy Code.
Or use:
Command Tips
Tab Completion
Many terminals support tab completion. Type / and press Tab to see available commands!
Command History
Use the up arrow to recall previous commands.
Partial Commands
You can often use shortcuts: - /h for /help - /s for /status - /v for /validate
Case Insensitive
Commands are case insensitive: - /HELP works - /Help works - /help works
Next Steps
Now that you know all the commands, learn how to use them effectively: