Sessions (Persistent Memory)

AnyLLM includes a powerful session feature that transforms your AI assistant into a true persistent pair programmer. It gives the AI a dynamic, long-term memory, allowing it to remember the context of your project, your past interactions, and even adapt its understanding of your codebase between runs.

Why Sessions are Powerful

Imagine working on a complex feature. Without sessions, every time you restart AnyLLM, the AI starts fresh, requiring you to re-explain the project and your current task. With sessions, the AI:

  • Remembers Conversations: Recalls previous discussions, questions, and answers.
  • Understands Project State: Knows which files you've recently read or modified.
  • Adapts to Your Focus: Dynamically adjusts its view of your codebase based on your current query.

This means less repetition, faster problem-solving, and a more natural, continuous workflow.

How It Works: The Smart Context

When session mode is enabled, AnyLLM creates a hidden .anyllm directory in your project's root. Inside this directory, it stores the project_context.json file, which contains a rich, JSON-structured summary of your interactions. This context is loaded every time you start AnyLLM in session mode, providing the AI with a comprehensive understanding of the project's current state and history.

Key components of this smart context include:

  • Dynamic Project Map (repo_map): This isn't just a static file tree. Based on your current query and recent activity, AnyLLM intelligently generates a focused view of your project. Irrelevant directories are collapsed (e.g., node_modules/ (1200 files)), while relevant sections are expanded, giving the AI a concise yet detailed overview of the files pertinent to your task.
  • Code Highlights (code_highlights): For the most relevant files identified by the dynamic map, AnyLLM extracts and provides a summary of key symbols (classes, functions) within them. This gives the AI immediate insight into the code's structure without needing to read the entire file.
  • Conversation History: A detailed log of your past prompts and the AI's responses, allowing the AI to pick up exactly where you left off.
  • Tracked Files: Records which files have been read or modified, helping the AI understand your recent work.
  • Executed Commands: Logs terminal commands, providing context on previous actions.

Enabling Sessions

You can enable session mode in two ways.

1. Using the --session flag

Launch the application with the --session command-line flag:

./anyllm --session

This is useful for enabling sessions on a temporary, per-command basis.

2. Using anyllm.json

For projects where you always want sessions enabled, you can add a parameter to your anyllm.json file:

{
  "session": true,
  "provider": {
    // ... your provider configuration
  }
}

Setting "session": true will make session mode the default for that project.

Example Usage

Imagine the following workflow:

Run 1: Analyze a file

./anyllm --session
> Analyze the file @src/Domain/Agent/BaseAgent.php and tell me its purpose.

The AI reads the file and gives you a summary. You then exit. The context of this interaction is saved.

Run 2: Recall the context

You open a new terminal later.

./anyllm --session
> Based on the file we just discussed, suggest a new method to add to it.

Because the session was saved, the AI remembers which file you were talking about and can provide a relevant suggestion without you needing to specify the file again.