/cohere-pack:cohere-local-dev-loopfrom cohere-pack
Sets up a local development workflow for Cohere API v2 with mocking, vitest testing, and hot reload. Useful for fast iteration without hitting production endpoints.
Ships in cohere-pack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Set up a fast, reproducible local development workflow with Cohere API v2 mocking, vitest testing, and hot reload.
cohere-install-auth setuptsx or ts-nodemy-cohere-project/
├── src/
│ ├── cohere/
│ │ ├── client.ts # CohereClientV2 wrapper
│ │ ├── chat.ts # Chat completions
│ │ ├── embed.ts # Embedding operations
│ │ └── rerank.ts # Reranking operations
│ └── index.ts
├── tests/
│ ├── chat.test.ts
│ ├── embed.test.ts
│ └── fixtures/
│ └── responses.ts # Mock API responses
├── .env.local # Local secrets (git-ignored)
├── .env.example # Template for team
└── package.json
{
"scripts": {
"dev": "tsx watch src/index.ts",
"test": "vitest",
"test:watch": "vitest --watch",
"test:integration": "COHERE_INTEGRATION=1 vitest --run"
},
"dependencies": {
"cohere-ai": "^7.0.0"
},
"devDependencies": {
"tsx": "^4.0.0",
"vitest": "^2.0.0",
"typescript": "^5.5.0"
}
}
// src/cohere/client.ts
import { CohereClientV2 } from 'cohere-ai';
let instance: CohereClientV2 | null = null;
export function getCohere(): CohereClientV2 {
if (!instance) {
instance = new CohereClientV2({
token: process.env.CO_API_KEY,
});
}
return instance;
}
// Reset for testing
export function resetClient(): void {
instance = null;
}
// tests/fixtures/responses.ts
export const mockChatResponse = {
id: 'test-chat-id',
message: {
role: 'assistant' as const,
content: [{ type: 'text' as const, text: 'Mocked response' }],
},
finishReason: 'COMPLETE' as const,
usage: { billedUnits: { inputTokens: 10, outputTokens: 5 } },
};
export const mockEmbedResponse = {
id: 'test-embed-id',
embeddings: {
float: [[0.1, 0.2, 0.3, 0.4]], // truncated for dev
},
meta: { billedUnits: { inputTokens: 4 } },
};
export const mockRerankResponse = {
id: 'test-rerank-id',
results: [
{ index: 0, relevanceScore: 0.95 },
{ index: 2, relevanceScore: 0.72 },
],
meta: { billedUnits: { searchUnits: 1 } },
};
// tests/chat.test.ts
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { mockChatResponse } from './fixtures/responses';
vi.mock('cohere-ai', () => ({
CohereClientV2: vi.fn().mockImplementation(() => ({
chat: vi.fn().mockResolvedValue(mockChatResponse),
chatStream: vi.fn().mockReturnValue({
[Symbol.asyncIterator]: async function* () {
yield { type: 'content-delta', delta: { message: { content: { text: 'Hi' } } } };
},
}),
embed: vi.fn().mockResolvedValue({ embeddings: { float: [[0.1, 0.2]] } }),
rerank: vi.fn().mockResolvedValue({
results: [{ index: 0, relevanceScore: 0.9 }],
}),
})),
}));
describe('Cohere Chat', () => {
it('should return a chat completion', async () => {
const { CohereClientV2 } = await import('cohere-ai');
const cohere = new CohereClientV2();
const result = await cohere.chat({
model: 'command-a-03-2025',
messages: [{ role: 'user', content: 'test' }],
});
expect(result.message?.content?.[0]?.text).toBe('Mocked response');
expect(result.finishReason).toBe('COMPLETE');
});
});
// tests/integration.test.ts
import { describe, it, expect } from 'vitest';
import { CohereClientV2 } from 'cohere-ai';
const shouldRun = process.env.COHERE_INTEGRATION === '1';
describe.skipIf(!shouldRun)('Cohere Integration', () => {
const cohere = new CohereClientV2();
it('chat endpoint responds', async () => {
const res = await cohere.chat({
model: 'command-r7b-12-2024', // cheapest model for tests
messages: [{ role: 'user', content: 'Say OK' }],
maxTokens: 5,
});
expect(res.message?.content?.[0]?.text).toBeTruthy();
}, 15_000);
it('embed endpoint responds', async () => {
const res = await cohere.embed({
model: 'embed-v4.0',
texts: ['test'],
inputType: 'search_document',
embeddingTypes: ['float'],
});
expect(res.embeddings.float[0].length).toBeGreaterThan(0);
}, 15_000);
});
# .env.example (commit this)
CO_API_KEY=your-trial-key-here
# .env.local (git-ignored, used by tsx/vitest)
CO_API_KEY=actual-key
# .gitignore entries
.env.local
.env.*.local
tsx watchCOHERE_INTEGRATION=1| Error | Cause | Solution |
|---|---|---|
vi.mock not working | Wrong import order | Mock before importing modules |
CO_API_KEY undefined | .env not loaded | Use dotenv/config or tsx env support |
| Integration test timeout | Slow network | Increase timeout to 15s+ |
| Type mismatch on mock | API shape changed | Update fixtures to match SDK types |
See cohere-sdk-patterns for production-ready code patterns.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
24 skills in this plugin
/cohere-ci-integrationConfigure CI/CD for Cohere integrations with GitHub Actions and automated testing.
Use when setting up automated testing for Chat/Embed/Rerank,
configuring CI pipelines, or testing Cohere-powered applications.
Trigger with phrases like "cohere CI", "cohere GitHub Actions",
"cohere automated tests", "CI cohere", "cohere pipeline".
/cohere-common-errorsDiagnose and fix Cohere API v2 errors and exceptions.
Use when encountering Cohere errors, debugging failed requests,
or troubleshooting CohereError, CohereTimeoutError, rate limits.
Trigger with phrases like "cohere error", "fix cohere",
"cohere not working", "debug cohere", "cohere 429", "cohere 400".
/cohere-core-workflow-aBuild a complete RAG pipeline with Cohere Chat, Embed, and Rerank.
Use when implementing retrieval-augmented generation, building
grounded Q&A systems, or combining search with LLM generation.
Trigger with phrases like "cohere RAG", "cohere retrieval",
"cohere grounded generation", "cohere search and answer".
/cohere-core-workflow-bBuild tool-use agents and function calling with Cohere API v2.
Use when implementing multi-step agents, function calling,
or building autonomous tool-using workflows with Cohere.
Trigger with phrases like "cohere tool use", "cohere agents",
"cohere function calling", "cohere multi-step".
/cohere-cost-tuningOptimize Cohere costs through model selection, token budgets, and usage monitoring.
Use when analyzing Cohere billing, reducing API costs,
or implementing usage monitoring and budget alerts.
Trigger with phrases like "cohere cost", "cohere billing",
"reduce cohere costs", "cohere pricing", "cohere expensive", "cohere budget".
/cohere-data-handlingImplement data privacy for Cohere API calls with PII redaction and compliance.
Use when handling sensitive data, implementing PII redaction before API calls,
or ensuring GDPR/CCPA compliance with Cohere integrations.
Trigger with phrases like "cohere data", "cohere PII",
"cohere GDPR", "cohere data retention", "cohere privacy", "cohere redact".
npx claudepluginhub flight505/skill-forge --plugin cohere-packOther plugins' skills for the same job