v2/docs/setup/ENV-SETUP-GUIDE.md
The .env file is required for ReasoningBank memory capabilities in claude-flow. Without it, the system falls back to heuristic mode (simple regex pattern matching) with no actual learning.
claude-flow init --env
This creates a comprehensive .env template with:
Open .env and add at minimum one of these:
# Required: Choose at least one
ANTHROPIC_API_KEY=sk-ant-xxxxx # Get from https://console.anthropic.com/settings/keys
OPENROUTER_API_KEY=sk-or-v1-xxxxx # Get from https://openrouter.ai/keys
GOOGLE_GEMINI_API_KEY=...
When you run:
claude-flow agent run coder "Build API" --enable-memory
Result:
⚠️ ReasoningBank memory requires .env configuration
📋 Setting up .env for ReasoningBank capabilities:
1. Create .env file:
claude-flow init --env
2. Add your API keys to .env:
ANTHROPIC_API_KEY=sk-ant-...
OPENROUTER_API_KEY=sk-or-v1-...
3. Get API keys:
• Anthropic: https://console.anthropic.com/settings/keys
• OpenRouter: https://openrouter.ai/keys
💡 Without API keys:
• ReasoningBank falls back to regex pattern matching (no learning)
• Memory operations will appear to work but won't actually learn
❌ Cannot use --enable-memory without .env file
If .env exists but has no API keys:
⚠️ No API keys found in .env file
⚠️ ReasoningBank will fall back to heuristic mode (regex matching)
Without API keys, memory will NOT learn from experience!
❌ Add API keys to .env to enable actual learning
✅ API keys configured:
• Anthropic (Claude)
• OpenRouter (cost optimization available)
🚀 Executing coder agent with agentic-flow...
Task: Build API
[... actual agent execution with learning ...]
.env or manually exported).swarm/reasoningbank.yaml)With OpenRouter + DeepSeek R1, you can reduce costs by 46%:
# 1. Add to .env
OPENROUTER_API_KEY=sk-or-v1-...
# 2. Create .swarm/reasoningbank.yaml
mkdir -p .swarm
cat > .swarm/reasoningbank.yaml << 'EOF'
reasoningbank:
judge:
model: "deepseek/deepseek-r1"
max_tokens: 512
temperature: 0
distill:
model: "deepseek/deepseek-r1"
max_tokens: 2048
temperature: 0.3
embeddings:
provider: "openrouter"
model: "deepseek/deepseek-r1"
dimensions: 1024
EOF
# 3. Use memory with cost optimization
claude-flow agent run coder "Build API" \
--enable-memory \
--memory-domain api/authentication \
--memory-k 5
See REASONINGBANK-COST-OPTIMIZATION.md for detailed cost analysis.
If you don't want to use .env, you can:
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENROUTER_API_KEY="sk-or-v1-..."
claude-flow agent run coder "task" --enable-memory
ANTHROPIC_API_KEY="sk-ant-..." \
claude-flow agent run coder "task" --enable-memory
# Add to ~/.bashrc or ~/.zshrc
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENROUTER_API_KEY="sk-or-v1-..."
.gitignore)claude-flow init --env # Create new .env
claude-flow init --env --force # Overwrite existing .env
# Basic memory
claude-flow agent run coder "task" --enable-memory
# Advanced memory
claude-flow agent run coder "task" \
--enable-memory \
--memory-domain api/authentication \
--memory-k 5 \
--memory-min-confidence 0.7
claude-flow init --help # See all init options
claude-flow agent --help # See all agent options
Duration: 2ms
Memories: 0 (fake)
Success rate: 67% (regex-based)
Learning: None
Duration: 19,036ms
Memories: 20 (real)
Success rate: 88% (learned)
Learning: Actual pattern consolidation
Database: 20 entries with embeddings
Solution: Run claude-flow init --env and add API keys
Solution: Add at least one valid API key to .env
Cause: No API keys configured, using heuristic fallback
Solution: Add API keys to .env file
Solution: See REASONINGBANK-COST-OPTIMIZATION.md
The generated .env template includes:
✅ API key placeholders for all providers ✅ Setup instructions with direct links ✅ Cost optimization examples ✅ Model configuration defaults ✅ Optional service keys (Perplexity, HuggingFace, E2B, Supabase) ✅ Comprehensive comments explaining behavior ✅ Security best practices
Total template size: ~150 lines with extensive documentation
For issues or questions: