Learn how to reliably pass conversation history to Anthropic Claude in n8n with clear steps for stable, context-aware automations.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
To pass conversation history to Claude reliably in n8n, you should explicitly build and control the conversation array yourself (usually inside a Function node) and then send that array as the messages field to the Anthropic API node or an HTTP Request node. Do not rely on “item chaining” or storing entire history in a single string field unless you intentionally format it that way. Keep the history small, store it in a predictable structure, and trim it before sending to Claude. This avoids runaway payload sizes, unexpected formatting, and memory/time‑limit problems in real n8n workflows.
Claude expects a structured message array like:
n8n workflows don’t maintain “conversation state” automatically; each node only receives the current item JSON. So you must maintain the entire chat history yourself (usually an array inside a field like chatHistory). Each turn, you append the new message, trim the array if needed, and then send that full array to Claude.
The safest, most production-proof approach is:
// Function node: Build/Update conversation history
// Incoming: userMessage (string), chatHistory (array) or empty
// Output: { messages: [...historyIncludingNewUserMsg] }
const userMessage = $json.userMessage;
let history = $json.chatHistory || []; // Load previous history if exists
// Append the new user message
history.push({
role: "user",
content: userMessage
});
// Optional trimming for safety
// e.g., keep only last 10 messages
history = history.slice(-10);
// Return for next node (Claude API)
return [
{
json: {
messages: history
}
}
];
You can use the official Anthropic node or a generic HTTP Request node. The critical part is sending the messages array as-is.
Here’s the payload structure when using HTTP Request:
{
"model": "claude-3-5-sonnet-latest",
"max_tokens": 1024,
"messages": {{ $json.messages }}
}
In the Anthropic node, you put the same array into the Messages field using an expression like:
// Inside field:
// {{$json["messages"]}}
Claude returns something like:
{
"content": [
{ "type": "text", "text": "Hello! ..." }
]
}
So you need another Function node right after Claude:
// Function node: Append Claude's reply to history and store
const history = $json.messages; // The same array we sent
const reply = $json.content[0].text; // Claude’s actual text
history.push({
role: "assistant",
content: reply
});
return [
{
json: {
chatHistory: history,
assistantReply: reply
}
}
];
n8n does not automatically remember anything. To pass conversation history to Claude, you manually store the history array, append to it each turn, trim it, and send that whole array to Claude. This is the same pattern used in real production chatbots running on n8n today, and it’s stable, predictable, and easy to maintain.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.