Context Management
ctx add¶
Add a new item to a context file.
Types:
| Type | Target File |
|---|---|
task |
TASKS.md |
decision |
DECISIONS.md |
learning |
LEARNINGS.md |
convention |
CONVENTIONS.md |
Flags:
| Flag | Short | Description |
|---|---|---|
--priority <level> |
-p |
Priority for tasks: high, medium, low |
--section <name> |
-s |
Target section within file |
--context |
-c |
Context (required for decisions and learnings) |
--rationale |
-r |
Rationale for decisions (required for decisions) |
--consequences |
Consequences for decisions (required for decisions) | |
--lesson |
-l |
Key insight (required for learnings) |
--application |
-a |
How to apply going forward (required for learnings) |
--file |
-f |
Read content from file instead of argument |
Examples:
# Add a task
ctx add task "Implement user authentication"
ctx add task "Fix login bug" --priority high
# Record a decision (requires all ADR (Architectural Decision Record) fields)
ctx add decision "Use PostgreSQL for primary database" \
--context "Need a reliable database for production" \
--rationale "PostgreSQL offers ACID compliance and JSON support" \
--consequences "Team needs PostgreSQL training"
# Note a learning (requires context, lesson, and application)
ctx add learning "Vitest mocks must be hoisted" \
--context "Tests failed with undefined mock errors" \
--lesson "Vitest hoists vi.mock() calls to top of file" \
--application "Always place vi.mock() before imports in test files"
# Add to specific section
ctx add convention "Use kebab-case for filenames" --section "Naming"
ctx complete¶
Mark a task as completed.
Arguments:
task-id-or-text: Task number or partial text match
Examples:
ctx drift¶
Detect stale or invalid context.
Flags:
| Flag | Description |
|---|---|
--json |
Output machine-readable JSON |
--fix |
Auto-fix simple issues |
Checks:
- Path references in
ARCHITECTURE.mdandCONVENTIONS.mdexist - Task references are valid
- Constitution rules aren't violated (heuristic)
- Staleness indicators (old files, many completed tasks)
- Missing packages: warns when
internal/directories exist on disk but are not referenced inARCHITECTURE.md(suggests running/ctx-map) - Entry count: warns when
LEARNINGS.mdorDECISIONS.mdexceed configurable thresholds (default: 30 learnings, 20 decisions), or whenCONVENTIONS.mdexceeds a line count threshold (default: 200). Configure via.ctxrc:
Example:
Exit codes:
| Code | Meaning |
|---|---|
| 0 | All checks passed |
| 1 | Warnings found |
| 3 | Violations found |
ctx sync¶
Reconcile context with the current codebase state.
Flags:
| Flag | Description |
|---|---|
--dry-run |
Show what would change without modifying |
What it does:
- Scans codebase for structural changes
- Compares with ARCHITECTURE.md
- Suggests documenting dependencies if package files exist
- Identifies stale or outdated context
Example:
ctx compact¶
Consolidate and clean up context files.
- Moves completed tasks older than 7 days to the archive
- Removes empty sections
Flags:
| Flag | Description |
|---|---|
--archive |
Create .context/archive/ for old content |
Example:
ctx tasks¶
Manage task archival and snapshots.
ctx tasks archive¶
Move completed tasks from TASKS.md to a timestamped archive file.
Flags:
| Flag | Description |
|---|---|
--dry-run |
Preview changes without modifying files |
Archive files are stored in .context/archive/ with timestamped names
(tasks-YYYY-MM-DD.md). Completed tasks (marked with [x]) are moved;
pending tasks ([ ]) remain in TASKS.md.
Example:
ctx tasks snapshot¶
Create a point-in-time snapshot of TASKS.md without modifying the original.
Arguments:
name: Optional name for the snapshot (defaults to "snapshot")
Snapshots are stored in .context/archive/ with timestamped names
(tasks-<name>-YYYY-MM-DD-HHMM.md).
Example:
ctx permissions¶
Manage Claude Code permission snapshots.
ctx permissions snapshot¶
Save .claude/settings.local.json as the golden image.
Creates .claude/settings.golden.json as a byte-for-byte copy of the
current settings. Overwrites if the golden file already exists.
The golden file is meant to be committed to version control and shared with the team.
Example:
ctx permissions restore¶
Replace settings.local.json with the golden image.
Prints a diff of dropped (session-accumulated) and restored permissions. No-op if the files already match.
Example:
ctx permissions restore
# Dropped 3 session permission(s):
# - Bash(cat /tmp/debug.log:*)
# - Bash(rm /tmp/test-*:*)
# - Bash(curl https://example.com:*)
# Restored from golden image.
ctx reindex¶
Regenerate the quick-reference index for both DECISIONS.md and LEARNINGS.md
in a single invocation.
This is a convenience wrapper around ctx decisions reindex and
ctx learnings reindex. Both files grow at similar rates and users
typically want to reindex both after manual edits.
The index is a compact table of date and title for each entry, allowing AI tools to scan entries without reading the full file.
Example:
ctx decisions¶
Manage the DECISIONS.md file.
ctx decisions reindex¶
Regenerate the quick-reference index at the top of DECISIONS.md.
The index is a compact table showing the date and title for each decision, allowing AI tools to quickly scan entries without reading the full file.
Use this after manual edits to DECISIONS.md or when migrating existing
files to use the index format.
Example:
ctx learnings¶
Manage the LEARNINGS.md file.
ctx learnings reindex¶
Regenerate the quick-reference index at the top of LEARNINGS.md.
The index is a compact table showing the date and title for each learning, allowing AI tools to quickly scan entries without reading the full file.
Use this after manual edits to LEARNINGS.md or when migrating existing
files to use the index format.
Example: