| name | confluence-cli |
| description | Use confluence-cli (NPM package) to manage Confluence content, pages, and spaces from the command line. Ideal for documentation workflows, bulk content operations, page migration, and when users request CLI-based Confluence interactions. Trigger on requests like "use Confluence CLI", "create Confluence pages via CLI", "migrate Confluence content", "automate documentation workflows", or when users want to script Confluence operations. |
Confluence CLI (NPM Package)
Overview
confluence-cli is a community-developed command-line interface for Atlassian Confluence that enables content management directly from the terminal. This is a third-party tool (not official Atlassian), available via NPM.
Use this skill when:
- Users request CLI-based Confluence operations
- Documentation workflows need automation
- Bulk page operations are required
- Content migration between spaces is needed
- Users want to script documentation updates
Important: This is NOT the official Atlassian CLI (acli), which does not support Confluence. This is a community tool: https://github.com/pchuri/confluence-cli
Installation
Prerequisites
- Node.js and NPM installed
Install Options
npm install -g confluence-cli
npx confluence-cli --help
Configuration
Interactive Setup (Recommended)
confluence init
The wizard will guide you through:
- Selecting your Confluence instance type (Cloud or self-hosted)
- Choosing appropriate API endpoints
- Setting up authentication
Environment Variables
Alternatively, configure using environment variables:
export CONFLUENCE_DOMAIN="yourcompany.atlassian.net"
export CONFLUENCE_EMAIL="your@email.com"
export CONFLUENCE_API_TOKEN="your-api-token"
export CONFLUENCE_API_PATH="/wiki/rest/api"
export CONFLUENCE_AUTH_TYPE="basic"
API Path Defaults:
- Cloud:
/wiki/rest/api
- Self-hosted/Data Center:
/rest/api
Authentication
Getting API Tokens
- Go to: https://id.atlassian.com/manage-profile/security/api-tokens
- Click "Create API token"
- Label your token (e.g., "confluence-cli")
- Copy the generated token
Authentication Types
Basic Auth (Cloud - Default)
- Requires: Email + API Token
- Used automatically when
CONFLUENCE_EMAIL is set
Bearer Token (Self-hosted/Data Center)
- Requires: Bearer token only
- Set
CONFLUENCE_AUTH_TYPE="bearer"
Core Commands
1. Read Pages
Retrieve page content in various formats:
confluence read 123456789
confluence read 123456789 --format html
confluence read 123456789 --format markdown
confluence read "https://yourcompany.atlassian.net/wiki/spaces/SPACE/pages/123456789"
Formats:
text - Plain text (default)
html - HTML format
markdown - Markdown format (useful for documentation workflows)
2. Get Page Information
View metadata about a page:
confluence info 123456789
confluence info "https://yourcompany.atlassian.net/wiki/spaces/SPACE/pages/123456789"
Returns: Page ID, title, space, version, created/modified dates, authors, etc.
3. Search Content
Find pages using Confluence Query Language (CQL):
confluence search "API documentation"
confluence search "meeting notes" --limit 10
confluence search "type=page AND space=DEV AND title~'API'"
Common CQL Patterns:
type=page - Pages only (not attachments)
space=SPACEKEY - Within specific space
title~'keyword' - Title contains keyword
text~'keyword' - Content contains keyword
created >= now()-7d - Created in last 7 days
4. List Spaces
View all accessible spaces:
confluence spaces
Returns: Space keys, names, types, and URLs
5. Find Pages by Title
Locate pages by exact or partial title:
confluence find "Project Documentation"
confluence find "API Guide" --space DEV
6. Create Pages
Create new pages with content:
confluence create "My New Page" SPACEKEY --content "Hello World!"
confluence create "Documentation" SPACEKEY --file ./content.md --format markdown
confluence create "Release Notes" SPACEKEY --content "<h1>Version 2.0</h1>" --format html
confluence create "Technical Doc" SPACEKEY --file ./doc.xml --format storage
Key options:
--content - Inline content string
--file - Read content from file
--format - Content format: markdown, html, or storage (default: storage)
7. Create Child Pages
Create pages under existing parent pages:
confluence create-child "Subsection" 123456789 --content "Child content"
confluence create-child "API Reference" 123456789 --file ./api-docs.md --format markdown
confluence create-child "Details" "https://...pages/123456789" --content "Details here"
8. Update Pages
Modify existing pages:
confluence update 123456789 --title "Updated Title"
confluence update 123456789 --content "New content" --format markdown
confluence update 123456789 --file ./updated-content.md --format markdown
confluence update 123456789 --title "New Title" --content "New content"
Key options:
--title - Change page title
--content - Inline content
--file - Read content from file
--format - Content format (markdown, html, storage)
9. Edit Workflow (Export → Modify → Update)
Export page for local editing:
confluence edit 123456789 --output ./page.xml
confluence update 123456789 --file ./page.xml --format storage
This workflow is useful for:
- Complex formatting changes
- Offline editing
- Version control integration
- Batch processing
10. Copy Page Trees
Duplicate page hierarchies with all children:
confluence copy-tree 123456789 987654321
confluence copy-tree 123456789 987654321 "Copied Documentation"
confluence copy-tree 123456789 987654321 --max-depth 2
confluence copy-tree 123456789 987654321 --exclude "temp*,*draft*,*obsolete*"
confluence copy-tree 123456789 987654321 --delay-ms 500
confluence copy-tree 123456789 987654321 --dry-run
Key options:
--max-depth <number> - Limit tree depth (default: unlimited)
--exclude <patterns> - Comma-separated wildcard patterns to skip
--delay-ms <number> - Milliseconds delay between API calls
--dry-run - Preview what would be copied without making changes
Exclusion patterns:
* matches any characters
? matches single character
- Examples:
temp*, *draft*, archive-?
11. View Statistics
Check CLI usage analytics:
confluence stats
Disable analytics:
export CONFLUENCE_CLI_ANALYTICS=false
Content Formats
Storage Format (Confluence Native)
Confluence's internal XML-based format (XHTML):
<p>This is <strong>bold</strong> and <em>italic</em> text.</p>
<ac:structured-macro ac:name="code">
<ac:plain-text-body><![CDATA[console.log('Hello');]]></ac:plain-text-body>
</ac:structured-macro>
When to use:
- Maximum fidelity for Confluence-specific features
- Macros, layouts, and advanced formatting
- Export/import workflows
HTML Format
Standard HTML:
<h1>Heading</h1>
<p>Paragraph with <strong>bold</strong> text.</p>
<ul>
<li>List item 1</li>
<li>List item 2</li>
</ul>
When to use:
- Familiar syntax
- Converting from other HTML sources
- Simple formatting needs
Markdown Format
GitHub-flavored Markdown:
# Heading
Paragraph with **bold** text.
- List item 1
- List item 2
```code
console.log('Hello');
**When to use:**
- Developer documentation
- README files and similar content
- Simple, readable syntax
- Integration with markdown-based tools
**Note**: Markdown is converted to storage format server-side. Complex Confluence features may not be available.
## Best Practices
### 1. Authentication and Security
```bash
# Store credentials securely in environment variables
# Add to ~/.bashrc, ~/.zshrc, or use a secrets manager
export CONFLUENCE_API_TOKEN="your-token-here"
# Rotate API tokens regularly
# Revoke old tokens from: https://id.atlassian.com/manage-profile/security/api-tokens
# Use separate tokens for different environments
export CONFLUENCE_DEV_TOKEN="dev-token"
export CONFLUENCE_PROD_TOKEN="prod-token"
2. Bulk Operations
For bulk operations, combine with shell tools:
confluence search "type=page AND space=DEV" | while read -r line; do
sleep 1
done
for file in docs/*.md; do
title=$(basename "$file" .md)
confluence create "$title" DEV --file "$file" --format markdown
sleep 0.5
done
3. Rate Limiting
Respect Confluence API rate limits:
sleep 0.5
confluence copy-tree SOURCE TARGET --delay-ms 500
4. Error Handling in Scripts
#!/bin/bash
if ! command -v confluence &> /dev/null; then
echo "confluence-cli not found. Install: npm install -g confluence-cli"
exit 1
fi
if ! confluence spaces &> /dev/null; then
echo "Authentication failed. Run: confluence init"
exit 1
fi
if confluence create "My Page" DEV --content "Hello"; then
echo "Page created successfully"
else
echo "Failed to create page"
exit 1
fi
5. Version Control Integration
mkdir -p confluence-backup
for page_id in 123456 234567 345678; do
confluence read "$page_id" --format markdown > "confluence-backup/${page_id}.md"
done
cd confluence-backup
git add .
git commit -m "Backup Confluence pages"
git push
6. Content Migration
SOURCE_SPACE="OLD"
TARGET_SPACE="NEW"
confluence search "type=page AND space=$SOURCE_SPACE AND parent is null" > root_pages.txt
confluence copy-tree SOURCE_PAGE_ID TARGET_PAGE_ID
Common Use Cases
Documentation Workflow
confluence create "API Documentation" DEV --content "# API Docs"
ROOT_ID=123456789
confluence create-child "Authentication" $ROOT_ID --file ./auth.md --format markdown
confluence create-child "Endpoints" $ROOT_ID --file ./endpoints.md --format markdown
confluence create-child "Examples" $ROOT_ID --file ./examples.md --format markdown
confluence update $ROOT_ID --file ./updated-overview.md --format markdown
Content Search and Export
confluence search "type=page AND title~'API'" --limit 50 | \
grep -o '[0-9]\{8,\}' | \
while read page_id; do
confluence read "$page_id" --format markdown > "export/${page_id}.md"
done
Space Migration
SOURCE_ROOT=123456789
TARGET_ROOT=987654321
confluence copy-tree $SOURCE_ROOT $TARGET_ROOT "Migrated Documentation" \
--exclude "*draft*,*temp*" \
--delay-ms 500 \
--dry-run
Automated Updates
#!/bin/bash
VERSION="2.0.0"
DATE=$(date +"%Y-%m-%d")
PAGE_ID=123456789
echo "# Release $VERSION ($DATE)" > release-notes.md
echo "" >> release-notes.md
git log --oneline --since="2 weeks ago" >> release-notes.md
confluence update $PAGE_ID --file release-notes.md --format markdown
echo "Release notes updated for version $VERSION"
Backup and Restore
BACKUP_DIR="./confluence-backup-$(date +%Y%m%d)"
mkdir -p "$BACKUP_DIR"
confluence search "type=page AND space=DEV" | \
grep -o '[0-9]\{8,\}' | \
while read page_id; do
confluence read "$page_id" --format storage > "$BACKUP_DIR/${page_id}.xml"
confluence info "$page_id" > "$BACKUP_DIR/${page_id}-info.json"
sleep 0.5
done
tar -czf "confluence-backup-$(date +%Y%m%d).tar.gz" "$BACKUP_DIR"
Integration with Claude Code
When using this skill in Claude Code:
- Check installation: Verify
confluence command is available
- Verify authentication: Run
confluence spaces to test
- Use Bash tool: Execute confluence commands via Bash tool
- Parse output: Most commands output human-readable text; use
--format flags where available
- Handle page IDs: Extract page IDs from URLs or search results
- Rate limiting: Add delays in bulk operations
- Error handling: Check exit codes and provide helpful error messages
- Confirm destructive operations: Warn before bulk updates or deletions
Troubleshooting
Authentication Issues
ls -la ~/.confluence/
confluence init
confluence spaces
API Errors
Rate Limiting
Content Format Issues
Limitations
Third-Party Tool
- Not official Atlassian product: Community-maintained
- Support: Through GitHub issues, not Atlassian support
- Updates: Dependent on community contributions
- Compatibility: May lag behind Confluence API changes
API Limitations
- No attachment management: Cannot upload/download attachments via this CLI
- Limited macro support: Complex Confluence macros may not work with markdown/HTML formats
- No admin operations: User/space management not supported
- Rate limits: Subject to Confluence Cloud API rate limits
Format Conversions
- Markdown limitations: Not all Confluence features available in markdown
- HTML to storage: May require manual adjustment for complex layouts
- Macros: Best created/edited in storage format
Alternative Tools
Official Atlassian CLI (acli)
- Status: Does NOT currently support Confluence (only Jira)
- If support added: May become preferred official tool
- Current: Use for Jira operations only
Appfire Confluence CLI
- Type: Commercial Marketplace app
- Features: More comprehensive admin/automation features
- Cost: Requires purchase/licensing
- Use case: Enterprise automation, advanced admin tasks
Confluence REST API
- Direct API calls: Using curl or similar tools
- Flexibility: Maximum control
- Complexity: More code required
- Use case: Custom integrations, specific requirements
Help and Documentation
confluence --help
confluence read --help
confluence create --help
confluence copy-tree --help
confluence --version
External Resources:
Important Notes
- Third-party tool: Not official Atlassian - community-developed
- Cloud and self-hosted: Supports both, but configuration differs
- API tokens: Required for authentication - obtain from Atlassian account settings
- Rate limits: Respect Confluence API rate limits in bulk operations
- Content formats: Storage format provides best fidelity for Confluence features
- No official CLI: Atlassian's official CLI (acli) does not support Confluence currently
- Analytics: Tool collects anonymous usage data (opt-out via environment variable)