Xiaohongshu Content Publishing
Automatically determine the publishing method and mode based on user input to simplify the publishing process.
Publishing Modes
- Image-Text Upload (Default): Images + Short Text, suitable for daily sharing
- Long Article Writing: Long-form Article + Typesetting Template Selection, suitable for in-depth content. Use this mode when the user explicitly says "post long article"
Workflow
User Input
│
├─ Complete Content + Images/Image URLs → Determine Mode → Publishing Process
│
└─ Webpage URL → WebFetch Extract Content and Images
│
├─ With Images → Summarize Content Appropriately → Determine Mode → Publishing Process
│
└─ Without Images → Prompt User to Download Images Manually
│
└─ After User Provides Images → Publishing Process
Step 1: Determine Input Type
Judge based on user input:
- Complete Content Mode: User provides title, body content, and images (local path or URL)
- URL Extraction Mode: User only provides a webpage URL
If unsure, ask the user.
Step 2: Process Content
Complete Content Mode
Directly use the title and body provided by the user, proceed to Step 3.
URL Extraction Mode
- Use WebFetch to extract webpage content
- Extract key information: title, body, image URLs
- Summarize content appropriately, ensuring:
- Complete key information
- Natural and fluent language
- Suitable for Xiaohongshu reading habits
Image Extraction Failure Handling
If no image URLs can be extracted from the webpage, or the image URLs are inaccessible, must:
- Inform the user that image extraction failed
- Provide the original webpage link and ask the user to access it manually
- Guide the user:
- Open the original webpage in the browser
- Right-click the desired image → "Save image as" or "Copy image address"
- Provide the saved image path or copied image URL to me
- Wait for the user to provide the image before continuing the publishing process
Sample Prompt:
Failed to extract usable images from the webpage. Please obtain them manually:
1. Open the original link: [URL]
2. Find suitable images, right-click to save locally or copy the image address
3. Send the image path or URL to me
We will continue the publishing process after receiving the image.
Step 3: Content Check
Title Check
Title length must be ≤ 38, calculation rules:
- Chinese characters and Chinese punctuation (《》、,。etc.): Each counts as 2
- English letters/numbers/spaces/ASCII punctuation: Each counts as 1
If it exceeds the limit, automatically generate a new title that meets the length requirement while maintaining the same meaning.
Body Format
- Use double line breaks between paragraphs
- Natural language, avoid machine translation feel
- Simplified Chinese
Step 4: Publish to Xiaohongshu
Refer to the complete publishing workflow: references/publish-workflow.md
4.1 User Content Confirmation
Use
to show the user the upcoming content (title, body, images) and obtain explicit confirmation before proceeding.
4.2 Select Publishing Mode
Use
to let the user select the publishing mode:
- Headless Mode (Recommended): Runs in the background, fast, no browser window. Report results directly after publishing is completed.
- Windowed Mode: Displays the browser window, allows content preview. Requires user confirmation before clicking publish.
AskUserQuestion Example:
Question: Select Publishing Mode
Options:
- Headless Mode (Recommended): Fast background publishing, no preview needed
- Windowed Mode: Displays browser, allows preview and confirmation
4.3 Write to Temporary File
Write the title and body to a temporary UTF-8 text file. Do not inline Chinese text in
.
4.4 Execute Publishing (Branch by Mode)
A. Image-Text Upload Mode (Default)
Execute the publishing script according to the user-selected mode:
Headless Mode (add
parameter):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --headless --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
Windowed Mode (do not add
):
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\publish_pipeline.py" --title-file title.txt --content-file content.txt --image-urls "URL1" "URL2"
Other Parameters:
bash
# Publish to specified account
python ... --account myaccount ...
# Use local images
python ... --images "C:\path\to\image.jpg"
Process Output:
- (exit code 1) → The script automatically switches to Windowed Mode, prompts the user to scan the code to log in, and re-runs after confirmation
- (exit code 0) → Proceed to the next step according to the mode
- Exit code 2 → Report error
B. Long Article Mode
Step B.1 — Fill Long Article Content + One-Click Typesetting:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" long-article --title-file title.txt --content-file content.txt
Optional
--images img1.jpg img2.jpg
to insert images into the editor.
The output contains a
JSON array, which is the list of available typesetting template names.
Step B.2 — Let User Select Template:
Use
to display the template names as options for the user to select (parsed from the TEMPLATES output).
Step B.3 — Select Template:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" select-template --name "User-selected Template Name"
Step B.4 — Click Next and Fill Body Description on Publishing Page:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-next-step --content-file content.txt
Note: The publishing page has an independent body description editor, which must be filled by passing content via
or
.
If the body exceeds 1000 words, it should be compressed to around 800 words while maintaining the original meaning before filling in.
Step B.5 — User Preview Confirmation and Publishing: Proceed to Step 4.5 below.
4.5 User Preview Confirmation (Windowed Mode / Long Article Mode Only)
Only when the user selects Windowed Mode or uses Long Article Mode, use
to ask the user to check the preview in the browser and confirm before publishing.
Skip this step for headless mode image-text publishing, directly proceed to 4.6.
4.6 Click Publish
Click the publish button:
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" click-publish
4.7 Report Results
Inform the user whether the publishing was successful based on the command output.
Important Notes
- Never publish automatically - Must obtain explicit user confirmation
- Image Requirements - Image-Text Upload Mode must have images; Long Article Mode images are optional
- Long Article Mode - Must let the user select a template, do not select automatically
- Body Description - The publishing page in Long Article Mode has an independent body description box; if it exceeds 1000 words, compress it to around 800 words
- Headless Mode: Use the parameter for automated publishing. If login is required, the script automatically switches to Windowed Mode
- If page structure changes cause selectors to fail, refer to
references/publish-workflow.md
for updates
Account Management
The system supports multiple Xiaohongshu accounts, each with an independent Chrome profile.
List Accounts
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" list-accounts
Add Account
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" add-account myaccount --alias "My Account"
Login
bash
# Default account
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" login
# Specified account
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account myaccount login
Switch Account
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" switch-account
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" --account otheraccount switch-account
Set Default Account
bash
python "C:\Users\admin\AI\.claude\skills\post-to-xhs\scripts\cdp_publish.py" set-default-account myaccount