Skip to content
FunCoding

skill-design-lineage

Persist design documents with branch tracking, revision chains, and cross-session discovery

Star
4,525
License
MIT
Last commit
Dec 2, 2026

codex-skills/skill-design-lineage/SKILL.md

View on GitHub

Host: Codex CLI — This skill was designed for Claude Code and adapted for Codex. Invoke installed skills by their $skill-name. Known Octopus commands are mapped below. A remaining /octo:* reference is a Claude Code command; do not execute it in Codex or invent an equivalent. Before the first helper call, derive the absolute plugin root from this loaded skill's path by finding its ancestor containing .codex-plugin/plugin.json. Verify that root, bind OCTO_ROOT, CODEX_PLUGIN_ROOT, and CLAUDE_PLUGIN_ROOT to the same root, and export all three in each fresh shell before launching child processes. Use the verified absolute helper path when needed. Do not infer the root from the user's project or assume exports survive tool calls. Stop and report a missing installation if the root cannot be verified. Use the active Codex shell and subagent tools. Do not claim a provider, model, or host subagent is available until the current session exposes it. Claude-native tool calls in examples are prompt templates to adapt, not Codex call signatures. If a mandatory verification agent or tool is unavailable or unauthorized, report that verification did not run and stop the affected completion step. Never claim a skipped check passed. Attribute commits only to actual contributors; do not copy fixed model attribution trailers from examples. For host tool equivalents, see codex-skills/blocks/codex-host-adapter.md.

Invoke this entry as $skill-design-lineage in Codex. Code-fenced Claude command examples are reference text, not Codex shell commands.

Design Document Lineage

When a design introduces or changes domain terms, load codex-skills/blocks/domain-modeling.md. Record each definition in the existing design lineage artifact with its evidence source, checked time, and scope. A changed definition invalidates dependent decisions. Link and reopen them instead of leaving stale implementation guidance marked current.

Overview

Persist design documents from brainstorming and planning sessions with branch tracking, revision chains, and cross-session discoverability. Design docs are immutable after creation -- new revisions supersede prior versions rather than editing in place.

Storage Location

All design documents are stored under:

~/.claude-octopus/designs/<project-slug>/

The project slug is derived from the current git repository name or working directory basename:

SLUG=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")
DESIGNS_DIR="${HOME}/.claude-octopus/designs/${SLUG}"
mkdir -p "$DESIGNS_DIR"

Filename Format

Design documents follow a strict naming convention:

{user}-{branch}-design-{datetime}.md

Where:

  • {user} -- the current OS username ($USER or whoami)
  • {branch} -- the current git branch with slashes replaced with dashes, or no-branch if Git cannot resolve HEAD
  • {datetime} -- ISO 8601 compact timestamp (YYYYMMDD-HHmmss)

If that filename already exists, the new design adds a unique suffix before .md. Both documents remain available in the revision history.

Example:

chris-feature-auth-refactor-design-20260321-143022.md

Resolution:

BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || BRANCH=no-branch
BRANCH_SLUG=${BRANCH//\//-}
DATETIME=$(date -u +"%Y%m%d-%H%M%S") || exit 1
FILENAME="${USER}-${BRANCH_SLUG}-design-${DATETIME}.md"

Design Document Template

Each design document contains YAML frontmatter followed by structured sections.

Frontmatter Metadata

---
branch: feature/auth-refactor
user: chris
created: 2026-03-21T14:30:22Z
supersedes: chris-feature-auth-refactor-design-20260320-091500.md
---

Fields:

  • branch -- the git branch at time of creation
  • user -- the OS username who created the document
  • created -- ISO 8601 timestamp of creation
  • supersedes -- filename of the prior design document this revision replaces (omitted if this is the first design for the branch)

Document Sections

# Design: [Title]

## Problem Statement
[What problem does this design solve? Why does it matter?]

## Constraints
[Technical, timeline, resource, or organizational constraints that bound the solution space.]

## Approaches Considered
[List each approach evaluated, with brief pros/cons for each.]

### Approach A: [Name]
- **Pros:** ...
- **Cons:** ...

### Approach B: [Name]
- **Pros:** ...
- **Cons:** ...

## Recommendation
[Which approach is recommended and why. Include the key trade-off that drove the decision.]

## Open Questions
[Unresolved questions that may affect implementation or require follow-up.]

Step 1: Save Design

After a brainstorm, planning, or define workflow produces design output, save it to the standard location with metadata.

SLUG=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")
DESIGNS_DIR="${HOME}/.claude-octopus/designs/${SLUG}"

BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || BRANCH=no-branch
BRANCH_SLUG=${BRANCH//\//-}
timestamps=$(date -u "+%Y%m%d-%H%M%S %Y-%m-%dT%H:%M:%SZ") || exit 1
IFS=' ' read -r DATETIME CREATED <<< "$timestamps"
mkdir -p "$DESIGNS_DIR" || exit 1
FILENAME="${USER}-${BRANCH_SLUG}-design-${DATETIME}.md"
FRONTMATTER_DELIMITER=---

FILEPATH=$(python3 -I -c '
import os
from pathlib import Path
import shutil
import sys
import tempfile

destination = Path(sys.argv[1])
with tempfile.NamedTemporaryFile(dir=destination.parent, prefix=".design-") as draft:
    shutil.copyfileobj(sys.stdin.buffer, draft)
    draft.flush()
    # Publish the complete document without replacing an existing revision.
    try:
        os.link(draft.name, destination)
    except FileExistsError:
        suffix = Path(draft.name).name[len(".design-"):]
        destination = destination.with_name(f"{destination.stem}-{suffix}.md")
        os.link(draft.name, destination)
print(destination)
' "$DESIGNS_DIR/$FILENAME" <<EOF
${FRONTMATTER_DELIMITER}
branch: ${BRANCH}
user: ${USER}
created: ${CREATED}
${SUPERSEDES:+supersedes: ${SUPERSEDES}}
${FRONTMATTER_DELIMITER}

# Design: [Title]

## Problem Statement
[Content from brainstorm/planning session]

## Constraints
[Identified constraints]

## Approaches Considered
[Evaluated approaches]

## Recommendation
[Selected approach and rationale]

## Open Questions
[Unresolved items]
EOF
) || exit 1
FILENAME="${FILEPATH##*/}"
printf 'Design saved to %s\n' "$FILEPATH"

Design docs are read-only after creation. To revise a design, create a new document with a supersedes reference to the prior version.

Step 2: Discover Prior Designs

Before writing a new design, search for related prior designs using keyword matching.

SLUG=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")
DESIGNS_DIR="${HOME}/.claude-octopus/designs/${SLUG}"

# Search for designs matching keywords (case-insensitive)
KEYWORDS="auth refactor"
grep -li "$KEYWORDS" "${DESIGNS_DIR}"/*.md 2>/dev/null | head -10

Constraints:

  • Keyword search is limited to 10 results to avoid overwhelming context
  • Search is case-insensitive via grep -li
  • Only searches within the current project slug's directory

When prior designs are found, present them to the user:

Found 2 prior designs related to "auth refactor":
  1. chris-feature-auth-refactor-design-20260320-091500.md (2026-03-20)
  2. chris-main-design-20260315-140000.md (2026-03-15)

Would you like to review any of these before creating a new design?

If a prior design exists for the same branch, use the newest matching document as SUPERSEDES before saving the next revision. Compare the original branch in the frontmatter because different branch names can share a filename slug. Existing designs keep their original filenames.

SLUG=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")
DESIGNS_DIR="${HOME}/.claude-octopus/designs/${SLUG}"
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) || BRANCH=no-branch

BRANCH_DESIGNS=$(python3 -I - "$DESIGNS_DIR" "$BRANCH" <<'PY_DESIGNS'
from pathlib import Path
import sys

root = Path(sys.argv[1])
branch_field = f"branch: {sys.argv[2]}"
matches = []
for design in root.glob("*-design-*.md"):
    try:
        if not design.is_file() or "\n" in design.name:
            continue
        with design.open(encoding="utf-8") as document:
            if document.readline().rstrip("\n") != "---":
                continue
            branches = []
            for line in document:
                line = line.rstrip("\n")
                if line == "---":
                    if branches == [branch_field]:
                        matches.append((design.stat().st_mtime_ns, design.name))
                    break
                if line.startswith("branch:"):
                    branches.append(line)
    except (OSError, UnicodeError):
        continue

for _, name in sorted(matches, reverse=True)[:3]:
    print(name)
PY_DESIGNS
) || exit 1
SUPERSEDES=${BRANCH_DESIGNS%%$'\n'*}

This creates a linked chain of revisions:

v3 (supersedes: v2) -> v2 (supersedes: v1) -> v1 (no supersedes)

To walk the full revision history, start with the design just saved. In a fresh shell, set FILENAME to the basename of the printed path and DESIGNS_DIR to the design directory from Step 1. Follow supersedes only in the frontmatter. If a revision is missing, unreadable, or part of a cycle, report the history as incomplete.

python3 -I - "${DESIGNS_DIR:?}" "${FILENAME:?}" <<'PY_HISTORY'
from pathlib import Path
import stat
import sys

root, current = Path(sys.argv[1]), sys.argv[2]
history = []
while current:
    if current in history:
        sys.exit(f"Revision history incomplete: cycle at {current!r}")
    name = Path(current)
    if name.name != current or not name.match("*-design-*.md") or "\n" in current:
        sys.exit(f"Revision history incomplete: invalid filename {current!r}")

    design = root / name
    try:
        if not stat.S_ISREG(design.lstat().st_mode):
            raise ValueError("expected a regular design file")
        with design.open("rb") as document:
            if document.readline().rstrip(b"\r\n") != b"---":
                raise ValueError("missing frontmatter")
            predecessors = []
            for raw_line in document:
                line = raw_line.decode("utf-8").rstrip("\r\n")
                if line == "---":
                    break
                if line.startswith("supersedes:"):
                    predecessors.append(line.split(":", 1)[1].strip())
            else:
                raise ValueError("unclosed frontmatter")
        if len(predecessors) > 1:
            raise ValueError("multiple supersedes fields")
    except (OSError, ValueError) as error:
        sys.exit(f"Revision history incomplete: {current!r}: {error}")

    history.append(current)
    current = predecessors[0] if predecessors else ""

print("\n".join(history))
PY_HISTORY

Step 4: Cross-Session Discovery

Downstream commands (deliver, review, develop) can auto-discover design context. Run the lookup block from Step 3 in the same shell before running this block. It returns up to three filenames for the current branch, newest first.

if [[ -n "$BRANCH_DESIGNS" ]]; then
  echo "Design context found for branch ${BRANCH}:"
  while IFS= read -r design; do
    printf '  - %s\n' "$design"
  done <<< "$BRANCH_DESIGNS"
  DESIGN_CONTEXT=$(<"${DESIGNS_DIR}/${SUPERSEDES}")
fi

Downstream skills should check for designs before starting work:

  • flow-discover: Check for existing designs to avoid duplicate research
  • flow-define: Incorporate prior design constraints into requirements
  • flow-develop: Read the recommended approach from the latest design
  • skill-brainstorm: Surface prior designs as starting context

Step 5: Drift Check

Use when the user asks whether the code still matches the saved designs. The check is read-only: never edit code or designs while running it.

List the current design of each revision chain, newest first. A design named in another design's supersedes field is history and is skipped. At most ten designs are checked per run. Incomplete revision chains stop selection before any designs are compared.

The store is keyed by directory basename. Before comparing or writing a report, confirm that the selected designs belong to the current checkout. If their ownership is unclear, ask the user to confirm the design paths. If ownership cannot be confirmed, stop and report the affected paths as incomplete.

SLUG=$(basename "$(git rev-parse --show-toplevel 2>/dev/null || pwd)")
DESIGNS_DIR="${HOME}/.claude-octopus/designs/${SLUG}"

DRIFT_DESIGNS=$(python3 -I - "$DESIGNS_DIR" <<'PY_DRIFT'
from pathlib import Path
import stat
import sys

root = Path(sys.argv[1])
designs, predecessors, incomplete = [], {}, []
try:
    candidates = sorted(path for path in root.iterdir() if path.match("*-design-*.md"))
except FileNotFoundError:
    candidates = []
except OSError:
    sys.exit(f"Revision chain selection incomplete: cannot list {str(root)!r}")

for design in candidates:
    try:
        metadata = design.lstat()
        if not stat.S_ISREG(metadata.st_mode) or "\n" in design.name:
            raise ValueError("invalid design file")
        # Decode one line at a time so unreadable body text does not hide
        # otherwise readable revision links.
        with design.open("rb") as document:
            if document.readline().rstrip(b"\r\n") != b"---":
                raise ValueError("missing frontmatter")
            previous = []
            for raw_line in document:
                line = raw_line.decode("utf-8").rstrip("\r\n")
                if line == "---":
                    break
                if line.startswith("supersedes:"):
                    previous.append(line.split(":", 1)[1].strip())
            else:
                raise ValueError("unclosed frontmatter")
        if len(previous) > 1:
            sys.exit(f"Revision chain selection incomplete: {design.name!r} has multiple supersedes fields.")
        predecessors[design.name] = previous[0] if previous else ""
        designs.append((metadata.st_mtime_ns, design.name))
    except (OSError, ValueError):
        incomplete.append(design.name)

if incomplete:
    for name in incomplete:
        print(f"Incomplete: cannot read design metadata for {name!r}", file=sys.stderr)
    sys.exit("Revision chain selection incomplete; no designs compared.")

checked = set()
for name in predecessors:
    revision, chain = name, set()
    while revision and revision not in checked:
        if revision in chain:
            sys.exit(f"Revision chain selection incomplete: cycle at {revision!r}.")
        if revision not in predecessors:
            sys.exit(f"Revision chain selection incomplete: missing predecessor {revision!r} in the chain for {name!r}.")
        chain.add(revision)
        revision = predecessors[revision]
    checked.update(chain)

superseded = set(predecessors.values())
current = [name for _, name in sorted(designs, reverse=True) if name not in superseded]
for name in current[:10]:
    print(name)
if len(current) > 10:
    print(f"Drift check skipped {len(current) - 10} older designs", file=sys.stderr)
PY_DRIFT
) || exit 1
printf '%s\n' "$DRIFT_DESIGNS"

If selection fails, include its diagnostics in the report once checkout ownership is confirmed. Stop the check without comparing designs, since an unreadable revision could supersede a readable one. Otherwise, proceed one design at a time:

  1. List the files, symbols, fields, commands and settings the design names. Use search for any without a path, and note them so the next revision can add the paths.
  2. Read the current code. Do not rely on memory or earlier summaries.
  3. Report only differences:
    • behavior the design describes that the code lacks
    • data shapes missing fields the design specifies
    • fixed values where the design asks for computed or configurable ones
    • a different pattern, library or boundary from the one the design recommends
    • code inside the design's scope that the design does not cover
  4. If the design or a source file cannot be read, mark the design Incomplete, never No drift found.

After confirming checkout ownership, create a unique report file:

DRIFT_TIMESTAMP=$(date -u +%Y%m%dT%H%M%SZ) || exit 1
mkdir -p -- "${DESIGNS_DIR}/drift" || exit 1
DRIFT_REPORT=$(mktemp "${DESIGNS_DIR}/drift/drift-${DRIFT_TIMESTAMP}-XXXXXX") || exit 1
printf '%s\n' "$DRIFT_REPORT"

Include one section per design with its filename, then each difference with file:line evidence, No drift found or Incomplete. Give the user the path. The user decides whether the code or the design should change. Save design changes as new revisions.

Caps and Limits

  • Max 50 design docs per project slug -- when the limit is reached, warn the user and suggest archiving old designs
  • Keyword search limited to 10 results -- prevents context overload
  • Drift check limited to 10 designs per run -- the newest of each revision chain
  • Design doc template max 500 lines -- encourages concise, actionable designs

Cap enforcement:

DOC_COUNT=$(ls "${DESIGNS_DIR}"/*.md 2>/dev/null | wc -l | tr -d ' ')
if [[ "$DOC_COUNT" -ge 50 ]]; then
  echo "Warning: ${DOC_COUNT} design docs in ${DESIGNS_DIR}. Consider archiving old designs."
fi

Integration Notes

Works With

  • flow-discover -- Design docs capture research findings for persistence
  • flow-define -- Design constraints feed into requirement definitions
  • skill-brainstorm -- Brainstorm output can be saved as a design document
  • skill-thought-partner -- Exploration sessions can produce design artifacts

Downstream Discovery

  • flow-develop -- Reads latest design before implementation
  • flow-deliver -- References design decisions during review
  • skill-code-review -- Checks implementation against design recommendations

Immutability Rule

Design docs are read-only after creation. To update a design:

  1. Create a new design document
  2. Set supersedes to the prior document's filename
  3. The prior document remains unchanged for audit trail

This ensures a complete history of design evolution is always available.

Similar Skills

ask-matt

MAmattpocock/skills337k4,978 new stars in the last 7 days

chief-of-staff

MAmattpocock/skills337k4,978 new stars in the last 7 days

setup-matt-pocock-skills

MAmattpocock/skills337k4,978 new stars in the last 7 days

subagent-driven-development

OBobra/superpowers331k4,772 new stars in the last 7 days

autonomous-loops

AFaffaan-m/ECC315k4,381 new stars in the last 7 days

autonomous-agent-harness

AFaffaan-m/ECC315k4,381 new stars in the last 7 days