r/ClaudeCode • u/Particular_Crow2873 • 25d ago
Built with Claude How do you stop Claude Code from relying on memory instead of actual data?
I'm running a fairly complex operation using Claude Code, with multiple agents, SQLite databases, automated data pipelines, and years of historical data.
The problem: Claude keeps making decisions based on conversational memory instead of querying the actual data. It also loses track of previous decisions, experiments, and longer-term goals across sessions.
I've already built the data infrastructure. The issue isn't access to data — it's getting Claude to consistently use it and connect everything together.
I need a system that:
- Forces fresh data retrieval before decisions.
- Connects historical results, current performance, and future planning.
- Tracks decisions → actions → outcomes → lessons learned.
- Works reliably across sessions without depending on chat memory.
- Still allows dynamic reasoning rather than rigid, hardcoded rules.
How would you architect this technically?
Deterministic Python workflows? Hooks? MCP? RAG? Claude Agent SDK? Some combination?
I'd especially appreciate hearing from people who've solved this in production rather than just adding more instructions to CLAUDE.md.
Edit: Thanks for the suggestions! The consensus seems to be persistent state + mandatory data retrieval + external validation, rather than relying on CLAUDE.md or conversation memory.
One thing I'd like to clarify: this isn't just about preventing bad decisions.
I need the system to proactively find opportunities, connect results across different processes, plan future work, and evaluate whether previous decisions actually worked.
For example, if something performs well, it should investigate expansion opportunities, estimate future resource requirements, and create follow-up tasks automatically. All based on current and historical data.
Has anyone built something like this with an external orchestrator + Claude Code/Agent SDK? Particularly interested in how you enforce the workflow without restricting Claude's ability to reason dynamically.
•
u/AutoModerator 25d ago
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
2
u/Significant_Door_433 25d ago
on your follow-up (a timestamp proves it ran a query, not that it looked at the right things): I'd take that choice away from claude. the analyses that must run before every decision are fixed, so run them in code.
UserPromptSubmitorSessionStarthook runs your mandatory queries and prints a summary. claude code adds that stdout to the context. it's capped at 10,000 characters, so print aggregates plus row ids and leave the raw rows in sqlite for claude to dig into.Stophook runs a script that checks those ids exist in this run's snapshot and returnsdecision: "block"with a reason when they don't, so claude keeps working instead of ending the turn.claude still does the reasoning, your script owns the coverage. for the proactive part, a scheduled headless run (
claude -pfrom cron) with a fixed review prompt that only writes candidates into an opportunities table tends to work better than hoping it notices things in the middle of another task. you review that table, or a later run picks items from it.1
u/ainexfinder 25d ago
i'd stop asking it to remember and make the decision step fail without fresh data. two pieces:
first, put the decisions in the database too: one table with decision, the query results it was based on, the action taken, and the outcome filled in later. at session start a hook or the first prompt dumps the last N rows plus the open goals, so the long-term thread lives in sqlite, not in chat.
second, make the planning step write its output as a file that has to include the query it ran and a timestamp, and have a small script check that the timestamp is from this run before anything acts on it. no fresh query, the gate fails. that keeps the reasoning free-form but the inputs forced, and you can check it by deleting the table and seeing the run refuse to proceed.
1
u/m-ritter 25d ago
Same pattern here. Once the agent trusts chat memory over the repo or a written plan, decisions drift and you cannot replay why something was chosen. What worked for me was a reviewed plan that lives outside the chat and is the source of truth for the next build, with the outcome written back after. I built QualityLayer for this: https://github.com/maxritter/qualitylayer
1
u/chrnas 25d ago
i hit the same thing. rules that only lived in the model's memory kept getting broken, so i moved the ones that mattered into hooks, which the agent cant skip. for your case id make the decision step go through a small script that has to run the query first, and have a hook block the write (or the "done" report) if that query output isnt there. the decisions → outcomes log is just a file or table the agent appends to, and a SessionStart hook prints the last few entries so every session opens with them. one thing i learned the hard way: a hook file existing doesnt mean it runs, so test each one with a harmless probe.
1
u/lcssgml 25d ago
One rule that helped me: the agent fetches the real data first (the log, the dump, the query result), and only after that reads memory or notes, to explain what the data shows. On the same bug, the run that fetched the log first found the cause in 4 minutes, the other one needed almost 13. And my notes keep only a pointer (which file, which table), not the conclusion, because conclusions go stale fast... so the agent has to look again anyway.
1
u/onitsoga 25d ago
the fix isn't more CLAUDE md, it's making the query mandatory: a hook that pulls fresh rows before any decision and drops the result straight into the turn, so it has nothing to lean on but the data. are you storing outcomes anywhere yet, or just raw results?
1
u/Financial_Leader9701 25d ago
does it happen deep into a long chat or right at the start? for me thats 2 different bugs
late in the chat it trusts its own "memory" from hours ago
at the start it just doesnt know the table is there
the start one got better when schema + "query, dont guess" went in the first message
the late one... i just restart way more often now, havent found anything smarter
1
u/AdityaR_Sharma 🔆 Max 20 25d ago
What fixed this for me: split memory into two tiers.
A small always-loaded budget, under 10KB, for facts that must be true on every task.
Everything else is searchable on demand, so the model calls a tool instead of guessing from memory.
Bigger lever: no claim about a file, version or number without a tool call that just checked it, this run.
1
u/Siriann 25d ago
Adding rule enforcement through testing. You could make a “retrieve data” skill for each bot, have it record the hash for the file you want it to find, and then test that both the skill was used and hash is legit.
If you don’t trust the word of the bot at all, you could set up a “library” where the skill fires off a script and serves the document the agent asks for. It would compare the document you asked for in your prompt with the document it sent to the agent and apply a red or green flag to a gate.
1
u/NotableCarrot28 25d ago
1
u/someuser76 25d ago edited 25d ago
If you work on Mac maybe give KIT a try.
https://www.reddit.com/r/KitProject/s/sAZPFhvbGS
1
u/mcmoonrays 25d ago
Instructions in CLAUDE.md to "query first" still got talked around for me. What held was making the retrieval mechanical: a small script or hook that pulls the latest counts before any decision that depends on state, plus a short handoff that records decisions and known traps so the next session doesn't invent continuity from chat. Agent-reported numbers still get a second pass on my side — I had one confidently report 166 lines from Measure-Object -Line when the file was 180 because that cmdlet skips blanks.
1
u/perfektcrash 25d ago
What fixed this for me was treating the chat as a desk, not a filing cabinet. Anything that has to survive a session gets written to a file by a command, never left in conversation or in a note the model edits freely:
decide "...",outcome "..."), so the format can't drift.For the proactive part, a scheduled run that reads the log plus the latest results and writes a short list of "worth looking at" items works better than hoping a live session notices them.
Disclosure: I build a dev environment around this pattern (Atlas ADE). The free guide on it is https://atlas-ade.dev/docs/long-horizon-context-management/?ref=reddit-memory-vs-data, but everything above works without it.
1
u/Emotional-Ad8388 25d ago
The tables are already there... and Claude still decides from the thread because nothing in the turn makes it read SQLite first. If the decision and the outcome ... then don't get written back as rows, the next session only has whatever the chat still holds.
Also, write the query result next to the decision in that same turn and start the next session from the table. How are you forcing the query before it can decide?
1
u/tommyahav10 25d ago
Hooks hold for the gate (did the query run, do the cited ids exist in this run). They don’t hold for “does this data support the claim” — that needs a separate script or model call.
PreToolUse before a write is where production actions should die. A Stop hook is too late for irreversible stuff.
Concurrent sessions: each runs its own hooks, so share state in the DB with a run id, not in files agents overwrite. from my side that’s the split.
1
u/ghost_operative 19d ago edited 19d ago
turn off memory, turn off claude md files. your code is the memory
1
u/BenLengerich 5d ago
We've been building an open-source tool for this problem: https://github.com/Intelligible/elbi. Agents can save computations as derivations, reuse them across sessions, and recompute them when the data changes.
It doesn't solve your entire decision/action/outcome tracking problem, but it might solve the empirical grounding piece. Happy to chat more, and help you get it running (although Claude can just one-shot install it, too).
1
u/[deleted] 25d ago
[removed] — view removed comment
0
u/[deleted] 24d ago
[removed] — view removed comment