Context Hub

Curated, Versioned Context for AI Coding Agents

andrewyng/context-hub · 11.2k stars · JavaScript

agent37.club

The Problem: Agent Amnesia & Hallucination

Two fundamental failures plague every AI coding agent:

API Hallucination

Agents generate plausible-looking but non-existent function signatures, parameters, and return types. The code compiles in their imagination, not in reality.

Session Amnesia

Every conversation starts from zero. Workarounds discovered at 2am are forgotten by morning. There is no persistent memory between sessions.

What this looks like in practice

# Agent confidently writes:
from stripe import PaymentProcessor

# This class doesn't exist.
# The real import is:
import stripe
stripe.PaymentIntent.create()

# Agent discovers this, fixes it.
# Next session? Same mistake.

What is Context Hub?

"Curated, versioned docs, plus the ability to get smarter with every task."
  • A CLI tool (@aisuite/chub) published to npm
  • A content repository of markdown documentation with YAML frontmatter
  • A feedback system connecting agent usage to content quality
  • A local annotation store for persistent cross-session learning

Key principle: Transparency

All content is plain markdown on GitHub. Users can inspect exactly what their agents read — no black boxes.

Architecture Overview

CLI Tool (chub)Node.js ≥ 18 · npm package
Local Annotation StorePersistent notes · per-doc
Content RepositoryMarkdown + YAML · GitHub
Feedback Pipelineup/down votes → authors
Agent IntegrationSKILL.md · Claude Code / etc.

All five layers work together to create a self-improving documentation system.

CLI Command Reference

Command Purpose Key Flags
chub search [query] Discover available docs/skills Empty query lists all
chub get <id> Fetch documentation by ID --lang py|js, --file, --full
chub annotate <id> <note> Attach persistent local note --clear, --list
chub feedback <id> up|down Rate doc quality for authors
chub help Show all commands and usage

Design for agents, not humans

The CLI output is structured for LLM consumption. Agents are prompted to run chub help to self-discover capabilities.

Search & Discovery

How agents find documentation

# Broad search
$ chub search "stripe"

Found 3 results:
  stripe/api        Stripe API reference
  stripe/webhooks   Webhook handling guide
  stripe/checkout   Checkout integration

# List everything available
$ chub search

All available content (47 items):
  openai/chat       OpenAI Chat Completions
  openai/embeddings Embedding API
  stripe/api        Stripe API reference
  ...

Search is the entry point

  • Text-based query matching against doc IDs and descriptions
  • Returns structured list of available content
  • Agents use this to decide which docs to fetch
  • Empty query = browse all available content

Token efficiency

Search returns only IDs and descriptions — not full content. The agent decides what to fetch.

Incremental Fetch

Retrieve only what you need

# Default: main doc only
$ chub get openai/chat --lang py

# Specific reference file
$ chub get openai/chat --file streaming

# Everything (all references)
$ chub get openai/chat --full

Each doc can have multiple reference files — the agent fetches only the section relevant to its current task.

Why this matters

Full web page
~15,000 tokens
chub --full
~6,000 tokens
chub --file
~2,000 tokens
chub default
~3,500 tokens

Approximate token counts for typical API documentation.

Language Variants

Same API, different languages

# Python variant
$ chub get openai/chat --lang py

# JavaScript variant
$ chub get openai/chat --lang js

Documentation is maintained per-language, not as a one-size-fits-all reference. Each variant includes:

  • Language-idiomatic code examples
  • Correct import paths and package names
  • Language-specific gotchas and patterns

Why this prevents hallucination

When an agent asks for the Python Stripe docs, it gets the exact import stripe pattern — not the JavaScript require('stripe') mixed in.

Language confusion is one of the top sources of hallucinated APIs.

Annotations: Persistent Memory

How agents learn across sessions

# Agent discovers a gotcha
$ chub annotate stripe/webhooks \
  "Must use raw request body, not
   parsed JSON, for signature
   verification. See: express
   raw() middleware."

# Next session: annotation appears
# automatically when fetching docs
$ chub get stripe/webhooks

[Content + local annotations shown]

# Manage annotations
$ chub annotate --list
$ chub annotate stripe/webhooks --clear

Key properties

  • Local storage — annotations live on your machine, not the server
  • Auto-surfaced — they appear every time you fetch that doc
  • Per-document — each doc ID has its own annotation list
  • Agent-written — designed for agents to write, not humans

The breakthrough

This turns a stateless tool into a stateful knowledge base. Each project accumulates tribal knowledge that persists indefinitely.

Feedback Pipeline

Community-driven quality

# Agent found docs helpful
$ chub feedback openai/chat up

# Agent found docs incomplete
$ chub feedback stripe/api down

Votes are aggregated and surfaced to content authors. This creates a signal for which docs need improvement.

The feedback loop

Agent uses docs
Fetches content, writes code
Agent votes
Up if code worked, down if not
Authors see metrics
Aggregated quality signals
Content improves
PRs fix gaps, add examples

Content Format

Markdown + YAML frontmatter

---
id: openai/chat
title: Chat Completions API
version: 2024.1
languages: [py, js]
references:
  - streaming
  - function-calling
  - vision
---

# Chat Completions

Create chat completions using
the OpenAI API...

## Basic Usage
...

Repository structure

content/
  openai/
    chat/
      index.md        # main doc
      py.md           # Python variant
      js.md           # JS variant
      streaming.md    # reference file
      function-calling.md
  stripe/
    api/
      index.md
      py.md
      webhooks.md

Contribution model

Submit content via pull requests. API providers, framework authors, and community members all contribute.

Agent Integration

SKILL.md pattern

Agents discover Context Hub through a skill file that teaches them when and how to use it:

# For Claude Code:
mkdir -p ~/.claude/skills/get-api-docs
cp SKILL.md ~/.claude/skills/get-api-docs/

# The SKILL.md tells the agent:
# 1. When to use chub (API questions)
# 2. How to search and fetch
# 3. When to annotate findings
# 4. When to provide feedback

Workflow inside an agent session

User: "Add Stripe payments to my app"
Agent runs: chub search stripe
Agent runs: chub get stripe/api --lang js
Agent writes code using correct APIs
Agent annotates any gaps discovered

The Self-Improving Loop

Two layers of improvement working simultaneously

Local: Annotations

Scope: Your machine, your projects

Speed: Immediate — available next session

Content: Workarounds, gotchas, project-specific notes

Think of it as the agent's personal notebook. Each project accumulates its own knowledge base.

Global: Feedback

Scope: All users of Context Hub

Speed: Slower — requires author action

Content: Quality signals, missing sections, incorrect examples

Aggregated votes guide authors toward the highest-impact improvements. Everyone benefits.

Combined effect

Local annotations handle the long tail of project-specific knowledge. Global feedback improves the shared baseline for everyone. Both together create a system that gets better at every scale.

Token Economics

Why curated context beats raw web scraping

Source Tokens Signal:Noise
Full web page ~15k Low (ads, nav, boilerplate)
Raw API docs ~10k Medium (all endpoints)
Context Hub full ~6k High (curated)
Context Hub targeted ~2k Very high (specific section)

The math

A typical coding session might reference 5-10 APIs. At 15k tokens each from web scraping, that is 75-150k tokens of context consumed.

With Context Hub targeted fetch: 10-20k tokens. That is a 7-8x reduction in context window consumption.

Context Hub vs. Alternatives

Approach Accuracy Persistence Token Cost Maintenance
Training data only Hallucinations None Zero None
Web search (RAG) Variable None High None
Copy-paste in prompt Good Manual Very high Heavy
Context Hub Curated Annotations Low Community

The sweet spot

Context Hub sits between "trust the model's memory" (cheap but unreliable) and "paste everything into the prompt" (accurate but expensive). It gives agents on-demand access to verified knowledge.

Under the Hood

Technology stack

  • Runtime: Node.js ≥ 18
  • Package: @aisuite/chub on npm
  • Content: GitHub repo (markdown + YAML)
  • Local store: File-based annotation persistence
  • Language: 100% JavaScript

Installation

npm install -g @aisuite/chub

# Verify
chub --version
chub help

How fetch works

// Simplified flow:

// 1. Parse doc ID + flags
const { id, lang, file } = parseArgs();

// 2. Resolve content path
const path = resolve(
  `content/${id}/${lang || 'index'}.md`
);

// 3. Fetch from GitHub
const content = await fetchContent(path);

// 4. Merge local annotations
const annotations = getAnnotations(id);

// 5. Return combined output
return format(content, annotations);

The aisuite Ecosystem

Context Hub is part of Andrew Ng's aisuite project — a collection of tools for building reliable AI agents.

  • aisuite — unified API for multiple LLM providers
  • context-hub — curated docs for agents (this talk)

The philosophy: agents need infrastructure, not just prompts. Better tools make better agents.

Andrew Ng's thesis

"Agentic AI is the next frontier. But agents need reliable knowledge retrieval, not just bigger models."

Context Hub embodies this: improve agent output by improving agent inputs.

Practical Example

Building a Stripe checkout flow with an AI agent

Without Context Hub

# Agent hallucinates:
from stripe.checkout import Session

session = Session("price_123")
session.redirect_url = "/success"
session.create()

# ImportError: No module named
# 'stripe.checkout'

# Agent tries 3 more wrong versions
# before getting it right...

With Context Hub

# Agent fetches docs first:
# $ chub get stripe/checkout --lang py

import stripe

session = stripe.checkout.Session.create(
  line_items=[{
    "price": "price_123",
    "quantity": 1,
  }],
  mode="payment",
  success_url="https://...",
)
# Works on first try.

Contributing Content

Who should contribute?

  • API providers — ship docs that agents can actually consume correctly
  • Framework authors — ensure agents use your library's idiomatic patterns
  • Developers — fix the gaps and gotchas you discover while coding
  • Companies — reduce support tickets by giving agents correct answers

How to contribute

# 1. Fork the repo
git clone andrewyng/context-hub

# 2. Add content
mkdir -p content/myapi/
# Write markdown with YAML frontmatter

# 3. Submit PR
git push && gh pr create

# Content guide in repo explains
# frontmatter format and conventions

Key Design Decisions

Markdown, not a database

Content is plain text in a Git repo. Anyone can read it, diff it, review it. No proprietary format, no vendor lock-in.

CLI, not an API

Agents already have shell access. A CLI is the simplest interface — no authentication, no API keys, no rate limits to manage.

Local annotations, not cloud sync

Privacy by default. Your agent's notes never leave your machine. No accounts, no telemetry on content.

Incremental fetch, not bulk download

Token budgets are real constraints. Fetching only what you need is not just efficient — it keeps the agent focused.

Limitations & Challenges

Current limitations

  • Content coverage — still growing; not every API is documented yet
  • Staleness risk — docs can fall behind API changes if not maintained
  • Node.js dependency — requires Node 18+ installed on the system
  • Discovery — agents need the SKILL.md to know Context Hub exists

Open questions

  • How to handle version conflicts when APIs change frequently?
  • Can annotations be shared across teams while preserving privacy?
  • How to scale curation as the content library grows?
  • Should agents be able to auto-contribute docs from their discoveries?

What's Next

Planned expansions

Agent Skills
Not just docs — executable skill templates agents can use directly
More Languages
Beyond Python and JavaScript to Rust, Go, TypeScript, etc.
Richer Feedback
Beyond up/down — structured reports on what was missing or wrong
Community Growth
986 forks already — scaling contribution and review workflows

The bigger picture

Context Hub is an early example of agent infrastructure — tools built not for humans to use, but for AI agents to use.

As agents become more capable, the bottleneck shifts from model intelligence to reliable knowledge retrieval. This is the infrastructure layer being built.

Key Takeaways

1. Context quality determines agent quality

Better inputs beat bigger models. Curated docs eliminate hallucination at the source.

2. Persistence is the missing piece

Annotations turn stateless agents into learning systems. Knowledge accumulates across sessions.

3. Community curation scales

The open-source model that works for code also works for agent knowledge. Feedback loops keep content fresh.

4. Agent infrastructure is a new category

Tools designed for agents (not humans) to use. Context Hub is early but points to where the ecosystem is heading.

Context Hub

Curated, Versioned Context for AI Coding Agents

npm install -g @aisuite/chub

github.com/andrewyng/context-hub

agent37.club