NanoClaw is a personal Claude assistant running in a container that interacts with users through WhatsApp. It utilizes the Claude Agent SDK to run Claude Code in an isolated Linux container, providing secure file access and task execution capabilities.
Introduction
NanoClaw manages Claude API authentication through the .env configuration file and supports various integration methods.
Relevant Information:
- Official Repository: https://github.com/gavrielc/nanoclaw
- Project Configuration:
src/config.ts - Environment Variables:
.env - Key Retrieval:
src/env.ts - SDK Calls:
container/agent-runner/src/index.ts
Method 1: Defapi (Recommended - Half Price Discount)
Defapi is a proxy service compatible with the Anthropic API, offering a price only half of the official rate, making it ideal for personal AI assistants like NanoClaw that require long-term operation.
Defapi supports the following protocols:
v1/chat/completionsinterfacev1/messagesinterfacev1beta/models/interface
Integration Steps
- Register for a Defapi Account
Visit the Defapi platform, register for an account, and obtain an API Key.
- Configure the .env File
Edit the .env file in the root directory of the NanoClaw project:
# Use Defapi
ANTHROPIC_API_KEY=your-defapi-api-key
ANTHROPIC_BASE_URL=https://api.defapi.com/v1
Or use the messages interface (recommended):
ANTHROPIC_API_KEY=your-defapi-api-key
ANTHROPIC_BASE_URL=https://api.defapi.com/v1
- Restart the Service
# macOS
launchctl unload ~/Library/LaunchAgents/com.nanoclaw.plist
launchctl load ~/Library/LaunchAgents/com.nanoclaw.plist
# Or run in development mode
npm run dev
Advantages
- Affordable Pricing: Only 50% of Anthropic's official pricing
- Excellent Compatibility: Fully compatible with the Anthropic API protocol
- Stable and Reliable: Supports v1/chat/completions, v1/messages, v1beta interfaces
- Plug-and-Play: No code modifications required, just change environment variables
Method 2: Anthropic Official API Key
Directly using the Anthropic official API requires payment, but it offers the highest stability.
Configuration
ANTHROPIC_API_KEY=sk-ant-api03-xxxxxxxxxxxx
How to Obtain
- Visit Anthropic Console
- Create an API Key
- Add it to the
.envfile
Method 3: Claude Code Subscription (OAuth Token)
If you have subscribed to Claude Code Pro/Max, you can use an OAuth Token.
Configuration
CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-xxxxxxxxxxxx
How to Obtain
# Extract from Claude Code credentials
cat ~/.claude/.credentials.json
Method 4: OpenRouter Proxy
OpenRouter also provides Anthropic-compatible interfaces, although the prices are generally slightly higher than those of Defapi.
Configuration
ANTHROPIC_API_KEY=sk-or-v1-xxxxxxxxxxxx
ANTHROPIC_BASE_URL=https://openrouter.ai/api/v1
Method 5: Custom Compatible Interface
If you are using another service compatible with the Anthropic API (like a locally deployed proxy), you can customize the BASE_URL:
ANTHROPIC_API_KEY=your-api-key
ANTHROPIC_BASE_URL=https://your-proxy.example.com/v1
Supported interfaces:
v1/chat/completionsv1/messagesv1beta/models/*:generateContentv1beta/models/*:streamGenerateContent
Verifying if NanoClaw Works Properly
Method 1: Direct Message Test
- Ensure the service is running
- Send a message in a registered group or private chat on WhatsApp:
@Andy Hello, please reply to this message
- If the configuration is correct, Claude will reply within seconds.
Method 2: Checking Logs
# View real-time logs
tail -f logs/nanoclaw.log
# View error logs
tail -f logs/nanoclaw.error.log
Method 3: Run Verification Script
.claude/skills/setup/scripts/09-verify.sh
Check if the CREDENTIALS status in the output is “passed.”
Common Use Cases
Use Case 1: Personal AI Assistant
Chat with Claude anytime through WhatsApp for assistance with Q&A, writing, programming, and more.
@Andy Help me write an email
@Andy Explain what quantum computing is
Use Case 2: Scheduled Task Reminders
Set recurring tasks, and Claude will automatically execute and notify you.
@Andy Send me the weather forecast every morning at 8 AM
@Andy Summarize my weekly work progress every Friday afternoon
Use Case 3: File Management and Q&A
Access mounted directories, helping you manage files and answer project-related questions.
@Andy Show me the notes I created last time
@Andy What problems are there with this code
Use Case 4: Web Searching and Summarization
Claude can search the web and provide you with the latest information.
@Drawer Search for the latest AI news
@Andy Summarize the main points of this paper https://example.com/paper
Use Case 5: Browser Automation
Execute complex web operations through the agent-browser skill.
@Andy Help me book a flight to Beijing
@Andy Search for the price of this product on Amazon
Configuration Summary
| Configuration Item | Description | Example Value |
|---|---|---|
ANTHROPIC_API_KEY | API Key | sk-ant-... |
ANTHROPIC_BASE_URL | API Endpoint | https://api.defapi.com/v1 |
CLAUDE_CODE_OAUTH_TOKEN | OAuth Token | sk-ant-oat01-... |
ASSISTANT_NAME | Trigger Word | Andy |
CONTAINER_TIMEOUT | Container Timeout (ms) | 1800000 |
IDLE_TIMEOUT | Idle Timeout (ms) | 1800000 |
Conclusion
Integrating the Claude API is the first step in using NanoClaw. For personal use, Defapi is recommended, as it provides a fully compatible API interface at only 50% of the official price, significantly reducing usage costs.
Just modify the ANTHROPIC_BASE_URL and ANTHROPIC_API_KEY in the .env file to complete the switch, without needing to modify any code.