Syntax
Description
Theadd-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
- 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
add-ref command is for programmatic insertion.Arguments
SPEC-001 or ISSUE-001This is where the reference will be inserted (the markdown file that will be modified).ISSUE-042 or SPEC-010This is what you’re referencing (the ID that will appear in [[ID]] syntax).Options
--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.--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 before or --position afterControls whether the reference is inserted before or after the specified line/text.--display "OAuth Implementation"Creates a reference with custom text: [[ISSUE-042|OAuth Implementation]]Without this, the reference is just [[ISSUE-042]].--type implementsAutomatically creates a relationship of the specified type when adding the reference. Valid types: blocks, implements, depends-on, references, related, discovered-from.--format newlineinline- Adds reference on the same line as the insertion pointnewline- Adds reference on a new line
Examples
Insert by Line Number
Add reference at line 15:Expected output
Expected output
Insert by Text Search
Add reference after “Requirements:” heading:Expected output
Expected output
Insert with Custom Display Text
Add reference with readable text:Expected output
Expected output
[[ISSUE-042|OAuth Implementation]]
Insert with Relationship Type
Add reference and create typed relationship:Expected output
Expected output
- Adds
[[ISSUE-042]]to the markdown - Creates an
implementsrelationship between ISSUE-042 and SPEC-001
Insert on New Line
Add reference on its own line:Expected output
Expected output
Insert Before Text
Add reference before a specific location:Expected output
Expected output
Complete Example
Add reference with all options:Expected output
Expected output
JSON Output
Get machine-readable output:JSON output
JSON output
Reference Syntax
The command creates Obsidian-style wiki links:Basic Reference
[[ISSUE-042]]
With Display Text
[[ISSUE-042|OAuth Implementation]]
With Relationship Type
[[ISSUE-042]] AND creates implements relationship
Line vs Text Insertion
Using —line (Precise Positioning)
- Exact positioning
- No ambiguity
- Fast execution
- Line numbers change as content is edited
- Need to know exact line number
Using —text (Content-Based Positioning)
- Based on stable content
- More maintainable
- Better for headings/sections
- Requires exact text match
- May fail if text changes
--line or --text, but not both. Specifying both will result in an error.Common Workflows
Adding Implementation References to Spec
Create issues from spec
Add references to spec
Verify in spec
Building Linked Specifications
Create parent spec
Create child specs
Add cross-references
Scripted Reference Addition
Add references programmatically:Manual Alternative
You can also add references manually by editing markdown files:add-ref for programmatic automation.Difference from link Command
add-ref
- Modifies markdown content
- Visible as
[[ID]]in files - Can include display text
- Optional relationship creation
- Good for documentation
link
- Creates typed relationship
- Not visible in markdown
- Required relationship type
- Bidirectional tracking
- Good for dependency modeling
- 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
Common Questions
Can I add multiple references at once?
Can I add multiple references at once?
add-ref processes one reference at a time. For bulk additions, use shell scripting:What if the text I'm searching for doesn't exist?
What if the text I'm searching for doesn't exist?
Can I remove a reference?
Can I remove a reference?
remove-ref command. To remove references:- Edit the markdown file directly
- Remove the
[[ID]]syntax - Run
sudocode sync
Does this work with archived entities?
Does this work with archived entities?
What happens if I add the same reference twice?
What happens if I add the same reference twice?
Can I use this with non-existent entities?
Can I use this with non-existent entities?
Troubleshooting
Error: Either --line or --text must be specified
Error: Either --line or --text must be specified
Error: Cannot specify both --line and --text
Error: Cannot specify both --line and --text
Error: Entity not found
Error: Entity not found
Error: File not found
Error: File not found
Error: Text not found
Error: Text not found
- Check for exact match (case-sensitive)
- View the file to verify text:
- Use different search text or switch to
--line
Error: Invalid line number
Error: Invalid line number
Error: Line number out of bounds
Error: Line number out of bounds
Related Commands
link
spec show
issue show
sync
Next Steps
Create entities
Add references
View the result
Verify relationships

