Skip to main content

Syntax

Or via entity-specific commands:

Description

The add-ref command inserts an inline cross-reference into a spec or issue’s markdown content using Obsidian-style [[ID]] syntax. This is useful for:
  • Adding references programmatically via CLI or scripts
  • Precisely controlling reference placement
  • Optionally creating relationships alongside references
  • Maintaining clean, version-controlled markdown
When you add a reference:
  • The markdown file is updated with [[REFERENCE-ID]] syntax
  • The content is synced to the database
  • Changes are exported to JSONL
  • An optional typed relationship can be created simultaneously
You can also add references manually by editing markdown files directly. The add-ref command is for programmatic insertion.

Arguments

entity-id
string
required
The entity to add the reference toExample: SPEC-001 or ISSUE-001This is where the reference will be inserted (the markdown file that will be modified).
reference-id
string
required
The entity being referencedExample: ISSUE-042 or SPEC-010This is what you’re referencing (the ID that will appear in [[ID]] syntax).

Options

-l, --line
number
Insert at specific line numberExample: --line 15The reference is inserted at (or after/before) this line number. Use --position to control before/after.Note: You must specify either --line or --text, but not both.
-t, --text
string
Search for text to insert nearExample: --text "Requirements:"Searches for this text in the content and inserts the reference near it. Use --position to control before/after.Note: You must specify either --line or --text, but not both.
--position
string
default:"after"
Position relative to line or textExample: --position before or --position afterControls whether the reference is inserted before or after the specified line/text.
--display
string
Custom display text for the linkExample: --display "OAuth Implementation"Creates a reference with custom text: [[ISSUE-042|OAuth Implementation]]Without this, the reference is just [[ISSUE-042]].
--type
string
Create a typed relationship alongside the referenceExample: --type implementsAutomatically creates a relationship of the specified type when adding the reference. Valid types: blocks, implements, depends-on, references, related, discovered-from.
--format
string
default:"inline"
Format style: inline or newlineExample: --format newline
  • inline - Adds reference on the same line as the insertion point
  • newline - Adds reference on a new line

Examples

Insert by Line Number

Add reference at line 15:
Before (line 15):
After (line 15):
Add reference after “Requirements:” heading:
Before:
After:

Insert with Custom Display Text

Add reference with readable text:
Creates: [[ISSUE-042|OAuth Implementation]]

Insert with Relationship Type

Add reference and create typed relationship:
This both:
  1. Adds [[ISSUE-042]] to the markdown
  2. Creates an implements relationship between ISSUE-042 and SPEC-001

Insert on New Line

Add reference on its own line:
Before:
After:

Insert Before Text

Add reference before a specific location:
Before:
After:

Complete Example

Add reference with all options:

JSON Output

Get machine-readable output:

Reference Syntax

The command creates Obsidian-style wiki links:

Basic Reference

Creates: [[ISSUE-042]]

With Display Text

Creates: [[ISSUE-042|OAuth Implementation]]

With Relationship Type

Creates: [[ISSUE-042]] AND creates implements relationship
The relationship type is not visible in the markdown - it creates a separate relationship in the database.

Line vs Text Insertion

Using —line (Precise Positioning)

Advantages:
  • Exact positioning
  • No ambiguity
  • Fast execution
Disadvantages:
  • Line numbers change as content is edited
  • Need to know exact line number

Using —text (Content-Based Positioning)

Advantages:
  • Based on stable content
  • More maintainable
  • Better for headings/sections
Disadvantages:
  • Requires exact text match
  • May fail if text changes
You must specify either --line or --text, but not both. Specifying both will result in an error.

Common Workflows

Adding Implementation References to Spec

1

Create issues from spec

2

Add references to spec

3

Verify in spec

Building Linked Specifications

1

Create parent spec

2

Create child specs

3

Add cross-references

Scripted Reference Addition

Add references programmatically:

Manual Alternative

You can also add references manually by editing markdown files:
Add references using Obsidian syntax:
Then sync changes:
Manual editing gives you full control over placement and formatting. Use add-ref for programmatic automation.

add-ref

Inline references in markdown
  • Modifies markdown content
  • Visible as [[ID]] in files
  • Can include display text
  • Optional relationship creation
  • Good for documentation

link

Database relationships
  • Creates typed relationship
  • Not visible in markdown
  • Required relationship type
  • Bidirectional tracking
  • Good for dependency modeling
When to use each:
  • add-ref: When you want the reference visible in markdown for human readers
  • link: When you want to model dependencies and relationships for graph queries
Best practice: Use both together:
This adds the reference to markdown AND creates the relationship in the database.

Common Questions

No, add-ref processes one reference at a time. For bulk additions, use shell scripting:
The command will error with “Text not found”. Ensure the search text exactly matches what’s in the file (case-sensitive).
There’s no remove-ref command. To remove references:
  1. Edit the markdown file directly
  2. Remove the [[ID]] syntax
  3. Run sudocode sync
Yes, you can add references to archived specs or issues, though they’ll be hidden from default listings.
The command will add the reference each time you run it. You can end up with duplicate references in the markdown. Always check before adding.
No, both entity_id and reference_id must exist in the database. The command validates existence before adding the reference.

Troubleshooting

Cause: You didn’t provide a location for insertionSolution: Specify one location method:
Cause: You provided both location methodsSolution: Choose only one:
Cause: The entity_id doesn’t existSolution: Verify the ID:
Cause: The markdown file doesn’t exist for the entitySolution: Sync to create markdown files:
Cause: The search text doesn’t exist in the fileSolution:
  • Check for exact match (case-sensitive)
  • View the file to verify text:
  • Use different search text or switch to --line
Cause: Line number is less than 1 or not a numberSolution: Use a valid positive integer:
Cause: The line number is greater than the number of lines in the fileSolution: Check the file length:
Use a valid line number within range.

link

Create typed relationships

spec show

View spec content

issue show

View issue content

sync

Sync markdown files

Next Steps

1

Create entities

2

Add references

3

View the result

4

Verify relationships

Cross-References in Markdown

Learn more about using Obsidian-style links in sudocode