linear-sdk-patterns
TypeScript/JavaScript SDK patterns and best practices for Linear. Use when learning SDK idioms, implementing pagination, filtering, relation loading, or custom GraphQL queries. Trigger: "linear SDK patterns", "linear best practices", "linear typescript", "linear API patterns", "linear pagination".
Best use case
linear-sdk-patterns is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
TypeScript/JavaScript SDK patterns and best practices for Linear. Use when learning SDK idioms, implementing pagination, filtering, relation loading, or custom GraphQL queries. Trigger: "linear SDK patterns", "linear best practices", "linear typescript", "linear API patterns", "linear pagination".
Teams using linear-sdk-patterns should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/linear-sdk-patterns/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How linear-sdk-patterns Compares
| Feature / Agent | linear-sdk-patterns | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
TypeScript/JavaScript SDK patterns and best practices for Linear. Use when learning SDK idioms, implementing pagination, filtering, relation loading, or custom GraphQL queries. Trigger: "linear SDK patterns", "linear best practices", "linear typescript", "linear API patterns", "linear pagination".
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
Related Guides
AI Agents for Coding
Browse AI agent skills for coding, debugging, testing, refactoring, code review, and developer workflows across Claude, Cursor, and Codex.
Best AI Skills for Claude
Explore the best AI skills for Claude and Claude Code across coding, research, workflow automation, documentation, and agent operations.
ChatGPT vs Claude for Agent Skills
Compare ChatGPT and Claude for AI agent skills across coding, writing, research, and reusable workflow execution.
SKILL.md Source
# Linear SDK Patterns
## Overview
Production patterns for `@linear/sdk`. The SDK wraps Linear's GraphQL API with strongly-typed models, cursor-based pagination (`fetchNext()`/`fetchPrevious()`), lazy-loaded relations, and typed error classes. Understanding these patterns avoids N+1 queries and rate limit waste.
## Prerequisites
- `@linear/sdk` installed
- TypeScript project with `strict: true`
- Understanding of async/await and GraphQL concepts
## Instructions
### Pattern 1: Client Singleton
```typescript
import { LinearClient } from "@linear/sdk";
let _client: LinearClient | null = null;
export function getLinearClient(): LinearClient {
if (!_client) {
const apiKey = process.env.LINEAR_API_KEY;
if (!apiKey) throw new Error("LINEAR_API_KEY is required");
_client = new LinearClient({ apiKey });
}
return _client;
}
// For multi-user OAuth apps — one client per user
const clientCache = new Map<string, LinearClient>();
export function getClientForUser(userId: string, accessToken: string): LinearClient {
if (!clientCache.has(userId)) {
clientCache.set(userId, new LinearClient({ accessToken }));
}
return clientCache.get(userId)!;
}
```
### Pattern 2: Cursor-Based Pagination
Linear uses Relay-style cursor pagination. The SDK provides `fetchNext()` and `fetchPrevious()` helpers, plus raw `pageInfo` for manual control.
```typescript
// SDK built-in pagination helpers
const firstPage = await client.issues({ first: 50 });
console.log(`Page 1: ${firstPage.nodes.length} issues`);
if (firstPage.pageInfo.hasNextPage) {
const secondPage = await firstPage.fetchNext();
console.log(`Page 2: ${secondPage.nodes.length} issues`);
}
// Manual pagination with cursor — good for streaming all data
async function* paginateAll<T>(
fetchPage: (cursor?: string) => Promise<{
nodes: T[];
pageInfo: { hasNextPage: boolean; endCursor: string };
}>
): AsyncGenerator<T> {
let cursor: string | undefined;
let hasNext = true;
while (hasNext) {
const page = await fetchPage(cursor);
for (const node of page.nodes) yield node;
hasNext = page.pageInfo.hasNextPage;
cursor = page.pageInfo.endCursor;
}
}
// Stream all issues without loading everything into memory
for await (const issue of paginateAll(c => client.issues({ first: 50, after: c }))) {
console.log(`${issue.identifier}: ${issue.title}`);
}
```
### Pattern 3: Relation Loading (Avoiding N+1)
SDK models lazy-load relations. Accessing `.assignee` triggers a separate API call. Use raw GraphQL to batch-fetch relations in one request.
```typescript
// LAZY (N+1 problem) — each .assignee is a separate API call
const issues = await client.issues({ first: 50 });
for (const issue of issues.nodes) {
const assignee = await issue.assignee; // API call per issue!
console.log(`${issue.identifier}: ${assignee?.name}`);
}
// BATCH (1 request) — use rawRequest for precise field selection
const response = await client.client.rawRequest(`
query TeamIssues($teamKey: String!) {
issues(first: 50, filter: { team: { key: { eq: $teamKey } } }) {
nodes {
id identifier title priority
assignee { name email }
state { name type }
labels { nodes { name color } }
project { name }
}
}
}
`, { teamKey: "ENG" });
// PRE-RESOLVE — parallel resolution for a single issue
async function enrichIssue(issue: any) {
const [assignee, state, team, labels] = await Promise.all([
issue.assignee,
issue.state,
issue.team,
issue.labels(),
]);
return { ...issue, _assignee: assignee, _state: state, _team: team, _labels: labels.nodes };
}
```
### Pattern 4: Filtering with Comparators
Linear supports `eq`, `neq`, `in`, `nin`, `lt`, `lte`, `gt`, `gte`, `startsWith`, `contains`, and logical `and`/`or` operators.
```typescript
// High-priority open bugs
const bugs = await client.issues({
first: 50,
filter: {
priority: { lte: 2 },
state: { type: { nin: ["completed", "canceled"] } },
labels: { name: { eq: "Bug" } },
team: { key: { eq: "ENG" } },
},
});
// OR logic — issues assigned to Alice or Bob
const filtered = await client.issues({
filter: {
or: [
{ assignee: { email: { eq: "alice@company.com" } } },
{ assignee: { email: { eq: "bob@company.com" } } },
],
state: { type: { eq: "started" } },
},
});
// Full-text search
const results = await client.issueSearch("authentication bug");
// Issues updated in the last 24 hours
const recent = await client.issues({
filter: {
updatedAt: { gte: new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString() },
},
orderBy: "updatedAt",
first: 100,
});
```
### Pattern 5: Type-Safe Error Handling
```typescript
import { LinearError, InvalidInputLinearError } from "@linear/sdk";
type Result<T> = { ok: true; data: T } | { ok: false; error: string; retryable: boolean };
async function safeCall<T>(fn: () => Promise<T>): Promise<Result<T>> {
try {
return { ok: true, data: await fn() };
} catch (error) {
if (error instanceof InvalidInputLinearError) {
return { ok: false, error: `Invalid input: ${error.message}`, retryable: false };
}
if (error instanceof LinearError) {
const retryable = error.status === 429 || error.status === 503;
return { ok: false, error: `[${error.status}] ${error.message}`, retryable };
}
return { ok: false, error: String(error), retryable: false };
}
}
// Usage
const result = await safeCall(() => client.issue("issue-uuid"));
if (result.ok) {
console.log(result.data.title);
} else if (result.retryable) {
console.warn("Transient error, retry:", result.error);
}
```
### Pattern 6: Custom GraphQL Client
Access the underlying `LinearGraphQLClient` for full control.
```typescript
const graphQLClient = client.client;
// Set custom headers
graphQLClient.setHeader("X-Request-Id", crypto.randomUUID());
// Raw query with variables
const data = await graphQLClient.rawRequest(`
query Cycle($id: String!) {
cycle(id: $id) {
id name startsAt endsAt
issues { nodes { identifier title state { name } } }
}
}
`, { id: "cycle-uuid" });
// Batch mutations
const batchResult = await graphQLClient.rawRequest(`
mutation BatchUpdate {
a: issueUpdate(id: "id1", input: { priority: 1 }) { success }
b: issueUpdate(id: "id2", input: { priority: 1 }) { success }
c: issueUpdate(id: "id3", input: { priority: 1 }) { success }
}
`);
```
## Error Handling
| Error | Cause | Solution |
|-------|-------|----------|
| `Cannot read properties of null` | Nullable relation not checked | Use `(await issue.assignee)?.name` |
| `Type is not assignable` | SDK/TypeScript version mismatch | Update `@linear/sdk` to latest |
| `Promise rejection unhandled` | Missing try/catch on async | Wrap in `safeCall()` or `.catch()` |
| `Query complexity too high` | Too many nested relations | Use `rawRequest()` with flat field selection |
## Examples
### Create Issue with Full Metadata
```typescript
const teams = await client.teams();
const eng = teams.nodes.find(t => t.key === "ENG")!;
const states = await eng.states();
const todo = states.nodes.find(s => s.type === "unstarted")!;
const labels = await client.issueLabels({ filter: { name: { eq: "Bug" } } });
await client.createIssue({
teamId: eng.id,
title: "Login page crashes on Safari",
description: "## Steps to reproduce\n1. Open login in Safari 17\n2. Click Sign in\n3. Crash",
stateId: todo.id,
priority: 1,
labelIds: [labels.nodes[0].id],
estimate: 3,
});
```
## Resources
- [SDK Getting Started](https://linear.app/developers/sdk)
- [SDK Data Fetching](https://linear.app/developers/sdk-fetching-and-modifying-data)
- [SDK Error Handling](https://linear.app/developers/sdk-errors)
- [Advanced Usage](https://linear.app/developers/advanced-usage)
- [GraphQL Filtering](https://linear.app/developers/filtering)
- [Pagination](https://linear.app/developers/pagination)Related Skills
workhuman-sdk-patterns
Workhuman sdk patterns for employee recognition and rewards API. Use when integrating Workhuman Social Recognition, or building recognition workflows with HRIS systems. Trigger: "workhuman sdk patterns".
wispr-sdk-patterns
Wispr Flow sdk patterns for voice-to-text API integration. Use when integrating Wispr Flow dictation, WebSocket streaming, or building voice-powered applications. Trigger: "wispr sdk patterns".
windsurf-sdk-patterns
Apply production-ready Windsurf workspace configuration and Cascade interaction patterns. Use when configuring .windsurfrules, workspace rules, MCP servers, or establishing team coding standards for Windsurf AI. Trigger with phrases like "windsurf patterns", "windsurf best practices", "windsurf config patterns", "windsurfrules", "windsurf workspace".
windsurf-reliability-patterns
Implement reliable Cascade workflows with checkpoints, rollback, and incremental editing. Use when building fault-tolerant AI coding workflows, preventing Cascade from breaking builds, or establishing safe practices for multi-file AI edits. Trigger with phrases like "windsurf reliability", "cascade safety", "windsurf rollback", "cascade checkpoint", "safe cascade workflow".
webflow-sdk-patterns
Apply production-ready Webflow SDK patterns — singleton client, typed error handling, pagination helpers, and raw response access for the webflow-api package. Use when implementing Webflow integrations, refactoring SDK usage, or establishing team coding standards. Trigger with phrases like "webflow SDK patterns", "webflow best practices", "webflow code patterns", "idiomatic webflow", "webflow typescript".
vercel-sdk-patterns
Production-ready Vercel REST API patterns with typed fetch wrappers and error handling. Use when integrating with the Vercel API programmatically, building deployment tools, or establishing team coding standards for Vercel API calls. Trigger with phrases like "vercel SDK patterns", "vercel API wrapper", "vercel REST API client", "vercel best practices", "idiomatic vercel API".
vercel-reliability-patterns
Implement reliability patterns for Vercel deployments including circuit breakers, retry logic, and graceful degradation. Use when building fault-tolerant serverless functions, implementing retry strategies, or adding resilience to production Vercel services. Trigger with phrases like "vercel reliability", "vercel circuit breaker", "vercel resilience", "vercel fallback", "vercel graceful degradation".
veeva-sdk-patterns
Veeva Vault sdk patterns for REST API and clinical operations. Use when working with Veeva Vault document management and CRM. Trigger: "veeva sdk patterns".
vastai-sdk-patterns
Apply production-ready Vast.ai SDK patterns for Python and REST API. Use when implementing Vast.ai integrations, refactoring SDK usage, or establishing coding standards for GPU cloud operations. Trigger with phrases like "vastai SDK patterns", "vastai best practices", "vastai code patterns", "idiomatic vastai".
twinmind-sdk-patterns
Apply production-ready TwinMind SDK patterns for TypeScript and Python. Use when implementing TwinMind integrations, refactoring API usage, or establishing team coding standards for meeting AI integration. Trigger with phrases like "twinmind SDK patterns", "twinmind best practices", "twinmind code patterns", "idiomatic twinmind".
together-sdk-patterns
Together AI sdk patterns for inference, fine-tuning, and model deployment. Use when working with Together AI's OpenAI-compatible API. Trigger: "together sdk patterns".
techsmith-sdk-patterns
TechSmith sdk patterns for Snagit COM API and Camtasia automation. Use when working with TechSmith screen capture and video editing automation. Trigger: "techsmith sdk patterns".