Offload Bulk Generation to DeepSeek via Claude Code
Claude designs and reviews, a shell script calls DeepSeek API for cheap bulk generation. Split reasoning from volume for 95% lower cost on test suites, boilerplate, and documentation.
Offload Bulk Generation to DeepSeek via Claude Code
Claude Code is expensive for bulk generation. DeepSeek is 95% cheaper but lacks Claude's reasoning quality. This pattern uses a shell script to call DeepSeek's API for high-volume tasks — Claude designs the approach and reviews the output, DeepSeek handles the volume.
Overview
Claude Code can invoke shell scripts via its bash tool. This pattern uses a helper script to send generation requests to DeepSeek's API and pipes the results back into Claude's context — Claude designs and reviews, DeepSeek handles volume.
The pattern splits the work:
- Claude Code — Reasons about the task, designs the generation prompt, invokes the script, reviews the output
- DeepSeek API — Handles bulk text generation at low cost with high throughput
The key insight: 80% of code generation tasks don't need Claude-level reasoning. This pattern lets you route the cheap work to DeepSeek without leaving Claude's workflow.
Key Features
- Works inline — no need to switch tools mid-session
- DeepSeek's API is 95% cheaper than Claude for equivalent token counts
- The script is a single file — no Claude config changes needed
- Claude maintains full control: it decides when to invoke the script and reviews all output
- Works with any API, not just DeepSeek — extend to OpenRouter, Together AI, or local models
Installation & Setup
Prerequisites
Claude Code:
npm install -g @anthropic-ai/claude-code
DeepSeek API key:
export DEEPSEEK_API_KEY=sk-...
Helper Script
Create a CLI script that Claude can invoke. Store it anywhere Claude can access:
~/.claude/hooks/cheap-gen.sh
#!/bin/bash
# cheap-gen.sh — Bulk generation via DeepSeek API
# Usage: echo "prompt" | cheap-gen.sh
#
# Reads prompt from stdin, sends to DeepSeek API, writes response to stdout.
PROMPT=$(cat)
MODEL="${DEEPSEEK_MODEL:-deepseek-chat}"
RESPONSE=$(curl -s https://api.deepseek.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $DEEPSEEK_API_KEY" \
-d "$(jq -n \
--arg model "$MODEL" \
--arg prompt "$PROMPT" \
'{
model: $model,
messages: [{role: "user", content: $prompt}],
temperature: 0.3,
max_tokens: 4096
}')")
# Extract content from response
echo "$RESPONSE" | jq -r '.choices[0].message.content'
Make it executable:
chmod +x ~/.claude/hooks/cheap-gen.sh
Claude Setup
No special configuration required — the script is invoked manually via Claude Code's bash tool. Optionally, add a shortcut description in your CLAUDE.md:
CLAUDE.md
## DeepSeek Generation
Use `~/.claude/hooks/cheap-gen.sh` for bulk code generation tasks:
- Pipe your prompt to stdin
- Output goes to stdout
- Model defaults to deepseek-chat, override with DEEPSEEK_MODEL env var
Available Tools/Resources
| Tool | Role | Strength |
|---|---|---|
cheap-gen.sh script | Calls DeepSeek API | Bulk generation at low cost |
deepseek-chat model | V3 for generation | 95% cheaper than Claude |
deepseek-reasoner model | R1 for complex tasks | Cost-effective reasoning |
Claude bash tool | Invokes the script | Direct control over when to invoke |
Configuration Example
In Claude Code session: Generate test suite
Claude designs the test structure, invokes the script for bulk generation:
Use cheap-gen.sh to generate unit tests for the following modules.
For each module, pipe a targeted prompt:
Module: auth.ts
echo "Generate Jest unit tests for an authentication module with JWT tokens, refresh logic, and rate limiting. Include edge cases." | ~/.claude/hooks/cheap-gen.sh
Module: database.ts
echo "Generate Jest unit tests for a PostgreSQL database module with connection pooling, migrations, and transactions." | ~/.claude/hooks/cheap-gen.sh
Claude then reviews each generated test file for correctness before integration.
When to use
- Generating repetitive code (test suites, boilerplate, API endpoints)
- Bulk documentation or changelog generation
- Data transformation scripts
- Any task where the volume is high but the per-unit reasoning requirement is low
Common Use Cases
Test Suite Generation
Claude designs the test strategy and edge case list. DeepSeek generates the individual test files. Claude reviews and corrects. 10 test files in 30 seconds for pennies.
API Endpoint Generation
Claude designs the API structure and data models. DeepSeek generates the CRUD endpoints with validation. Claude reviews for security and correctness.
Documentation Generation
Claude defines the documentation structure and tone. DeepSeek generates the full document from code comments. Claude tightens the language and verifies accuracy.
Data Migration Scripts
Claude analyzes the schema changes and designs the migration plan. DeepSeek generates the migration scripts. Claude verifies the data transformations are correct.
Best Practices
Security Considerations
- The DeepSeek API key is passed as an environment variable — never hardcode it in the shell script or Claude config.
- Review all DeepSeek output before committing. The script is a generation tool, not an approval tool.
- Set
max_tokensto a reasonable limit (4096-8192) to avoid runaway costs. - DeepSeek's API processes data on their servers. Don't send proprietary code through the script without reviewing the terms of service.
Performance Optimization
- Use
deepseek-chat(V3) for most generation tasks. Switch todeepseek-reasoner(R1) only when the task requires multi-step reasoning. - Batch related prompts into a single API call when possible. One 4K-token request is cheaper than four 1K-token requests.
- Set
temperaturelow (0.1-0.3) for deterministic output like code generation. Higher temperatures (0.7+) are useful for creative content.
Troubleshooting
API returns errors
Check the DeepSeek API status at status.deepseek.com. Rate limits are typically 60 RPM — if you hit them, add a sleep 1 between calls in the shell script.
Output is truncated
Increase max_tokens in the shell script. The default 4096 may not be enough for large generation tasks.
JSON output has extra whitespace or formatting
DeepSeek may wrap JSON in markdown code fences. Strip them in the script's post-processing:
echo "$RESPONSE" | jq -r '.choices[0].message.content' | sed 's/^```json//; s/```$//'
Related Integrations
- Driving Gemini with Ralph Loops — Use Gemini instead of DeepSeek when the task needs iterative verification
- Claude Code Cost Optimization — Full cost optimization guide: task routing, session discipline, model selection
- Hermes Cleanup Loop — For longer-running autonomous tasks that need configuration and review
- OpenCode Multi-Provider — Alternatives to DeepSeek: GLM for bilingual tasks, MiniMax for creative generation
Related Articles
Cline — AI Coding Tool Guide
VS Code extension for autonomous AI coding. Browser automation, MCP server creation, terminal control, and prompt patterns for complex multi-step development workflows.
Codex CLI — AI Coding Tool Guide
OpenAI's open-source CLI coding agent. Reasoning strategies, task decomposition, sandboxed execution, and configuration for multi-model workflows.
AI Coding Tools — Prompt Engineering & Configuration
Complete guides for Claude Code, OpenCode, Gemini CLI, Cursor, GitHub Copilot, and more. Tool-specific prompt patterns, configuration files, and setup guides for every major AI coding assistant.