Skip to main content
The Learnings API provides methods to store, retrieve, update, and delete learnings. Each learning captures a rule, mistake, and correction from your coding sessions.

Learning Interface

export interface Learning {
  id: number;                    // Auto-incrementing primary key
  created_at: string;            // ISO 8601 timestamp
  project: string | null;        // Project scope (null = global)
  category: string;              // e.g., "Testing", "Git", "Architecture"
  rule: string;                  // The corrected behavior
  mistake: string | null;        // What went wrong
  correction: string | null;     // How it was fixed
  times_applied: number;         // Usage counter
}
The times_applied counter tracks how often a learning is referenced. Use incrementTimesApplied() to update it.

Store Methods

All methods are available on the Store instance returned by createStore().

addLearning

learning
Omit<Learning, 'id' | 'created_at' | 'times_applied'>
required
Learning data to insert. id, created_at, and times_applied are auto-generated.
learning.project
string | null
Project name (e.g., "my-app") or null for global learnings.
learning.category
string
required
Category for grouping. Common values: Testing, Git, Editing, Architecture, Performance, Claude-Code.
learning.rule
string
required
One-line description of the correct behavior. This is the primary searchable field.
learning.mistake
string | null
What went wrong. Can be null for proactive learnings.
learning.correction
string | null
How the mistake was fixed. Can be null for proactive learnings.
return
Learning
The inserted learning with auto-generated id and created_at.
import { createStore } from 'pro-workflow';

const store = createStore();

const learning = store.addLearning({
  project: 'my-app',
  category: 'Testing',
  rule: 'Run tests after editing API endpoints',
  mistake: 'Pushed broken /users endpoint',
  correction: 'Added npm test to pre-push hook'
});

console.log(`Saved as learning #${learning.id}`);
store.close();

getLearning

id
number
required
Learning ID to retrieve.
return
Learning | undefined
The learning if found, otherwise undefined.
const learning = store.getLearning(42);
if (learning) {
  console.log(learning.rule);
}

getAllLearnings

project
string | undefined
Filter by project name. If omitted, returns all learnings.
return
Learning[]
Array of learnings sorted by created_at DESC.
When filtering by project, learnings with project: null are always included (global learnings).
const allLearnings = store.getAllLearnings();
console.log(`Total: ${allLearnings.length}`);

updateLearning

id
number
required
Learning ID to update.
updates
Partial<Learning>
required
Fields to update. Only category, rule, mistake, and correction can be updated.
return
boolean
true if the update succeeded, false if the learning was not found.
You cannot update id, created_at, project, or times_applied directly. Use incrementTimesApplied() for the counter.
const success = store.updateLearning(42, {
  rule: 'Run tests and lint before pushing',
  correction: 'Added npm run verify to pre-push hook'
});

if (success) {
  console.log('Learning updated');
}

deleteLearning

id
number
required
Learning ID to delete.
return
boolean
true if deleted, false if not found.
Deleting a learning automatically removes it from the FTS index via triggers.
const deleted = store.deleteLearning(42);
if (deleted) {
  console.log('Learning removed');
}

incrementTimesApplied

id
number
required
Learning ID to increment.
return
void
No return value. The counter is incremented atomically.
// Mark a learning as applied
store.incrementTimesApplied(42);
Use this when a learning is successfully applied in a session. Helps surface frequently-used patterns.

Categories

Recommended categories for consistency:
CategoryUse For
NavigationFile paths, finding code
EditingCode change patterns
TestingTest approaches, coverage
GitCommits, branches, merges
QualityLint, types, style
ContextWhen to clarify requirements
ArchitectureDesign decisions
PerformanceOptimization patterns
Claude-CodeSessions, modes, CLAUDE.md
PromptingScope, constraints, acceptance criteria
DebuggingRoot cause analysis
SecurityAuth, secrets, validation

Examples

// In a PostToolUse hook
import { createStore } from 'pro-workflow';

const store = createStore();

if (toolName === 'Edit' && output.includes('console.log')) {
  store.addLearning({
    project: process.env.PROJECT_NAME,
    category: 'Quality',
    rule: 'Remove console.log before committing',
    mistake: 'Left debug logging in production code',
    correction: 'Added eslint rule to catch console statements'
  });
}

store.close();

Next Steps

Search API

Full-text search for learnings

Sessions API

Track session activity

Commands

Use learnings in slash commands

Agents

Preload learnings into agents

Build docs developers (and LLMs) love