MedgeClaw: Half-price Claude for bioinformatics analysis.
Repository: https://github.com/xjtulyc/MedgeClaw
Medium difficulty, approximately 30 minutes. Learn how to build a Biomedical AI Assistant using half-price Claude APIs, saving over $500 monthly.
Target Audience
- Life science researchers looking to use AI to assist in data analysis.
- Bioinformatics engineers needing to automate scientific workflows.
- University students interested in AI + Scientific Research.
Core Dependencies and Environment
- Node.js 22+
- Docker + docker-compose
- Git
- Defapi API Key (The half-price solution, detailed below)
[!TIP]
A GPU with 8GB+ VRAM is not mandatory, but it allows for more local model deployments.
Project Structure
MedgeClaw/
βββ .env.example # Environment configuration template
βββ .env # Actual configuration (copied from example)
βββ setup.sh # One-click installation script
βββ sync.py # OpenClaw configuration sync
βββ docker-compose.yml # Docker environment definition
βββ .medgeclaw-sync.yml # Sync rule configuration
βββ docker/
β βββ Dockerfile # R + Python + RStudio + Jupyter
β βββ entrypoint.sh # Container startup script
βββ skills/ # MedgeClaw built-in skills
β βββ biomed-dispatch/ # Task router
β βββ dashboard/ # Real-time research dashboard
β βββ cjk-viz/ # Chinese font detection
β βββ svg-ui-templates/ # SVG templates
β βββ feishu-rich-card/ # Feishu rich text cards
βββ scientific-skills/ # K-Dense 140 scientific skills (git submodule)
βββ data/ # Data directory (place your input files here)
βββ outputs/ # Output directory (analysis results go here)
βββ writing_outputs/ # Scientific writing outputs
Step-by-Step Tutorial
Step 1: Clone the Repository
# Clone the project (including submodules)
git clone --recurse-submodules https://github.com/xjtulyc/MedgeClaw.git
cd MedgeClaw
[!WARNING]
You must include--recurse-submodules, otherwise thescientific-skillsdirectory will be empty.
Step 2: Configure Half-Price Claude API
This is the most critical stepβwe are using Defapi to save big!
Defapi is a model aggregation platform compatible with the OpenAI format, offering half-price services for the Claude series. Indeed, while the official price for Claude Sonnet 4.5 is $3.75/M tokens, it is only $1.875 here.
[!TIP]
Suppose you run 1,000 gene analyses per day, each consuming 100k context tokens + 5k output tokens:
- Official API: Approx. $3.75 Γ 1000 = $3750/month
- Defapi: Approx. $1.875 Γ 1000 = $1875/month
- Monthly Savings: $1875!
First, copy the configuration template:
cp .env.example .env
Then edit .env and enter your Defapi API Key:
# Defapi Half-Price Configuration
ANTHROPIC_API_KEY=dk-xxxxxxxxxxxxxxxx
ANTHROPIC_BASE_URL=https://api.defapi.org
MODEL=anthropic/claude-sonnet-4.5
# Critical: Claude Code pre-flight requires this configuration
ANTHROPIC_SMALL_FAST_MODEL=anthropic/claude-sonnet-4.5
# Web Interface Passwords
RSTUDIO_PASSWORD=biomed
JUPYTER_TOKEN=biomed
[!WARNING]
Don't have a Defapi API Key? Register at https://defapi.org; new users get free credits. Defapi supports thev1/chat/completionsendpoint and is fully compatible with Claude Code.
Step 3: Run the Installation Script
bash setup.sh
This script will automatically:
- Check for Node.js 22+ and Docker dependencies.
- Globally install
openclawandclaude-code. - Generate
~/.claude/settings.json(Claude Code configuration). - Build the Docker image (containing R, Python, RStudio, JupyterLab).
- Configure the OpenClaw workspace.
[!WARNING]
Building the Docker image for the first time takes 10-20 minutes, depending on your network and machine specs.
Step 4: Start the Docker Environment
docker compose up -d
Once started successfully, you can access:
- RStudio Server: http://localhost:8787 (Username:
rstudio, Password:biomed) - JupyterLab: http://localhost:8888 (Token:
biomed)
Step 5: Sync Configuration to OpenClaw
python3 sync.py
openclaw gateway restart
sync.py will:
- Copy MedgeClaw skills to the OpenClaw workspace.
- Update OpenClaw configuration files.
- Inject project documentation into the Agent context.
Step 6: Verify Installation
# Quickly verify API connection (should return "hello" within 30 seconds)
claude --dangerously-skip-permissions -p 'run: echo hello'
If you see hello, the configuration is correct.
[!WARNING]
If it hangs for more than 30 seconds,ANTHROPIC_SMALL_FAST_MODELis likely configured incorrectlyβyour proxy might not support that model. Defapi works fine as it supports the full Claude model list.
Troubleshooting
Q1: Docker Build Failed
Symptoms: docker compose build hangs or throws an error.
Solution:
# Clean Docker cache and retry
docker system prune -a
docker compose build --no-cache
Q2: Claude Code Pre-flight Hangs
Symptoms: Any command hangs, showing "Pre-flight check is taking longer than expected".
Solution: Third-party proxies may not support the default Haiku model; you must set ANTHROPIC_SMALL_FAST_MODEL:
# Add to .env (or modify to a model supported by your proxy)
ANTHROPIC_SMALL_FAST_MODEL=anthropic/claude-sonnet-4.5
Defapi fully supports this configuration.
Q3: scientific-skills directory is empty
Symptoms: The skills/ directory exists but has no content.
Solution:
git submodule update --init --recursive
Q4: Port Occupied
Symptoms: Port 8787 or 8888 is already in use.
Solution:
# Find the process using the port
lsof -i :8787
lsof -i :8888
# Or change the port mapping in docker-compose.yml
Q5: OpenClaw cannot find MedgeClaw skills
Symptoms: Agent does not recognize skills like biomed-dispatch.
Solution:
# Re-sync
python3 sync.py
openclaw gateway restart
Q6: R/Python Package Installation Failed
Symptoms: Analysis script errors with "package not found".
Solution:
# Python package
docker exec medgeclaw pip install <package-name>
# R package
docker exec medgeclaw Rscript -e 'install.packages("<package-name>", repos="https://cran.r-project.org")'
Further Reading / Advanced Directions
1. K-Dense Scientific Skills
MedgeClaw integrates 140 scientific skills covering:
- Omics Analysis: DESeq2, edgeR, Scanpy, Seurat
- Drug Discovery: ChEMBL, DeepChem, DiffDock
- Literature Search: PubMed, bioRxiv, Semantic Scholar
- Pathway Analysis: gseapy, clusterProfiler
For detailed usage, refer to the SKILL.md files in the scientific-skills/scientific-skills/ directory.
2. Custom Skill Development
Want to add new skills to MedgeClaw? Create a directory following the AgentSkills specification:
skills/
βββ your-custom-skill/
βββ SKILL.md # Skill definition file
SKILL.md Template:
# Your Custom Skill
## When to use
Describe the scenarios in which this skill should be called.
## How it works
The specific implementation logic of the skill.
## Examples
Provide a few usage examples.
3. Multi-Model Comparison
Real-world comparison of different models:
| Model | Speed | Quality | Price | Suitable Scenario |
|---|---|---|---|---|
| claude-sonnet-4.5 (Defapi) | Medium | High | Medium | Daily Analysis (Recommended) |
| claude-opus-4.5 (Defapi) | Slow | Highest | High | Complex Reasoning Tasks |
| claude-haiku-4.5 (Defapi) | Fast | Medium | Low | Simple Tasks |
| qwen2.5:14b (Local) | Local | Medium | Free | Fully Offline Scenarios |
[!TIP]
If you want to save even more, Defapi supports Claude Haiku 4.5 at a lower price point, suitable for simple tasks.
4. Feishu Integration
To let MedgeClaw work within Feishu groups, configure the FEISHU_DEFAULT_CHAT_ID environment variable, then use the feishu-rich-card skill to send rich media reports.
5. Research Dashboard
Every analysis task automatically generates a real-time dashboard. Access data/<task_name>/dashboard/dashboard.html to view progress, code, and output previews.