build

An agent that never hits the same wall twice

Teach your coding agent to write down what it learns. Next session, it reads those notes and skips the mistake. No fine-tuning. No embeddings. Plain files.

The loop you are stuck in

Your agent calls an API. The call fails because the endpoint uses cursor-based pagination, not page offsets. You explain the fix. Two days later, a new session hits the same endpoint. The agent tries page offsets again.

The problem is not the model. Session memory dies with the session. CLAUDE.md is for instructions, not for accumulated discoveries. The agent needs a place to write what it learned and a habit of reading those notes before it starts work.

The learnings-file pattern

On failure-then-success, write what worked to a learnings file. On task start, read the relevant learnings first. Each file covers one topic. Each entry has a date and the specific detail that matters.

That file is five lines. It saves the agent (and you) from a failed request, a stack trace, a debugging cycle, and a second explanation. Every entry compounds.

learnings/api-pagination.md
## 2026-08-15: cursor-based pagination
The /v2/items endpoint uses cursor tokens, not page offsets.
Pass the `next_cursor` value from each response as `cursor`.
Page size default is 50. Maximum is 200.

Step 1: Serve a state folder

The learnings files need a home the agent can read and write to across sessions. gcontext is an open-source MCP server that serves a folder of plain text files as persistent state.

The server exposes read_file, write_file, list_dir, and grep as MCP tools. Any MCP client can connect. The folder persists on disk. Push it to git and it persists across machines.

install and start
$ uv tool install gcontext-ai
$ gcontext init my_agent
$ gcontext up my_agent

Step 2: Tell the agent the rule

The agent needs one instruction. Add it to your CLAUDE.md, a skill, or your system prompt.

The learnings rule

Before you start a task, read learnings/ via the gcontext MCP server for relevant notes. After you solve a non-obvious problem, write what you learned to learnings/topic.md.

That is the entire mechanism. The agent reads before it works. It writes after it discovers. The folder accumulates knowledge session by session. The agent uses list_dir to see what learnings exist and grep to find relevant entries.

Step 3: Watch it compound

On the next session, the agent hits the same API. This time it reads the learnings folder first. No failed request. No debugging. No second explanation.

After a few weeks, the learnings folder holds dozens of entries: API quirks, deployment gotchas, schema constraints, environment differences. Each one is a mistake the agent makes at most once.

second session
Reading learnings/api-pagination.md ...
Found note: /v2/items uses cursor tokens, not page offsets.
Applying cursor-based pagination for /v2/items.
Request succeeded. 143 items fetched in 3 pages.
No new learnings to record.

Keeping learnings healthy

  • One topic per file. Do not mix API pagination and database connection strings in the same file.
  • Date each entry. Old entries may no longer apply. A date tells you when the fact was true.
  • Prune duplicates. Merge repeated entries into one.
  • Review quarterly. Remove entries about bugs that are now fixed. Keep the folder lean.

You can ask the agent to do this review: "Review the learnings folder. Remove duplicates and delete entries that are no longer relevant."

Why plain files win here

You can read the memory in any editor. You can correct mistakes with a text edit. You can git diff what the agent added. No database to manage. No embeddings to regenerate.

When the agent writes something wrong, you open the file and fix it. Try that with a vector database or a fine-tuned model. Plain files give you full control over what the agent remembers.

Questions

What is a self-improving agent?

An agent that writes down what it learns and reads those notes in future sessions. No fine-tuning or weight changes are involved. The agent stays the same; its context grows.

Does this need fine-tuning?

No. The agent's weights stay the same. It reads its own notes as context, the same way you read your own documentation.

Which coding tools support this?

Any MCP client: Claude Code, Cursor, Codex, Claude Desktop. The learnings folder lives behind an MCP server, so any tool that speaks the protocol can read and write to it.

Related

Skills and MCP state
Instructions vs accumulated knowledge
Subagent coordination
Sharing findings between parallel agents
AI agent memory
Four approaches to persistent agent memory
What is agent state?
Definition and management patterns
Stop re-explaining

Install gcontext. Add the learnings rule. Your agent remembers what it learns.

View on GitHubBrowse agents