Building an AI Digital Twin with Claude Code
Praveen Daniel highlighted
How to architect a digital brain for AI agents using hooks and Knowledge Base

In Part 1, I mentioned that we need to build a brain for our agent. This is the only way to truly empower the agent so it becomes a genuine twin rather than just a contractor.
A contractor simply carries out tasks as instructed. They don’t share our intuition for subtle details, leaving them to rely on educated guesses. This might work fine in simple greenfield projects. However, dropping them into complex projects to handle intricate tasks eventually leads to disaster.
In this article, I will use Claude Code, a popular harness tool, as an example. We will look at what it takes to build a digital twin and how to actually implement one. I will share how I set up my own configuration. That said, I will skip most of the granular details because my twin will naturally look very different from yours.
First, we need a digital brain. We have already broken down the essential components of a digital brain:
An LLM capable of reasoning and processing input. I use Claude Opus here, prioritizing high reasoning intelligence and a large context window. We need a model with high intelligence. Sonnet can work, but it is not comprehensive enough.
A harness that can implement the ReAct pattern and interact with the real world. I use Claude Code along with various skills and scripts. I previously explained the underlying logic of my skills. Each skill acts as an execution unit, but everything underneath is a script. This approach gives me maximum control over how the agent reacts instead of letting it freestyle. Just like our own brains, every operation needs clear boundaries to prevent rogue behavior. The skill documentation represents our cognition, while the script acts as the brain’s brakes.
A Knowledge Base (KB) that stores domain knowledge while providing search and linking capabilities. I use an LLM wiki paired with Obsidian. Importantly, I do not use any MCP or APIs here. The agent works directly with plain text files.
An offline batch data pipeline that converts short-term memory into long-term memory. At its core, this is a scheduled job designed to ingest large amounts of data. We can keep it simple with Cron or scale up with Airflow, depending on our goals. I built a custom service for this because Airflow felt too heavy, while Cron felt too basic.
On a side note, let me expand a bit on skills.
Most of my skills perform purely mechanical operations. For instance, my Jira skill wraps various Jira APIs into a script. Then, my SKILL.md tells the agent how to invoke this script. It can search Jira, post comments, or create tickets. However, it contains zero writing guidelines on how to craft those comments or descriptions.
Similarly, skills like Confluence, Grafana, and Kubernetes focus strictly on execution. They wrap APIs into scripts accompanied by an instruction manual, without interfering with the agent’s cognition.
To me, a skill should focus on how to do something. It defines how the harness interacts with the real world, rather than forcing the agent into a rigid way of thinking. Over 90% of my skills focus purely on execution rather than reasoning. As I mentioned before, an agent is simply an execution loop: it ingests inputs, reasons, acts, and produces outputs.
Anchoring behavior with scripts effectively controls randomness and keeps costs down.
So how do we give the agent intelligence and make it act more like a human? Or more specifically, like me? That is precisely what the brain does. Let us walk through how this brain pipeline actually works.
Overall Architecture
Let us break down the overall architecture. I will explain what each block and edge represents, without diving too deep into implementation details.

We can see three distinct sections here. They represent three key components of the brain: Thinking and Reaction (Claude Code), Cognition (Human + KB), and the Hippocampus (Offline Batch).
The human user does not just provide input here. We also serve as the Meta-cognition engine. We monitor the agent’s execution steps and offer guidance when it gets stuck.
What happens inside Claude Code is fairly straightforward. The only unique elements are the hooks and prompt injections.
How do we make Claude Code aware that it has a brain to consult? Using a skill is one approach, but it is unreliable because skills can easily lose the model’s focus. Using CLAUDE.md works since it gets injected into the context during conversation. Still, it is not foolproof. As the session gets longer, the influence of CLAUDE.md steadily degrades.
To ensure the agent never forgets its brain and continuously reads and updates it, the most direct approach is to inject a prompt into every User Message. This prompt reminds the agent that its brain exists and needs updating.
I document my thought processes entirely inside the wiki, including a page dedicated to how to think. Using hooks, we remind the agent about its brain and direct it to that thinking framework page. Consequently, the agent reiterates this context during every execution step, reinforcing its cognition. When it hits a roadblock, it proactively searches the wiki for answers. This mirrors how humans build self-awareness. We rely on logic to structure our thinking patterns continuously.
The final section is Cron, which acts as the human brain’s hippocampus.
It handles three main responsibilities:
Decision distillation. We want the agent to mimic us closely. To achieve this, we must feed it natural conversational data to show how we think. I extract dialogue from session logs, have the agent identify underlying patterns, and write actionable, generalizable rules into the wiki. This wiki content serves as the source of truth for our hook injections.
Domain knowledge distillation. Although our hooks remind the agent to record what it learns, this is not a hard constraint. The agent still decides whether something is worth recording. That subjective judgment means it might skip useful information, much like the human brain. Late at night, the hippocampus kicks in to consolidate short-term memories into long-term memories. Domain distillation handles this exact process.
Wiki maintenance. Without ongoing maintenance, a wiki quickly turns into a cluttered mess. Garbage in, garbage out applies directly to artificial brains. Therefore, a separate scheduled job periodically cleans up wiki content and indexing. It enforces our taxonomy framework and the MECE principle. It also keeps data fresh by cross-referencing sources. If an entry mentions code, it checks the actual repository. If it mentions Jira, it checks Jira directly.
With this architecture, the agent can operate much more like a real person. It internalizes our mental models and responds with high precision.
Wrap Up
This entire setup requires fine-tuning across several key areas:
The content used in hook injections
Wiki content and taxonomy
The implementation and prompts for the three offline pipelines
That is not even mentioning prompt engineering and skill tuning.
There are no silver bullets for these details. Every use case demands a different approach based on task requirements. That is why this article focuses purely on the architectural framework rather than implementation specifics.
On a final note, I have since migrated away from Claude Code as my primary harness. As mentioned in my previous post, I shifted from Claude Code + Opus to Pi + GLM. This move lowered operational costs while open-source tools provided far greater flexibility for customization.
However, the underlying architecture remains unchanged. A harness can only do so much. If we want to grant true intelligence to an agent, we must start by studying how the human brain functions.
Plenty of open-source skills exist today, but I do not use any of them. Skills should fit specific workflows and line up with our exact habits. Every skill I build simply provides the agent with tools to interact with the world, without imposing how it should think.
True thinking stems from accumulated experience. I have lived by this principle throughout my career as an architect, and AI agents are no exception.
Originally published on Medium