AGENT SKILL

linear-sdk-patterns

TypeScript/JavaScript SDK patterns and best practices for Linear. Use when learning SDK idioms, implementing common patterns, or optimizing Linear API usage. Trigger with phrases like "linear SDK patterns", "linear best practices", "linear typescript", "linear API patterns", "linear SDK idioms".

License 许可
MIT
最近更新
2026-11-15
Stars
★ 2.0k
Forks
233

01 前言 Front Matter

name
linear-sdk-patterns
author
Jeremy Longshore <jeremy@intentsolutions.io>
license
MIT
version
1.0.0
description
TypeScript/JavaScript SDK patterns and best practices for Linear. Use when learning SDK idioms, implementing common patterns, or optimizing Linear API usage. Trigger with phrases like "linear SDK patterns", "linear best practices", "linear typescript", "linear API patterns", "linear SDK idioms".
allowed-tools
Read, Write, Edit, Grep

03 SKILL.md 正文

Linear SDK Patterns

Overview

Essential patterns and best practices for working with the Linear SDK.

Prerequisites

  • Linear SDK installed and configured
  • TypeScript project setup
  • Understanding of async/await patterns

Core Patterns

Pattern 1: Client Singleton

// lib/linear.ts
import { LinearClient } from "@linear/sdk";

let client: LinearClient | null = null;

export function getLinearClient(): LinearClient {
  if (!client) {
    if (!process.env.LINEAR_API_KEY) {
      throw new Error("LINEAR_API_KEY environment variable not set");
    }
    client = new LinearClient({
      apiKey: process.env.LINEAR_API_KEY,
    });
  }
  return client;
}

Pattern 2: Pagination Handling

import { LinearClient, Issue, IssueConnection } from "@linear/sdk";

async function* getAllIssues(
  client: LinearClient,
  filter?: Record<string, unknown>
): AsyncGenerator<Issue> {
  let hasNextPage = true;
  let endCursor: string | undefined;

  while (hasNextPage) {
    const connection: IssueConnection = await client.issues({
      filter,
      first: 50, // Max per page
      after: endCursor,
    });

    for (const issue of connection.nodes) {
      yield issue;
    }

    hasNextPage = connection.pageInfo.hasNextPage;
    endCursor = connection.pageInfo.endCursor;
  }
}

// Usage
for await (const issue of getAllIssues(client, { state: { name: { eq: "Todo" } } })) {
  console.log(issue.identifier, issue.title);
}

Pattern 3: Error Handling Wrapper

import { LinearClient, LinearError } from "@linear/sdk";

interface LinearResult<T> {
  success: boolean;
  data?: T;
  error?: {
    message: string;
    code?: string;
    retryable: boolean;
  };
}

async function linearOperation<T>(
  operation: () => Promise<T>
): Promise<LinearResult<T>> {
  try {
    const data = await operation();
    return { success: true, data };
  } catch (error) {
    if (error instanceof LinearError) {
      return {
        success: false,
        error: {
          message: error.message,
          code: error.type,
          retryable: error.type === "RateLimitedError",
        },
      };
    }
    return {
      success: false,
      error: {
        message: error instanceof Error ? error.message : "Unknown error",
        retryable: false,
      },
    };
  }
}

// Usage
const result = await linearOperation(() => client.createIssue({
  teamId: team.id,
  title: "New issue",
}));

if (result.success) {
  console.log("Issue created:", result.data);
} else if (result.error?.retryable) {
  // Implement retry logic
}

Pattern 4: Batch Operations

async function batchUpdateIssues(
  client: LinearClient,
  issueIds: string[],
  update: { stateId?: string; priority?: number }
): Promise<{ success: number; failed: number }> {
  const results = await Promise.allSettled(
    issueIds.map(id => client.updateIssue(id, update))
  );

  return {
    success: results.filter(r => r.status === "fulfilled").length,
    failed: results.filter(r => r.status === "rejected").length,
  };
}

Pattern 5: Caching Layer

interface CacheEntry<T> {
  data: T;
  expiresAt: number;
}

class LinearCache {
  private cache = new Map<string, CacheEntry<unknown>>();
  private ttl: number;

  constructor(ttlSeconds = 60) {
    this.ttl = ttlSeconds * 1000;
  }

  async get<T>(key: string, fetcher: () => Promise<T>): Promise<T> {
    const cached = this.cache.get(key) as CacheEntry<T> | undefined;

    if (cached && cached.expiresAt > Date.now()) {
      return cached.data;
    }

    const data = await fetcher();
    this.cache.set(key, { data, expiresAt: Date.now() + this.ttl });
    return data;
  }

  invalidate(key: string): void {
    this.cache.delete(key);
  }
}

// Usage
const cache = new LinearCache(300); // 5 minute TTL

const teams = await cache.get("teams", () => client.teams());

Pattern 6: Type-Safe Filters

import { IssueFilter } from "@linear/sdk";

function buildIssueFilter(options: {
  teamKeys?: string[];
  states?: string[];
  assigneeId?: string;
  priority?: number[];
}): IssueFilter {
  const filter: IssueFilter = {};

  if (options.teamKeys?.length) {
    filter.team = { key: { in: options.teamKeys } };
  }

  if (options.states?.length) {
    filter.state = { name: { in: options.states } };
  }

  if (options.assigneeId) {
    filter.assignee = { id: { eq: options.assigneeId } };
  }

  if (options.priority?.length) {
    filter.priority = { in: options.priority };
  }

  return filter;
}

Output

  • Reusable client singleton
  • Pagination iterator for large datasets
  • Type-safe error handling
  • Efficient batch operations
  • Caching for performance

Error Handling

Error Cause Solution
Type mismatch SDK version incompatibility Update @linear/sdk package
Undefined property Nullable field access Use optional chaining (?.)
Promise rejection Unhandled async error Wrap in try/catch or use wrapper

Resources

Next Steps

Apply these patterns in linear-core-workflow-a for issue management.

04 同仓库更多 Skills

Dicklesworthstone
Dicklesworthstone/pi_agent_rust

theme-factory

Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with colors/fonts that you can apply to any artifact that has been creating, or can generate a new theme on-the-fly.

视觉设计
★ 2.0k
Dicklesworthstone
Dicklesworthstone/pi_agent_rust

web-artifacts-builder

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

前端开发
★ 2.0k
Dicklesworthstone
Dicklesworthstone/pi_agent_rust

webapp-testing

Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.

测试与质量前端开发
★ 2.0k
Dicklesworthstone
Dicklesworthstone/pi_agent_rust

neuropixels-analysis

Neuropixels neural recording analysis. Load SpikeGLX/OpenEphys data, preprocess, motion correction, Kilosort4 spike sorting, quality metrics, Allen/IBL curation, AI-assisted visual analysis, for Neuropixels 1.0/2.0 extracellular electrophysiology. Use when working with neural recordings, spike sorting, extracellular electrophysiology, or when the user mentions Neuropixels, SpikeGLX, Open Ephys, Kilosort, quality metrics, or unit curation.

★ 2.0k
Dicklesworthstone
Dicklesworthstone/pi_agent_rust

skill-creator

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

Skill与智能体开发
★ 2.0k
Dicklesworthstone
Dicklesworthstone/pi_agent_rust

notebooklm

Use this skill to query your Google NotebookLM notebooks directly from Claude Code for source-grounded, citation-backed answers from Gemini. Browser automation, library management, persistent auth. Drastically reduced hallucinations through document-only responses.

Skill与智能体开发
★ 2.0k